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

Strange span in borrow error in nested match. #74050

Closed
ehuss opened this issue Jul 5, 2020 · 3 comments · Fixed by #74125
Closed

Strange span in borrow error in nested match. #74050

ehuss opened this issue Jul 5, 2020 · 3 comments · Fixed by #74125
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Jul 5, 2020

I tried this code:

fn main() {
    let mut args = std::env::args_os();
    let _arg = match args.next() {
        Some(arg) => {
            match arg.to_str() {
                Some(s) => s,
                None => return,
            }
        }
        None => return,
    };
}

Previously, in 1.36 or earlier, it presented an error like this:

error[E0597]: `arg` does not live long enough
  --> src/main.rs:7:19
   |
5  |     let _arg = match args.next() {
   |         ---- borrow later stored here
6  |         Some(arg) => {
7  |             match arg.to_str() {
   |                   ^^^ borrowed value does not live long enough
...
13 |     };
   |     - `arg` dropped here while still borrowed

Starting with 1.37, the "dropped here while still borrowed" message points to an odd location:

error[E0597]: `arg` does not live long enough
  --> src/main.rs:7:19
   |
5  |     let _arg = match args.next() {
   |         ---- borrow later stored here
6  |         Some(arg) => {
7  |             match arg.to_str() {
   |                   ^^^ borrowed value does not live long enough
...
12 |         None => return,
   |            - `arg` dropped here while still borrowed

The earlier error looks more correct to me.

Bisected the change to nightly-2019-05-24, I would guess maybe it is #60174.

@ehuss ehuss added the C-bug Category: This is a bug. label Jul 5, 2020
@jonas-schievink jonas-schievink added A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 5, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 5, 2020
@jonas-schievink jonas-schievink added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Jul 5, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 5, 2020

Without using any methods:

fn main() {
    let _arg = match Some(()) {
        Some(arg) => {
            match Some(&arg) {
                Some(s) => s,
                None => return,
            }
        } // <- this is probably the desired location
        None => return,
    };
}

results in

error[E0597]: `arg` does not live long enough
  --> src/main.rs:6:24
   |
4  |     let _arg = match Some(()) {
   |         ---- borrow later stored here
5  |         Some(arg) => {
6  |             match Some(&arg) {
   |                        ^^^^ borrowed value does not live long enough
...
11 |         None => return,
   |            - `arg` dropped here while still borrowed

@LeSeulArtichaut LeSeulArtichaut added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 6, 2020
@LeSeulArtichaut
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization WG procedure.

Bisected the change to nightly-2019-05-24, I would guess maybe it is #60174.

cc @matthewjasper

@matthewjasper
Copy link
Contributor

This should probably be prev_token:

let hi = self.token.span;

Manishearth added a commit to Manishearth/rust that referenced this issue Jul 8, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 8, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 9, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 9, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 10, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 10, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 10, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 10, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 11, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 11, 2020
@bors bors closed this as completed in 3c63fba Jul 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants