Update region inference for traits so that a method with
explicit self doesn't incorrectly cause the entire trait to be tagged as being region-parameterized. Fixes #5224.
This commit is contained in:
parent
65986ba0c0
commit
cbfd88a486
13 changed files with 264 additions and 190 deletions
|
|
@ -17,5 +17,5 @@ fn main() {
|
|||
let x: @Map<~str, ~str> = @LinearMap::new::<~str, ~str>() as
|
||||
Map::<~str, ~str>;
|
||||
let y: @Map<uint, ~str> = @x;
|
||||
//~^ ERROR mismatched types: expected `@core::container::Map/&<uint,~str>`
|
||||
//~^ ERROR mismatched types: expected `@core::container::Map<uint,~str>`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
// Test how region-parameterization inference
|
||||
// interacts with explicit self types.
|
||||
//
|
||||
// Issue #5224.
|
||||
|
||||
trait Getter {
|
||||
// This trait does not need to be
|
||||
// region-parameterized, because 'self
|
||||
// is bound in the self type:
|
||||
fn get(&self) -> &'self int;
|
||||
}
|
||||
|
||||
struct Foo {
|
||||
field: int
|
||||
}
|
||||
|
||||
impl Getter for Foo {
|
||||
fn get(&self) -> &'self int { &self.field }
|
||||
}
|
||||
|
||||
fn get_int<G: Getter>(g: &G) -> int {
|
||||
*g.get()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let foo = Foo { field: 22 };
|
||||
assert get_int(&foo) == 22;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue