Skip to content

properly handle anonymous regions appearing in return type- named-anon conflicts #42703

Open
@gaurikholkar-zz

Description

@gaurikholkar-zz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions