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

[NLL] Lifetimes errors in a function can mask later errors in same function #96331

Open
marmeladema opened this issue Apr 23, 2022 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@marmeladema
Copy link
Contributor

For test src/test/ui/regions/region-multiple-lifetime-bounds-on-fns-where-clause.rs, under NLL, a lifetime may not live long enough error is missing.
This is a behavior change which should be investigated.

See comment posted by @jackh726 in #96212 (comment)

@marmeladema marmeladema added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 23, 2022
@marmeladema
Copy link
Contributor Author

@rustbot label +A-NLL +NLL-diagnostics

@rustbot rustbot added A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal labels Apr 23, 2022
@m-ou-se
Copy link
Member

m-ou-se commented May 17, 2022

Reduced test case:

fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
    *x = *y;
    *z = *y;
}

Rustc output:

error[E0623]: lifetime mismatch
 --> src/main.rs:2:10
  |
1 | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
  |                          ---------          --------- these two types are declared with different lifetimes...
2 |     *x = *y;
  |          ^^ ...but data from `y` flows into `x` here

error[E0623]: lifetime mismatch
 --> src/main.rs:3:10
  |
1 | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
  |                                             ---------          ---------
  |                                             |
  |                                             these two types are declared with different lifetimes...
2 |     *x = *y;
3 |     *z = *y;
  |          ^^ ...but data from `y` flows into `z` here

error: aborting due to 2 previous errors

Rustc output with -Z borrowck=mir:

error: lifetime may not live long enough
 --> src/main.rs:2:5
  |
1 | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
  |      --  -- lifetime `'b` defined here
  |      |
  |      lifetime `'a` defined here
2 |     *x = *y;
  |     ^^^^^^^ assignment requires that `'b` must outlive `'a`
  |
  = help: consider adding the following bound: `'b: 'a`

error: aborting due to previous error

It doesn't give an error about the *z = *y; line.

However, if you remove the *x = *y; line, it doesn't succeed. It then produces the right error:

error: lifetime may not live long enough
 --> src/main.rs:2:5
  |
1 | fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
  |          --  -- lifetime `'c` defined here
  |          |
  |          lifetime `'b` defined here
2 |     *z = *y;
  |     ^^^^^^^ assignment requires that `'b` must outlive `'c`
  |
  = help: consider adding the following bound: `'b: 'c`

So, this doesn't seem like a case where invalid code is accepted. Just a case where diagnostics are incomplete.

@m-ou-se
Copy link
Member

m-ou-se commented May 17, 2022

When using two unrelated variables/lifetimes, it does produce both errors:

fn b<'a, 'b, 'c, 'd>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize, z2: &mut &'d isize) {
    *x = *y;
    *z = *z2;
}

@m-ou-se
Copy link
Member

m-ou-se commented May 17, 2022

When doing *x = *y; *x = *y; (the same thing twice), you only get the error once. It seems that in the new mode, that 'deduplicating' effect also applies to *x = *y; *z = *y;.

(*x = *y; *y = *z; (last assignment flipped) does produce two errors with and without nll.)

@jackh726
Copy link
Member

Thanks @m-ou-se for looking at this!

I think based on this, it should be okay to move forward without "fixing" this. Seems like only a diagnostics thing instead of accidently allowing more code.

@jackh726 jackh726 changed the title [NLL] Investigate behavior difference with non-nll for region-multiple-lifetime-bounds-on-fns-where-clause.rs test [NLL] Lifetimes errors in a function can mask later errors in same function May 21, 2022
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 A-NLL Area: Non Lexical Lifetimes (NLL) NLL-diagnostics Working torwads the "diagnostic parity" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants