Skip to content

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

Closed
@lcnr

Description

@lcnr

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`

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions