Skip to content

Unused variables lint does not work inside an array length expression #77169

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
ecstatic-morse opened this issue Sep 24, 2020 · 1 comment · Fixed by #77281
Closed

Unused variables lint does not work inside an array length expression #77169

ecstatic-morse opened this issue Sep 24, 2020 · 1 comment · Fixed by #77281
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Sep 24, 2020

Array length expressions can can do anything that a const initializer can. However, the unused variables lint does not work inside an array length expression. For example,

fn main() {
    let _ = [(); {
        let x = 42;
        35
    }];
}

(Playground)

...compiles with no warnings:

   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.51s
     Running `target/debug/playground`

@ecstatic-morse ecstatic-morse added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. labels Sep 24, 2020
@ecstatic-morse ecstatic-morse changed the title Unused variables lint does not work inside an array initializer Unused variables lint does not work inside an array length expression Sep 24, 2020
@tesuji
Copy link
Contributor

tesuji commented Sep 25, 2020

Seems like the liveness of x is over the ExitNode contains it, if I read the log correctly.
https://gist.github.com/lzutao/2053546ae057353af4f31cddc4676f58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants