From 243a53048073de3986197c38f8697df8d02ef664 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 12 Apr 2015 17:51:24 -0700 Subject: [PATCH 1/2] Fix issue #24085 Perform trait selection for builtin traits with a throw-away inference context, restoring the behavior prior to 83ef304. This prevents unwanted region constraints that lead to later errors. --- src/librustc_typeck/check/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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> { From 6463cbd51f63d42e72d7490c7940d8b3c853f96c Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sun, 12 Apr 2015 20:18:16 -0700 Subject: [PATCH 2/2] Add regression test for issue #24085 --- src/test/run-pass/traits-issue-24085.rs | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/run-pass/traits-issue-24085.rs 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;}); +}