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

dead_code lint triggers even though function is used in const pattern #78171

Closed
camelid opened this issue Oct 21, 2020 · 3 comments · Fixed by #88036
Closed

dead_code lint triggers even though function is used in const pattern #78171

camelid opened this issue Oct 21, 2020 · 3 comments · Fixed by #88036
Assignees
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented Oct 21, 2020

This should compile without warnings (playground):

#![allow(incomplete_features)]
#![feature(inline_const)]

const fn one() -> i32 {
    1
}

fn main() {
    match 1 {
        const { one() } => {}
        _ => {}
    }
}

Yet it warns:

   Compiling playground v0.0.1 (/playground)
warning: function is never used: `one`
 --> src/main.rs:4:10
  |
4 | const fn one() -> i32 {
  |          ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.80s
     Running `target/debug/playground`
@camelid camelid added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. A-patterns Relating to patterns and pattern matching F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) labels Oct 21, 2020
@camelid
Copy link
Member Author

camelid commented Oct 21, 2020

Note that this only occurs in const patterns. This produces no warnings (playground):

#![allow(incomplete_features)]
#![feature(inline_const)]

const fn one() -> i32 {
    1
}

fn main() {
    match const { one() } {
        1 => {}
        _ => {}
    }
}

Output:

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

@camelid camelid changed the title "function is never used" lint triggers even though function is used in const pattern dead_code lint triggers even though function is used in const pattern Oct 21, 2020
@camelid
Copy link
Member Author

camelid commented Oct 21, 2020

Cc @spastorino – this only occurs with inline const expressions; no warning is triggered with const items.

@JohnTitor JohnTitor added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 21, 2020
@nbdd0121
Copy link
Contributor

@rustbot claim

camsteffen added a commit to camsteffen/rust that referenced this issue Aug 15, 2021
Fix dead code warning when inline const is used in pattern

Fixes rust-lang#78171
@bors bors closed this as completed in 016f691 Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-patterns Relating to patterns and pattern matching C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) 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.

3 participants