Skip to content

Improve lifetime error with return value #44875

Closed
@cengiz-io

Description

@cengiz-io

Hello!

(this shall be considered an item under #42516)

While me and @nikomatsakis were working on #42701 we've discovered that this case is not handled properly. (properly: didn't use new lifetime error messages)

struct Foo {
    field: i32,
}
fn foo2<'a, 'b>(a: &'a Foo, x: &'b i32) -> &'a i32 {
    if true {
        let p: &i32 = &a.field;
        &*p
    } else {
        &*x
    }
}
fn main() {}

This currently shows a error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements. It should show one of the E06XX errors instead.

@nikomatsakis said that fix might be dependent on this: #44124

So, this issue is a reminder for us to fix that case. Any help is more than welcome!

🍻

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.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions