From 7e85db645e35061d11897c049715c845fb4cf073 Mon Sep 17 00:00:00 2001 From: Florian Hartwig Date: Sun, 17 Jan 2016 17:53:41 +0100 Subject: [PATCH] Fix another false positive in lifetime elision lint The false positive occurred when we have an anonymous input lifetime and a named output lifetime. This is not elidable, because if we elided the output lifetime, it would be inferred to be the same as the input. --- src/lifetimes.rs | 1 - tests/compile-fail/lifetimes.rs | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lifetimes.rs b/src/lifetimes.rs index 1edd75a45aa1..83da3d8644ae 100644 --- a/src/lifetimes.rs +++ b/src/lifetimes.rs @@ -144,7 +144,6 @@ fn could_use_elision(cx: &LateContext, func: &FnDecl, slf: Option<&ExplicitSelf> match (&input_lts[0], &output_lts[0]) { (&Named(n1), &Named(n2)) if n1 == n2 => true, (&Named(_), &Unnamed) => true, - (&Unnamed, &Named(_)) => true, _ => false, // already elided, different named lifetimes // or something static going on } diff --git a/tests/compile-fail/lifetimes.rs b/tests/compile-fail/lifetimes.rs index 99c16917426e..eb161af9dc3c 100644 --- a/tests/compile-fail/lifetimes.rs +++ b/tests/compile-fail/lifetimes.rs @@ -119,5 +119,9 @@ fn alias_with_lt3<'a>(_foo: &FooAlias<'a> ) -> &'a str { unimplemented!() } // no warning, two input lifetimes fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b> ) -> &'a str { unimplemented!() } +fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() } //~ERROR explicit lifetimes given + +fn elided_input_named_output<'a>(_arg: &str) -> &'a str { unimplemented!() } + fn main() { }