Skip to content

Merge unused_tuple_struct_fields into dead_code#118297

Merged
bors merged 8 commits into
rust-lang:masterfrom
shepmaster:warn-dead-tuple-fields
Jan 5, 2024
Merged

Merge unused_tuple_struct_fields into dead_code#118297
bors merged 8 commits into
rust-lang:masterfrom
shepmaster:warn-dead-tuple-fields

Conversation

@shepmaster

@shepmaster shepmaster commented Nov 25, 2023

Copy link
Copy Markdown
Member

This implicitly upgrades the lint from allow to warn and places it into the unused lint group.

Discussion on Zulip

@shepmaster shepmaster added the I-lang-nominated Nominated for discussion during a lang team meeting. label Nov 25, 2023
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2023
@rust-log-analyzer

This comment has been minimized.

@shepmaster shepmaster force-pushed the warn-dead-tuple-fields branch from 876ee9f to 048aa9d Compare November 25, 2023 20:45
@rust-log-analyzer

This comment has been minimized.

@shepmaster shepmaster force-pushed the warn-dead-tuple-fields branch from 048aa9d to d254a5f Compare November 25, 2023 21:38
@rustbot

rustbot commented Nov 25, 2023

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@compiler-errors

Copy link
Copy Markdown
Contributor

I'd happily take a PR that proactively fixes all of the compiler warnings. Most of them can just be removed, except for the TyCtxt one, which can be replaced with PhantomData.

@shepmaster

Copy link
Copy Markdown
Member Author

Yeah, my plan is to find all of the current issues and submit it as a separate PR, it’s just easier to find it here first.

I was attempting to do that without causing undue noise (thanks rustbot 👀).

Comment thread compiler/rustc_infer/src/infer/nll_relate/mod.rs Outdated
@shepmaster shepmaster force-pushed the warn-dead-tuple-fields branch from 0f05b27 to b1f9900 Compare November 26, 2023 15:05
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Nov 26, 2023
@shepmaster shepmaster marked this pull request as draft November 26, 2023 15:05
@rust-log-analyzer

This comment has been minimized.

@traviscross

Copy link
Copy Markdown
Contributor

Regarding the T-lang nomination, one of the open questions here is whether this should be part of the dead_code lint now that we're making it warn-by-default.

The motivation for making this part of dead_code is that unused fields of normal structs warn under dead_code, so this would be consistent. E.g.:

warning: field `a` is never read
 --> src/lib.rs:1:12
  |
1 | struct A { a: () }
  |        -   ^
  |        |
  |        field in this struct
  |
  = note: `#[warn(dead_code)]` on by default

On 2022-01-25, T-lang requested this lint be separated from dead_code so that it could be introduced gradually and so people could disable it specifically. The motivation seems to have been the belief that this lint could be "harder to fix than removing named fields, because removing a positional field changes the indices of the following fields".

However, after that decision, on 2022-01-26, @pnkfelix suggested a change to the lint that would allow people to resolve the warning without changing field indices:

...I thought: "well, we should let people include () fields (i.e. not warn about them), and perhaps even have the lint diagnostic here suggest either removing the field or making it have () type. That would keep the indices unchanged."

This change was implemented and is suggested as part of the error message, e.g.:

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);
   | 

In discussion in T-compiler in Zulip, the feeling seemed to be that this should be part of dead_code. Given the change suggested by @pnkfelix and implemented in the lint that resolves the issue of preserving field indices, do we now agree?

@bors

bors commented Nov 27, 2023

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #118370) made this pull request unmergeable. Please resolve the merge conflicts.

@shepmaster

Copy link
Copy Markdown
Member Author

a PR that proactively fixes all of the compiler warnings.

Opened in #118382

@traviscross

Copy link
Copy Markdown
Contributor

@rustbot labels -I-lang-nominated

This was discussed in the T-lang triage call today, and the consensus was that it's OK for this to become part of the dead_code lint.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Nov 29, 2023
@traviscross traviscross added the T-lang Relevant to the language team label Nov 29, 2023
@shepmaster shepmaster force-pushed the warn-dead-tuple-fields branch from b1f9900 to 0ee2b06 Compare November 29, 2023 18:42
@shepmaster shepmaster changed the title Convert unused_tuple_struct_fields to warn-by-default Merge unused_tuple_struct_fields into dead_code Nov 29, 2023
@shepmaster

Copy link
Copy Markdown
Member Author

r? compiler

@shepmaster shepmaster marked this pull request as ready for review November 29, 2023 18:44
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bit of a nitpick. Feel free to change labels to waiting on review once CI is green

Comment thread compiler/rustc_passes/src/dead.rs Outdated
Comment on lines +1015 to +1017
if is_pos {
is_positional = true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just is_positional = is_pos or is_positional |= is_pos?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can't we just do a single check is variant is tuple-like or not, instead of trying to move this out of the loop?..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this [...] is_positional |= is_pos?

Yeah, I thought about that but wanted to make the diff smaller / easier to see how it changed. Happy to update to this.

do a single check is variant is tuple-like or not

That seems plausible, but I don't know my way around the compiler enough to do so. Got any hints?

instead of trying to move this out of the loop

I thought you were suggesting that we should move it out of the loop — I must not understand what you mean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you were suggesting that we should move it out of the loop — I must not understand what you mean.

Right, I see why this is confusing.

"trying to move this out of the loop"

this refers to the is_pos which is moved into is_positional, which is outside of the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.