Skip to content

Conversation

CrooseGit
Copy link
Contributor

@CrooseGit CrooseGit commented Aug 27, 2025

Fixes #140962

Uplift the clippy::needless_maybe_sized lint into rustc as redundant_sizedness_bounds. This is useful for #144404 as it deals with redundant bound that would need to be addressed during migration.


redundant_sizedness_bounds

(warn-by-default)

The needless_maybe_sized lint checks that ?Sized bounds aren't redundant. This lint is extended to do the equivalent checks for the sizedness traits introduced by #144404 and thus renamed from needless_maybe_sized.

Example

// `T` cannot relaxed the `Size` bound because `Clone` requires it to be `Sized`.
fn f<T: Clone + ?Sized>(t: &T) {}
// `T` must already be `Sized`, so the bound is redundant.
fn g<T: Clone + Sized>() {}

Explanation

Relaxing a default Sized bound with ?Sized does nothing when there's another bound with a Sized supertrait (Clone in the example above)


@rustbot label: +I-lang-nominated
r? @lcnr
cc @flip1995


For Clippy:

changelog: Moves: Uplifted clippy::needless_maybe_sized into rustc as redundant_sizedness_bounds

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2025

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 27, 2025
@CrooseGit
Copy link
Contributor Author

@davidtwco

@CrooseGit CrooseGit changed the title Dev/reucru01/needless maybe sized Uplifts and extends needless-maybe-sized Aug 27, 2025
@CrooseGit CrooseGit changed the title Uplifts and extends needless-maybe-sized Uplifts and extends clippy::needless-maybe-sized into rustc Aug 27, 2025
@rust-log-analyzer

This comment has been minimized.

@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from 6f856bf to fe3f26f Compare August 27, 2025 12:33
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Reviewed only the Clippy part.

View changes since this review

@traviscross traviscross added the P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. label Aug 27, 2025
@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from fe3f26f to 7306887 Compare August 27, 2025 17:24
@CrooseGit
Copy link
Contributor Author

Thank you @samueltardieu for your feedback. Regarding the small changes to unrelated files, I believe that was my auto-formatter doing me a disservice, and I believe I have removed said changes from the commits.
I also believe I have addressed the other points you made, but do let me know if anything is amiss.
Thanks again.

Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

I also believe I have addressed the other points you made, but do let me know if anything is amiss.

I think you still have to remove src/tools/clippy/tests/ui/needless_maybe_sized.rs and src/tools/clippy/tests/ui/needless_maybe_sized.stderr.

View changes since this review

@CrooseGit
Copy link
Contributor Author

As far as I can tell those files have already been removed, let me know if I'm missing anything. Thank you

needless_maybe_sized.stderr
needless_maybe_sized.rs

@davidtwco
Copy link
Member

davidtwco commented Aug 28, 2025

I think you still have to remove src/tools/clippy/tests/ui/needless_maybe_sized.rs and src/tools/clippy/tests/ui/needless_maybe_sized.stderr.

These have been removed as far as I can tell, they're just showing as moves in Git as similar tests have been added to the rustc ui test suite w/ some changes.

@samueltardieu
Copy link
Member

I think you still have to remove src/tools/clippy/tests/ui/needless_maybe_sized.rs and src/tools/clippy/tests/ui/needless_maybe_sized.stderr.

These have been removed as far as I can tell, they're just showing as moves in Git as similar tests have been added to the rustc ui test suite w/ some changes.

Oh yes, the subpar GitHub diff UI shows this only at the point of destination, not at the point of origin.

@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from 7306887 to 8446c5a Compare August 28, 2025 09:54
@CrooseGit
Copy link
Contributor Author

I have added a .fixed file to the tests

@traviscross traviscross added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-lang Relevant to the language team S-waiting-on-team DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-clippy Relevant to the Clippy team. labels Sep 10, 2025
@tmandry
Copy link
Member

tmandry commented Sep 24, 2025

@rfcbot fcp merge

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Sep 26, 2025
@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from a02ff43 to 00b61bb Compare September 26, 2025 16:24
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Sep 26, 2025
@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

new name lgtm

@tmandry
Copy link
Member

tmandry commented Sep 30, 2025

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 30, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from 00b61bb to 302136b Compare October 1, 2025 09:33
@Urgau Urgau added S-waiting-on-t-lang Status: Awaiting decision from T-lang and removed S-waiting-on-team DEPRECATED: Use the team-based variants `S-waiting-on-t-lang`, `S-waiting-on-t-compiler`, ... labels Oct 6, 2025
@bors

This comment was marked as resolved.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 7, 2025
- Copies the lint and test (+ stderr) from clippy into rustc_lint/src and
  tests/ui/lint respectively.
- Makes necessary changes to uplifted lint to work correctly in
  rustc.
- Removes needless `?Sized` bounds from 3 files as detected and suggested
  by the lint.
- Changes name from needless-maybe-sized to redundant-sizedness-bound to
  reflect extended functionality.
- Extends the test to include tests covering the lint's soon to be
  extended functionality.
- Adds `//@ run-rustfix` to test and creates corresponding .fixed file.
- Extends lint to check for redundant sizedness bounds.
- Applies the extended lint's suggestions to `clone.rs` as flagged by the lint.
- Uses clippy dev tool to rename and deprecate needless-maybe-sized in
  clippy.
- Removes needless-maybe-sized from late pass lint register.
@CrooseGit CrooseGit force-pushed the dev/reucru01/needless-maybe-sized branch from 302136b to 66f91da Compare October 8, 2025 09:15
@rustbot
Copy link
Collaborator

rustbot commented Oct 8, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@camsteffen
Copy link
Contributor

I think the two cases should not be the same lint, and we should probably only uplift the first case. One case is ”bound is overridden by other bound" and the other case is "bound is implied by other bound". Ostensibly the latter case is more controversial of a lint since you may wish to make an implicit bound explicit for readability. Additionally, the latter case is generalizable for cases like Clone + Copy or ExactSizedIterator + Iterator, so we may want to leave an opening for such a more general lint.

@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 10, 2025
@rust-rfcbot
Copy link
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

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

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. I-lang-nominated Nominated for discussion during a lang team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-clippy Relevant to the Clippy team. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

relaxed ?Sized bound getting implied by super trait warn