properly handle anonymous regions appearing in return type- named-anon conflicts (original) (raw)

These cases, going by the way #42669 for one named and other anonymous lifetime parameter , the error message generated would suggest consider changing type of self to &'a i32. In the first case, this is fine but the second case, with self.field not being the return value, the message is wrong and should only suggest changing the return type. We need to differentiate both the cases and fix the error message for the second case.

fn foo<'a>(&self, x: &'a i32) -> &i32 { // Preferred message: // fn foo<'a>(&self, x: &'a i32) -> &i32 { // ----- ---- consider changing to &'a i32 // | // consider changing to &'a self if true { &self.field } else { x } }

fn foo<'a>(&self, x: &'a i32) -> &i32 { // preferred error // fn foo<'a>(&self, x: &'a i32) -> &i32 {
// ---- consider changing to &'a i32 x

// error[E0611]: explicit lifetime required in the type of self // | // 33 | fn foo<'a>(&self, x: &'a i32) -> &i32 { // | ^^^^^ consider changing the type of self to &'a Foo // 34 | //
// 35 | x // | - lifetime 'a required }

cc @nikomatsakis