diff --git a/src/lifetimes.rs b/src/lifetimes.rs index c3c915ea777..0127822dbde 100644 --- a/src/lifetimes.rs +++ b/src/lifetimes.rs @@ -115,8 +115,8 @@ fn could_use_elision(func: &FnDecl, slf: Option<&ExplicitSelf>, } else if output_lts.is_empty() { // no output lifetimes, check distinctness of input lifetimes - // only one reference with unnamed lifetime, ok - if input_lts.len() == 1 && input_lts[0] == Unnamed { + // only unnamed and static, ok + if input_lts.iter().all(|lt| *lt == Unnamed || *lt == Static) { return false; } // we have no output reference, so we only need all distinct lifetimes diff --git a/tests/compile-fail/lifetimes.rs b/tests/compile-fail/lifetimes.rs index 287a8199d2c..a5597e6478f 100755 --- a/tests/compile-fail/lifetimes.rs +++ b/tests/compile-fail/lifetimes.rs @@ -13,6 +13,8 @@ fn same_lifetime_on_input<'a>(_x: &'a u8, _y: &'a u8) { } // no error, same life fn only_static_on_input(_x: &u8, _y: &u8, _z: &'static u8) { } // no error, static involved +fn mut_and_static_input(_x: &mut u8, _y: &'static str) { } + fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 { x } //~^ERROR explicit lifetimes given @@ -60,7 +62,6 @@ 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 } -static STATIC: u8 = 1; fn main() { }