-
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
Warn about dead tuple struct fields #92972
Conversation
This comment has been minimized.
This comment has been minimized.
c428442
to
8481c2a
Compare
This comment has been minimized.
This comment has been minimized.
8481c2a
to
1ad1040
Compare
This comment has been minimized.
This comment has been minimized.
1ad1040
to
33b305d
Compare
This comment has been minimized.
This comment has been minimized.
33b305d
to
6efceca
Compare
This comment has been minimized.
This comment has been minimized.
6efceca
to
e227330
Compare
This comment has been minimized.
This comment has been minimized.
e227330
to
ee9a896
Compare
@@ -2312,7 +2312,7 @@ impl TypeBinding { | |||
crate enum SubstParam { | |||
Type(Type), | |||
Lifetime(Lifetime), | |||
Constant(Constant), | |||
Constant, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I'm not sure about this change. I'll have to look into it.
@@ -30,7 +30,7 @@ pub type DoubleDouble = DoubleFloat<ieee::Double>; | |||
// FIXME: Implement all operations in DoubleDouble, and delete these | |||
// semantics. | |||
// FIXME(eddyb) This shouldn't need to be `pub`, it's only used in bounds. | |||
pub struct FallbackS<F>(F); | |||
pub struct FallbackS<F>(#[allow(dead_code)] F); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we had a better name for this than "dead code". I'm actually surprised it's not "unused" instead.
I suppose this change is small enough, and just a lint attribute, that it's probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you could use unused
as well, but that is the lint group containing the dead_code
lint, so the latter is more precise (not that it makes a difference here). Also, just to be clear: I didn't come up with the name here, it is also called dead_code
for named fields.
In any case: Thanks for having a look!
I don't think I have enough knowledge of this code nor time to review this PR in its entirety, but I'll try to review some of the rustdoc changes when I get a chance. Thanks for working on this! :) r? rust-lang/compiler |
I do think this needs a lang signoff; nominating. |
Given that this may be harder for people to change, I think it deserves a separate sub-lint of I do think this is a good idea, and we should make this change. |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ee9a896 with merge 4b8f3ac2f6e62978663873ba7b287f5df5f314d9... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
We discussed this in today's @rust-lang/lang meeting. We'd like to go with a gradual approach:
Thanks for working on this! |
I couldn't tell from skimming the PR: What does this warning do for fields of unit type, I ask because my first reaction when I read:
is that I thought: "well, we should let people include But, like I said above, I cannot tell from a quick read what this does for |
☔ The latest upstream changes (presumably #93548) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: |
closing this as inactive |
@rustbot label -S-inactive @Dylan-DPC Sorry for the delay here, I didn't mean to abandon this. I've updated the branch, can you reopen this PR, please? Specifically, I have added this functionality as a new allow-by-default lint Furthermore, I have disabled the lint for fields of unit type as requested in #92972 (comment), so error messages now look like this:
|
@FabianWolff if you force push closed PR it can no longer be reopened. |
Ah, I didn't know this, I thought I was lacking the necessary permissions for reopening. Thanks for the hint @mati865! |
@Dylan-DPC you should mention the force-push caveat as part of your canned closing message. |
I believe you can reopen a PR if you change the commit of the branch back to what it was when you closed it. |
… r=estebank Warn about dead tuple struct fields Continuation of rust-lang#92972. Fixes rust-lang#92790. The language team has already commented on this in rust-lang#92972 (comment); I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (rust-lang#92972 (comment)), so error messages look like this: ``` error: field is never read: `1` --> $DIR/tuple-struct-field.rs:6:21 | LL | struct Wrapper(i32, [u8; LEN], String); | ^^^^^^^^^ | help: change the field to unit type to suppress this warning while preserving the field numbering | LL | struct Wrapper(i32, (), String); | ~~ ``` r? `@joshtriplett`
…=estebank Warn about dead tuple struct fields Continuation of rust-lang#92972. Fixes rust-lang#92790. The language team has already commented on this in rust-lang#92972 (comment); I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (rust-lang#92972 (comment)), so error messages look like this: ``` error: field is never read: `1` --> $DIR/tuple-struct-field.rs:6:21 | LL | struct Wrapper(i32, [u8; LEN], String); | ^^^^^^^^^ | help: change the field to unit type to suppress this warning while preserving the field numbering | LL | struct Wrapper(i32, (), String); | ~~ ``` r? `@joshtriplett`
…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
Fixes #92790. Since the introduction of warnings about unused fields (commit 0271224 in 2014), only named fields got warnings, but not positional fields in tuple structs or tuple enum variants.
Warning about positional fields is probably somewhat controversial because
I am putting this up for discussion now. Maybe this should be nominated for language team sign-off as well?
cc @shepmaster
r? @camelid