lifetimes lint: include support for lifetimes as generic params

This commit is contained in:
Georg Brandl 2015-08-13 06:43:25 +02:00
parent 6603299f3f
commit 2f7693094f
2 changed files with 17 additions and 0 deletions

View File

@ -128,7 +128,16 @@ impl RefVisitor {
}
impl<'v> Visitor<'v> for RefVisitor {
// for lifetimes of references
fn visit_opt_lifetime_ref(&mut self, _: Span, lifetime: &'v Option<Lifetime>) {
self.record(lifetime);
}
// for lifetimes as parameters of generics
fn visit_lifetime_ref(&mut self, lifetime: &'v Lifetime) {
self.record(&Some(*lifetime));
}
// for lifetime bounds; the default impl calls visit_lifetime_ref
fn visit_lifetime_bound(&mut self, _: &'v Lifetime) { }
}

View File

@ -25,6 +25,12 @@ fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } // n
fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) } //~ERROR
type Ref<'r> = &'r u8;
fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) { }
fn lifetime_param_2<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) { } //~ERROR
struct X {
x: u8,
}
@ -53,6 +59,8 @@ fn main() {
let _ = deep_reference_1(&1, &2);
let _ = deep_reference_2(Ok(&1));
let _ = deep_reference_3(&1, 2);
lifetime_param_1(&1, &2);
lifetime_param_2(&1, &2);
let foo = X { x: 1 };
foo.self_and_out();