-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Incorrect dead_code
lint with items only used in const
.
#118424
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
Comments
dead_code
lint with generics using type aliases in macros.dead_code
lint with type alias declared in macro from ident
passed to macro, used in expr
passed to macro.
dead_code
lint with type alias declared in macro from ident
passed to macro, used in expr
passed to macro.dead_code
lint with type alias used in const
.
@rustbot label -A-macros Upon further minimizing, this actually appears to have nothing to do with the type alias being declared in a macro; the warning shows up even for type T = u32;
const _: () = assert!(
std::mem::size_of::<T>() == std::mem::size_of::<T>()
);
const _A: () = assert!(
std::mem::size_of::<T>() == std::mem::size_of::<T>()
); The Note that |
@rustbot claim |
The problem happens without type T = u32;
const _A: usize = std::mem::size_of::<T>();
fn main() {} |
This also happens with several other kinds of items, not just type aliases: type T = u32;
const fn hmm() -> usize { 0 }
struct Struct;
const B: usize = 42;
impl Struct {
const fn hmmm(&self) -> usize { 0 }
}
const _A: usize =
std::mem::size_of::<T>()
+ hmm()
+ std::mem::size_of::<Struct>()
+ B
+ Struct.hmmm();
fn main() {
// let _a = _A; // uncomment for no warnings
} Compiling playground v0.0.1 (/playground)
warning: type alias `T` is never used
--> src/main.rs:1:6
|
1 | type T = u32;
| ^
|
= note: `#[warn(dead_code)]` on by default
warning: function `hmm` is never used
--> src/main.rs:2:10
|
2 | const fn hmm() -> usize { 0 }
| ^^^
warning: struct `Struct` is never constructed
--> src/main.rs:3:8
|
3 | struct Struct;
| ^^^^^^
warning: constant `B` is never used
--> src/main.rs:4:7
|
4 | const B: usize = 42;
| ^
warning: method `hmmm` is never used
--> src/main.rs:6:14
|
5 | impl Struct {
| ----------- method in this implementation
6 | const fn hmmm(&self) -> usize { 0 }
| ^^^^
warning: `playground` (bin "playground") generated 5 warnings
Finished dev [unoptimized + debuginfo] target(s) in 2.55s
Running `target/debug/playground` |
dead_code
lint with type alias used in const
.dead_code
lint with items only used in const
.
Uh oh!
There was an error while loading. Please reload this page.
Code
Original code
Current output
Warnings for original code
Output with
-Zmacro-backtrace
Desired output
Rationale and extra context
(Playground link)
The items
T
,Struct
,B
,hmm
, andhmmm
are not unused; and removing them causes the code to fail to compile.Other cases
No response
Anything else?
(edit: minimized, appears unrelated to macros)
The text was updated successfully, but these errors were encountered: