Skip to content

Misplaced span for the error "does not live long enough" #39268

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

Closed
KalitaAlexey opened this issue Jan 24, 2017 · 3 comments
Closed

Misplaced span for the error "does not live long enough" #39268

KalitaAlexey opened this issue Jan 24, 2017 · 3 comments
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

@KalitaAlexey
Copy link
Contributor

Playground

Code:

fn main() {
    let mut x = &5;
    {
        let y = 5;
        x = &y;
    }
}

Compiler's output:

error: `y` does not live long enough
 --> <anon>:6:5
  |
5 |         x = &y;
  |              - borrow occurs here
6 |     }
  |     ^ `y` dropped here while still borrowed
7 | }
  | - borrowed value needs to live until here

error: aborting due to previous error

Look at --> <anon>:6:5.
It points to the },
but I expected it to point to the y.

Look at | ^y dropped here while still borrowed.
It is treated as a primary span,
but I expected | - borrow occurs here to be treated as a primary span.

It is bad for editors, i.e., VSCode.

@Mark-Simulacrum
Copy link
Member

It's not strictly speaking obvious which span should be the primary, but probably the first one (borrow occurs here) is better.

@Mark-Simulacrum Mark-Simulacrum added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 20, 2017
@Mark-Simulacrum
Copy link
Member

err, not E-needstest - this needs to be fixed.

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Jun 17, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank estebank added E-needs-mentor WG-diagnostics Working group: Diagnostics labels Dec 12, 2017
@estebank
Copy link
Contributor

This seems to have been done on purpose. @nikomatsakis do you see any reason not to remove the db.span = ... reassignments? I'm leaning heavily towards doing it.

@estebank estebank added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. and removed E-needs-mentor labels Dec 13, 2017
@estebank estebank removed the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Dec 14, 2017
bors added a commit that referenced this issue Dec 16, 2017
Point at var in short lived borrows instead of drop location

For RLS' sake, point at the borrow location as primary span for short lived borrows, instead of the borrow drop location.

Fix #39268.
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