Skip to content

“consider using an explicit lifetime parameter” note appears before the corresponding error #15433

@ftxqxd

Description

@ftxqxd
fn foo(x: Option<&int>) -> &int {
    x.unwrap()
}
fn main() {}

Yields the following error:

<anon>:1:1: 3:2 note: consider using an explicit lifetime parameter as shown: fn foo<'a>(x: Option<&'a int>) -> &'a int
<anon>:1 fn foo(x: Option<&int>) -> &int {
<anon>:2     x.unwrap()
<anon>:3 }
<anon>:2:5: 2:15 error: cannot infer an appropriate lifetime due to conflicting requirements
<anon>:2     x.unwrap()
             ^~~~~~~~~~
<anon>:2:5: 2:15 error: mismatched types: expected `&int` but found `&int` (lifetime mismatch)
<anon>:2     x.unwrap()
             ^~~~~~~~~~

This could be mildly confusing when there are multiple error messages, and so someone may misinterpret some note as being attached to a previous error. This error should probably appear after the cannot infer an appropriate lifetime error or perhaps after the mismatched types error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions