Repository navigation
do not suggest capturing '_ twice in use<...> for E0700 - #163471
Merged
rust-bors[bot] merged 2 commits intoSep 29, 2026
Merged
rust-bors[bot] merged 2 commits into
rust-bors[bot] merged 2 commits into
Conversation
the test records what the compiler prints today: for an opaque that already has use<'_> and a second anonymous lifetime to capture, it suggested use<'_, '_>, which doesnt compile
suggest_precise_capturing was appending '_ to a use<..> list that already had it, suggesting use<'_, '_>, which rustc rejects with cannot capture parameter '_ twice the branch for an opaque with an existing use<..> now bails out the same way the branch for an opaque without one does: both check if the lifetime is already captured
'_ twice in use<...> for E0700
oli-obk
requested changes
Sep 29, 2026
| @@ -1 +1 @@ | |||
| error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds | |||
Contributor
There was a problem hiding this comment.
would this test pass if rustfix were run on it? if so, you can make it a rustfix test to ensure this doesn't regress
Contributor
Author
There was a problem hiding this comment.
just checked, it cant be a rustfix test. after the fix dup gets no suggestion, so the .fixed file still fails E0700 and compiletest requires it to compile.
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
Contributor
Author
|
@rustbot ready |
Contributor
|
Thanks for checking @bors r+ rollup |
Contributor
Contributor
Author
|
thanks for the review! |
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 29, 2026
…uwer Rollup of 4 pull requests Successful merges: - #163024 (Add `Dir` equivalents of `fs::metadata` & `fs::symlink_metadata`) - #162839 (Bump min Emscripten version to 4.0, drop deprecated -sWASM_BIGINT for wasm32-unknown-emscripten) - #163370 (Fix incorrect typo suggestion for `struct field` shorthands) - #163471 (do not suggest capturing `'_` twice in `use<...>` for E0700)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 29, 2026
Rollup merge of #163471 - Albab-Hasan:no-duplicate-anon-lifetime-capture-suggestion, r=oli-obk do not suggest capturing `'_` twice in `use<...>` for E0700 starting from `use<'_>` with a second anonymous lifetime to capture, E0700 suggests `use<'_, '_>`. that fails with: ``` error: cannot capture parameter `'_` twice ``` then the compiler suggests `use<'_, '_, '_>`. both `AddPreciseCapturing::New` and `AddPreciseCapturing::Existing` are `machine-applicable` (rustc_trait_selection/src/diagnostics.rs:1876 and :1888) so rustfix applies the broken edit. the branch for an opaque without `use<..>` already skips lifetimes that are captured. this adds the same check to the branch for an existing `use<..>`. the issue repro compiles clean on edition 2024 and needs 2021 so the test starts one step in with `use<'_>` already written. two extra cases check the guard stays narrow: `use<>` with one anonymous lifetime still gets `use<'_>` and a named lifetime still gets suggested by name. one note. the guard removes the suggestion without replacing it so someone who already wrote `use<'_>` gets no path forward. a correct suggestion needs to name the elided lifetimes and suggest_precise_capturing cannot do that today. that the multipart suggestion this issue asks for will be the follow up. #132199 r? @oli-obk
pull Bot
pushed a commit
to LeeeeeeM/miri
that referenced
this pull request
Sep 30, 2026
…uwer Rollup of 4 pull requests Successful merges: - rust-lang/rust#163024 (Add `Dir` equivalents of `fs::metadata` & `fs::symlink_metadata`) - rust-lang/rust#162839 (Bump min Emscripten version to 4.0, drop deprecated -sWASM_BIGINT for wasm32-unknown-emscripten) - rust-lang/rust#163370 (Fix incorrect typo suggestion for `struct field` shorthands) - rust-lang/rust#163471 (do not suggest capturing `'_` twice in `use<...>` for E0700)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
starting from
use<'_>with a second anonymous lifetime to capture, E0700 suggestsuse<'_, '_>. that fails with:then the compiler suggests
use<'_, '_, '_>. bothAddPreciseCapturing::NewandAddPreciseCapturing::Existingaremachine-applicable(rustc_trait_selection/src/diagnostics.rs:1876 and :1888) so rustfix applies the broken edit.the branch for an opaque without
use<..>already skips lifetimes that are captured. this adds the same check to the branch for an existinguse<..>.the issue repro compiles clean on edition 2024 and needs 2021 so the test starts one step in with
use<'_>already written. two extra cases check the guard stays narrow:use<>with one anonymous lifetime still getsuse<'_>and a named lifetime still gets suggested by name.one note. the guard removes the suggestion without replacing it so someone who already wrote
use<'_>gets no path forward. a correct suggestion needs to name the elided lifetimes and suggest_precise_capturing cannot do that today. that the multipart suggestion this issue asks for will be the follow up.#132199
r? @oli-obk