2015-08-12 13:16:09 +02:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
#![deny(needless_lifetimes)]
|
2015-08-13 17:40:45 +02:00
|
|
|
#![allow(dead_code)]
|
2015-08-13 07:51:24 +02:00
|
|
|
fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) { }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
2015-08-13 07:51:24 +02:00
|
|
|
fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) { }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
|
|
|
fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) { } // no error, same lifetime on two params
|
|
|
|
|
|
|
|
fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) { } // no error, static involved
|
|
|
|
|
2015-08-15 09:36:02 +02:00
|
|
|
fn mut_and_static_input(_x: &mut u8, _y: &'static str) { }
|
|
|
|
|
2015-08-13 07:51:24 +02:00
|
|
|
fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
|
|
|
fn multiple_in_and_out_1<'a>(x: &'a u8, _y: &'a u8) -> &'a u8 { x } // no error, multiple input refs
|
|
|
|
|
|
|
|
fn multiple_in_and_out_2<'a, 'b>(x: &'a u8, _y: &'b u8) -> &'a u8 { x } // no error, multiple input refs
|
|
|
|
|
|
|
|
fn in_static_and_out<'a>(x: &'a u8, _y: &'static u8) -> &'a u8 { x } // no error, static involved
|
|
|
|
|
|
|
|
fn deep_reference_1<'a, 'b>(x: &'a u8, _y: &'b u8) -> Result<&'a u8, ()> { Ok(x) } // no error
|
|
|
|
|
|
|
|
fn deep_reference_2<'a>(x: Result<&'a u8, &'a u8>) -> &'a u8 { x.unwrap() } // no error, two input refs
|
|
|
|
|
2015-08-13 07:51:24 +02:00
|
|
|
fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> { Ok(x) }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
2015-08-13 06:43:25 +02:00
|
|
|
type Ref<'r> = &'r u8;
|
|
|
|
|
2015-08-13 17:24:47 +02:00
|
|
|
fn lifetime_param_1<'a>(_x: Ref<'a>, _y: &'a u8) { } // no error, same lifetime on two params
|
2015-08-13 06:43:25 +02:00
|
|
|
|
2015-08-13 17:24:47 +02:00
|
|
|
fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) { }
|
2015-08-13 07:51:24 +02:00
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-13 06:43:25 +02:00
|
|
|
|
2015-08-13 17:24:47 +02:00
|
|
|
fn lifetime_param_3<'a, 'b: 'a>(_x: Ref<'a>, _y: &'b u8) { } // no error, bounded lifetime
|
|
|
|
|
2015-08-12 13:16:09 +02:00
|
|
|
struct X {
|
|
|
|
x: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl X {
|
2015-08-13 07:51:24 +02:00
|
|
|
fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
|
|
|
fn self_and_in_out<'s, 't>(&'s self, _x: &'t u8) -> &'s u8 { &self.x } // no error, multiple input refs
|
|
|
|
|
2015-08-13 07:51:24 +02:00
|
|
|
fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
|
|
|
|
//~^ERROR explicit lifetimes given
|
2015-08-12 13:16:09 +02:00
|
|
|
|
|
|
|
fn self_and_same_in<'s>(&'s self, _x: &'s u8) { } // no error, same lifetimes on two params
|
|
|
|
}
|
|
|
|
|
2015-08-13 17:40:45 +02:00
|
|
|
struct Foo<'a>(&'a u8);
|
|
|
|
|
|
|
|
impl<'a> Foo<'a> {
|
|
|
|
fn self_shared_lifetime(&self, _: &'a u8) {} // no error, lifetime 'a not defined in method
|
|
|
|
fn self_bound_lifetime<'b: 'a>(&self, _: &'b u8) {} // no error, bounds exist
|
|
|
|
}
|
2015-08-12 13:16:09 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|