diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 862c454a38833..9367678ec765d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -315,7 +315,8 @@ impl<'a, 'tcx> mc::Typer<'tcx> for FnCtxt<'a, 'tcx> { } fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool { let ty = self.infcx().resolve_type_vars_if_possible(&ty); - !traits::type_known_to_meet_builtin_bound(self.infcx(), self, ty, ty::BoundCopy, span) + let infcx = infer::new_infer_ctxt(self.tcx()); + !traits::type_known_to_meet_builtin_bound(&infcx, self, ty, ty::BoundCopy, span) } fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { diff --git a/src/test/run-pass/traits-issue-24085.rs b/src/test/run-pass/traits-issue-24085.rs new file mode 100644 index 0000000000000..78bd378ba0add --- /dev/null +++ b/src/test/run-pass/traits-issue-24085.rs @@ -0,0 +1,29 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that trait selection for Copy does not introduce +// bad region constraints. Issue #24085. + +#[derive(Clone, Copy)] +enum Path<'a:'b, 'b> { + Data(&'a i32), + Link(&'a i32, &'b Path<'a, 'b>) +} + +fn foo<'a,'b,F>(_p: Path<'a, 'b>, _f: F) + where F: for<'c> FnMut(&Path<'a, 'c>) { +} + +fn main() { + let y = 0; + let p = Path::Data(&y); + + foo(p, |x| {*x;}); +}