Skip to content

Strange span in borrow error in nested match. #74050

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions