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:
Niko Matsakis 2013-02-26 14:37:31 -05:00
parent 65986ba0c0
commit cbfd88a486
13 changed files with 264 additions and 190 deletions

View file

@ -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>`
}

View file

@ -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;
}