Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lifetime error with return value #44875

Closed
cengiz-io opened this issue Sep 26, 2017 · 1 comment
Closed

Improve lifetime error with return value #44875

cengiz-io opened this issue Sep 26, 2017 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics

Comments

@cengiz-io
Copy link
Contributor

cengiz-io commented Sep 26, 2017

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!

🍻

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints WG-diagnostics Working group: Diagnostics labels Sep 26, 2017
@aidanhs aidanhs added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Sep 28, 2017
@estebank
Copy link
Contributor

estebank commented Jan 7, 2018

Current output:

error[E0623]: lifetime mismatch
 --> src/main.rs:9:9
  |
4 | fn foo2<'a, 'b>(a: &'a Foo, x: &'b i32) -> &'a i32 {
  |                                -------     -------
  |                                |
  |                                this parameter and the return type are declared with different lifetimes...
...
9 |         &*x
  |         ^^^ ...but data from `x` is returned here

@estebank estebank closed this as completed Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants