Skip to content

Commit ee21b00

Browse files
committed
auto merge of #15991 : pcwalton/rust/resolve-regions-in-trait-matching, r=alexcrichton
matching. This breaks code like: struct Foo<'a,'b> { x: &'a int, y: &'b int, } trait Tr { fn foo(x: Self) {} } impl<'a,'b> Tr for Foo<'a,'b> { fn foo(x: Foo<'b,'a>) {} // <-- bad } Change this code to not contain a lifetime mismatch error. For example: struct Foo<'a,'b> { x: &'a int, y: &'b int, } trait Tr { fn foo(x: Self) {} } impl<'a,'b> Tr for Foo<'a,'b> { fn foo(x: Foo<'a,'b>) {} // OK } Closes #15517. [breaking-change] r? @alexcrichton
2 parents 0d53597 + 5de8ed5 commit ee21b00

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/librustc/middle/typeck/check/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,10 @@ fn compare_impl_method(tcx: &ty::ctxt,
10761076
ty::note_and_explain_type_err(tcx, terr);
10771077
}
10781078
}
1079+
1080+
// Finally, resolve all regions. This catches wily misuses of lifetime
1081+
// parameters.
1082+
infcx.resolve_regions_and_report_errors();
10791083
}
10801084

10811085
fn check_cast(fcx: &FnCtxt,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that the trait matching code takes lifetime parameters into account.
12+
// (Issue #15517.)
13+
14+
struct Foo<'a,'b> {
15+
x: &'a int,
16+
y: &'b int,
17+
}
18+
19+
trait Tr {
20+
fn foo(x: Self) {}
21+
}
22+
23+
impl<'a,'b> Tr for Foo<'a,'b> {
24+
fn foo(x: Foo<'b,'a>) {
25+
//~^ ERROR method not compatible with trait
26+
//~^^ ERROR method not compatible with trait
27+
}
28+
}
29+
30+
fn main(){}

0 commit comments

Comments
 (0)