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

constant as trait param results in incorrect dead code warning #70225

Closed
lcnr opened this issue Mar 21, 2020 · 3 comments · Fixed by #77073
Closed

constant as trait param results in incorrect dead code warning #70225

lcnr opened this issue Mar 21, 2020 · 3 comments · Fixed by #77073
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 21, 2020

I tried this code:

#![feature(const_generics)]

const L: usize = 3;

fn main() {
    let p = Printer {};
    p.print();
}

trait Print<const N: usize> {
    fn print(&self) -> usize {
        3
    }
}

struct Printer {}
impl Print<L> for Printer {}

playground

I expected to see this happen: no dead_code warning is emitted.

Instead, this happened:

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

warning: constant item is never used: `L`
 --> src/main.rs:3:1
  |
3 | const L: usize = 3;
  | ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.70s
     Running `target/debug/playground`
@lcnr lcnr added the C-bug Category: This is a bug. label Mar 21, 2020
@lcnr lcnr changed the title constant as trait param results in incorrect dead code warning constant as const trait param results in incorrect dead code warning Mar 21, 2020
@lcnr lcnr changed the title constant as const trait param results in incorrect dead code warning constant as trait param results in incorrect dead code warning Mar 21, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 21, 2020
@varkor
Copy link
Member

varkor commented Sep 13, 2020

I'm not sure this needs to block min_const_generics, but it affects it, so marking as blocking for now.

@lcnr
Copy link
Contributor Author

lcnr commented Sep 22, 2020

@rustbot claim

@lcnr
Copy link
Contributor Author

lcnr commented Sep 22, 2020

This is actually not an issue related to const generics 😅 It does not look at trait impls even if they are used as long as they don't overwrite the relevant method.

enum Foo {
    Bar,
}

fn main() {
    let p = [0; 0];
    p.print();
}

trait Print {
    fn print(&self) -> usize {
        3
    }
}

impl Print for [u32; Foo::Bar as usize] {
    // fn print(&self) -> usize {
    //    3
    // }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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