Skip to content

Format self correctly #42700

Open
Open
@gaurikholkar-zz

Description

@gaurikholkar-zz

Fix the formatting of self in the error message.

struct Foo {
  field: i32
}

impl Foo {

fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {

    if true { self } else { x }
    
    // now gives:
// error[E0611]: explicit lifetime required in the type of `self`
//    |
// 20 |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
//    |                  ^^^^^ consider changing the type of `self` to `&'a Foo`
// ...
// 25 |         if true { self } else { x }
//    |                   ---- lifetime `'a` required

    // should actually:
// error[E0611]: explicit lifetime required in the type of `self`
//    |
// 20 |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
//    |                  ^^^^^ consider changing to `&'a self`
// ...
// 25 |         if true { self } else { x }
//    |                   ---- lifetime `'a` required
  }
  
}
^^^^^ consider changing the type of `self` to `&'a Foo`

should actually be

^^^^^ consider changing to `&'a self`

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