Skip to content

False-positive unused variable warning in the presence of unimplemented!() #88317

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
nzentzis opened this issue Aug 25, 2021 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nzentzis
Copy link

Given the following code: Playground

pub enum View {
    A, B
}

pub struct Foo;

impl Foo {
    pub fn do_stuff(&self, view: View) {
        let _: f32 = unimplemented!();
        match view {
            _ => {},
        }
    }
}

The current output warns about an unused parameter:

warning: unused variable: `view`
 --> src/lib.rs:8:28
  |
8 |     pub fn do_stuff(&self, view: View) {
  |                            ^^^^ help: if this is intentional, prefix it with an underscore: `_view`
  |
  = note: `#[warn(unused_variables)]` on by default

However, the view parameter is used in the match block, even though it'll never be executed as things stand. If I comment out the unimplemented!(), the warning goes away.

@nzentzis nzentzis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 25, 2021
@ghost
Copy link

ghost commented Aug 25, 2021

I thought this was intended behavior? The variable really is never used when the codes runs...

@ehuss
Copy link
Contributor

ehuss commented Aug 25, 2021

Thanks for the report! This is intended behavior, as the variables really aren't used since the "used" parts are in an unreachable block. Closing as a duplicate of #78136.

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants