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

Incorrect report of undeclared label #15516

Closed
s0lst1ce opened this issue Aug 25, 2023 · 2 comments · Fixed by #15517
Closed

Incorrect report of undeclared label #15516

s0lst1ce opened this issue Aug 25, 2023 · 2 comments · Fixed by #15517
Labels
A-ide general IDE features C-bug Category: bug

Comments

@s0lst1ce
Copy link

rust-analyzer version: 0.3.1631-standalone

rustc version: rustc 1.72.0 (5680fa18f 2023-08-23)

relevant settings: I don't believe I've set anything particular. I can share the rust-analyzer settings file if need be.
Hello, I'm having an issue with ra where it reports a use of undeclared label `'my_label` (which I easily visualize with error lens on code).
Neither cargo check nor clippy report any warning (much less error as is the case with ra) regarding this when I run them in my terminal.
I'm not sure about a minimal example but here's one I quickly crafted from the actual snippet that causing me the issue.

struct PlaceHolder;

impl Iterator for PlaceHolder {
    type Item = Result<Option<()>, ()>;

    fn next(&mut self) -> Option<Self::Item> {
        Some(Ok(Some(())))
    }
}

fn main() {
    let mut placeholder = PlaceHolder;
    'my_label: while let Some(a) = match placeholder.next().unwrap() {
        Ok(_) => todo!(),
        Err(err) => {
            continue 'my_label; // use of undeclared label `'my_label`
        }
    } {
        a
    }
}

image

@s0lst1ce s0lst1ce added the C-bug Category: bug label Aug 25, 2023
@s0lst1ce
Copy link
Author

And though this example does come with its share of warnings cargo clippy | grep error | wc -l outputs 0.

@xffxff
Copy link
Contributor

xffxff commented Aug 26, 2023

It looks like RA is unable to resolve the label in the match arm

fn main() {
    let mut optional = Some(0);

    'my_label: while let Some(a) = match optional {
        None => break 'my_label,
        Some(val) => Some(val),
    } {
        println!("{}", a);
        optional = None;
        continue 'my_label;
    }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ide general IDE features C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants