-
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
dead_code suggestion would break the semantics of code using#[repr(transparent)]
#119659
Comments
``` error: field `0` is never read --> bpf/aya-bpf/src/helpers.rs:737:22 | 737 | pub struct PrintkArg(u64); | --------- ^^^ | | | field in this struct | = note: `PrintkArg` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis = note: `-D dead-code` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(dead_code)]` help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field | 737 | pub struct PrintkArg(()); | ~~ ``` See rust-lang/rust#119659.
Yes, the standard library had something similar and we allowed the warning: rust/library/alloc/src/boxed/thin.rs Lines 173 to 175 in 26194a3
Note that this isn't actually new, just recently applied to tuple struct fields. If you had used a named field: #[repr(transparent)]
pub struct PrintkArg {
z: u64,
} You'd get less of a suggestion:
In #119645 we are discussing improvements to the lint message. My own opinion is that the combination of |
#[repr(transparent)]
#[repr(transparent)]
Of note is that |
Since repr(transparent) means you can either We had the same issue pop up in lccc for a type with a single ignored field that exists for a padding byte so that the definition can be matched in pre-C++20 code. |
@rustbot labels +T-lang +I-lang-nominated Nominating so we can answer the question, "should we suppress this lint for |
I think there's some utility in having users However it is weird that |
We talked about this in today's @rust-lang/lang meeting. We agreed that we should treat |
@rustbot labels -I-lang-nominated As Josh said, there was a clear consensus to do this. Let's unnominate. |
I'm assigning this P-high because we definitely should fix it since it may inadvertently affect unsafe code via the |
…ent, r=Nilstrieb dead_code treats #[repr(transparent)] the same as #[repr(C)] In rust-lang#92972 we enabled linting on unused fields in tuple structs. In rust-lang#118297 that lint was enabled by default. That exposed issues like rust-lang#119659, where the fields of a struct marked `#[repr(transparent)]` were reported by the `dead_code` lint. The language team [decided](rust-lang#119659 (comment)) that the lint should treat `repr(transparent)` the same as `#[repr(C)]`. Fixes rust-lang#119659
Rollup merge of rust-lang#120107 - shepmaster:dead-code-repr-transparent, r=Nilstrieb dead_code treats #[repr(transparent)] the same as #[repr(C)] In rust-lang#92972 we enabled linting on unused fields in tuple structs. In rust-lang#118297 that lint was enabled by default. That exposed issues like rust-lang#119659, where the fields of a struct marked `#[repr(transparent)]` were reported by the `dead_code` lint. The language team [decided](rust-lang#119659 (comment)) that the lint should treat `repr(transparent)` the same as `#[repr(C)]`. Fixes rust-lang#119659
…lstrieb dead_code treats #[repr(transparent)] the same as #[repr(C)] In #92972 we enabled linting on unused fields in tuple structs. In #118297 that lint was enabled by default. That exposed issues like #119659, where the fields of a struct marked `#[repr(transparent)]` were reported by the `dead_code` lint. The language team [decided](rust-lang/rust#119659 (comment)) that the lint should treat `repr(transparent)` the same as `#[repr(C)]`. Fixes #119659
This occurs in aya:
https://github.com/aya-rs/aya/blob/e1aefa4e87970553dc60549141b3b4cf883f4366/bpf/aya-bpf/src/helpers.rs#L734-L737
On a nightly that includes #118297 I get:
In a strict sense the compiler is correct. That's because
PrintkArg
is used like so:Thus the compiler's suggestion would break the semantics of this code. Playground. /cc @shepmaster
The text was updated successfully, but these errors were encountered: