Skip to content

Make impl_trait_redundant_captures suggestion remove adjacent +#156843

Open
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-redundant-captures-143216
Open

Make impl_trait_redundant_captures suggestion remove adjacent +#156843
onehr wants to merge 1 commit into
rust-lang:mainfrom
onehr:fix-redundant-captures-143216

Conversation

@onehr
Copy link
Copy Markdown
Contributor

@onehr onehr commented May 23, 2026

Closes #143216

The impl_trait_redundant_captures lint's machine-applicable suggestion only
spanned the use<...> syntax itself, leaving the adjacent + joiner behind.
Applying the suggestion produced uncompilable code, e.g.
impl Sized + use<> becoming impl Sized + (stray trailing +).

This extends the removal span to also cover one adjacent +, preserving
valid syntax in the three bound-list positions covered by the regression test:

  • impl Sized + use<> becomes impl Sized
  • impl use<> + Sized becomes impl Sized
  • impl Sized + use<> + Send becomes impl Sized + Send

A //@ run-rustfix UI test exercises all three positions, so the
rustfix-applied output is actually compiled — covering the gap the
existing redundant.rs test left (which only checks lint firing, not
suggestion correctness).

Tested:

  • ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --bless
  • ./x test tidy

@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 May 23, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 23, 2026

r? @tiif

rustbot has assigned @tiif.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@rust-log-analyzer

This comment has been minimized.

The lint suggestion now removes the `+` joiner adjacent to a redundant
`use<...>` clause, so applying the suggestion does not leave a dangling
`+` that fails to parse.

The existing `tests/ui/impl-trait/precise-capturing/redundant.stderr`
baseline emits the same diagnostic with the expanded suggestion span and
is blessed along with the new `run-rustfix` test.

Tested:
- ./x test tests/ui/impl-trait/precise-capturing/redundant.rs --force-rerun
- ./x test tests/ui/impl-trait/precise-capturing/redundant-machine-applicable.rs --force-rerun
- ./x test tidy
@onehr onehr force-pushed the fix-redundant-captures-143216 branch from aed2feb to 6493163 Compare May 23, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

impl-trait-redundant-captures leaves + if there are several items

4 participants