Skip to content

Break-outside-of-loop false positives in try block #14701

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
ldanilek opened this issue May 1, 2023 · 1 comment · Fixed by #14705
Closed

Break-outside-of-loop false positives in try block #14701

ldanilek opened this issue May 1, 2023 · 1 comment · Fixed by #14705
Assignees
Labels
A-hir hir and hir-def related C-bug Category: bug

Comments

@ldanilek
Copy link

ldanilek commented May 1, 2023

Looks like #14503. has been happening since then and i was waiting for the fix to be published, but it looks like rust-analyzer was released with the fix and my issue persists.

in this function, which notably has a try-block, containing a closure that returns a Result, and within the closure uses the ? syntax:

fn _do_thing() {
    let r: anyhow::Result<()> = try {
        let v = vec![1, 2, 3];
        v.iter().map(|i| {
            let result = Some("hi").ok_or(anyhow::anyhow!("bad"));
            result?; // this line has error
            anyhow::Ok(i)
        }).collect::<anyhow::Result<Vec<_>>>()?;
    };
    r.unwrap();
}

We get a "break outside of loop" error, which is interesting because the code contains no break statements.

Screen Shot 2023-05-01 at 11 27 22 AM

Note in contrast to #14503, there is nothing async here -- instead we have a try block enabled by #![feature(try_blocks)]

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
happens in pre-release and release which are both rust-analyzer version: 0.3.1498-standalone (3a27518fe 2023-04-30)

rustc version: (eg. output of rustc -V)
rustc 1.69.0-nightly (31f858d9a 2023-02-28)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

@ldanilek ldanilek added the C-bug Category: bug label May 1, 2023
@Veykril Veykril added the A-hir hir and hir-def related label May 1, 2023
@Veykril
Copy link
Member

Veykril commented May 1, 2023

Looks like we mess up resetting the tracked try block when we encounter a closure nested in a try block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-hir hir and hir-def related C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants