Skip to content

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

@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn impl-trait-redundant-captures

this code:

fn a() -> impl Sized + use<> {} fn b() -> impl use<> + Sized {}

caused the following diagnostics:

 Checking _snippet_0 v0.1.0 (/tmp/icemaker_global_tempdir.BLc4baxM1XwC/icemaker_clippyfix_tempdir.yaIvKRyduqKN/_snippet_0) warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant --> src/lib.rs:1:11 | 1 | fn a() -> impl Sized + use<> {} | ^^^^^^^^^^^^^----- | | | help: remove the `use<...>` syntax | = note: requested on the command line with `--force-warn impl-trait-redundant-captures` warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant --> src/lib.rs:2:11 | 2 | fn b() -> impl use<> + Sized {} | ^^^^^-----^^^^^^^^ | | | help: remove the `use<...>` syntax warning: `_snippet_0` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p _snippet_0` to apply 2 suggestions) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s 

However after applying these diagnostics, the resulting code:

fn a() -> impl Sized + {} fn b() -> impl + Sized {}

no longer compiled:

 Checking _snippet_0 v0.1.0 (/tmp/icemaker_global_tempdir.BLc4baxM1XwC/icemaker_clippyfix_tempdir.yaIvKRyduqKN/_snippet_0) error[E0178]: expected a path on the left-hand side of `+` --> src/lib.rs:2:11 | 2 | fn b() -> impl + Sized {} | ^^^^ expected a path error: at least one trait must be specified --> src/lib.rs:2:11 | 2 | fn b() -> impl + Sized {} | ^^^^ For more information about this error, try `rustc --explain E0178`. error: could not compile `_snippet_0` (lib test) due to 2 previous errors warning: build failed, waiting for other jobs to finish... error: could not compile `_snippet_0` (lib) due to 2 previous errors 

Version:

rustc 1.90.0-nightly (ed2d75978 2025-06-29) binary: rustc commit-hash: ed2d759783dc9de134bbb3f01085b1e6dbf539f3 commit-date: 2025-06-29 host: x86_64-unknown-linux-gnu release: 1.90.0-nightly LLVM version: 20.1.7 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions