-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
rustc complains about unused code if item is used in #[automatically_derived]
context
#126031
Comments
Okay, I submitted it under the wrong category. Apologies for that. Clearly a diagnostic issue. |
@rustbot modify labels: -regression-from-stable-to-stable +A-diagnostics |
@rustbot modify labels: -I-prioritize +T-compiler |
@rustbot claim |
@apiraino After some investigation I don't think this is a regression. We can construct the following, which will also trigger use std::fmt::Debug;
struct T;
struct Thing {}
#[automatically_derived]
impl Debug for Thing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let _x = T;
write!(f, "1")
}
}
fn main() {
let hello = Thing {};
println!("{hello:?}");
} Before 1.78, dead code analysis will check all impls regardless of whether the struct is used or not, so that we don't see such warnings cause it has an impl block. In fact, the reason is that the @aumetra in the Real-world example, it's because I don't know which macro the |
It's actually part of |
@aumetra furthermore, #[derive(Debug)]
struct T(i32);
fn main() {
let x = T(1);
println!("{x:?}")
} so that we can still get As a comparison, I guess another way to solve this in the real-world example is to print differently when meeting different |
Code
I tried this code:
I expected to see this happen: The code compiles without any warnings since, the
Identity
struct is clearly used.Instead, this happened: The compiler emits a
dead_code
lint, telling me that the struct is never constructedExample where this can occur: when using the
derive_more
crate to derive a specializedDebug
implementation, and the usage ofderive_more::Debug
utilizes a formatter struct to avoid allocating into an intermediate heap allocated bufferReal-world example
Version it worked on
It most recently worked on: Rust 1.77.2
Version with regression
rustc --version --verbose
:@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged
The text was updated successfully, but these errors were encountered: