Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate fix for issue #24085 #24404

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,17 @@ pub fn evaluate_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
// anyhow).
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);

fulfill_cx.register_builtin_bound(infcx, ty, bound, cause);
// Relax region constraints that result from trait selection by
// inserting an inference variable. This mimics the behavior
// of method confirmation where fresh inference variables are
// substituted into the method self type, which is then unified
// with the adjusted receiver type and handed to trait selection.
let relax_ty = infcx.next_ty_var();
try!(infcx.sub_types(false, infer::Misc(span), ty, relax_ty).map_err(|_| Unimplemented));
let relax_ty = infcx.resolve_type_vars_if_possible(&relax_ty);
debug!("relax_ty: {}", relax_ty.repr(infcx.tcx));

fulfill_cx.register_builtin_bound(infcx, relax_ty, bound, cause);

// Note: we only assume something is `Copy` if we can
// *definitively* show that it implements `Copy`. Otherwise,
Expand Down
29 changes: 29 additions & 0 deletions src/test/run-pass/traits-issue-24085.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;});
}