Skip to content

do not suggest precise capturing when the opaque span is in a macro expansion - #163581

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:no-use-bound-suggestion-in-macro
Oct 2, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:no-use-bound-suggestion-in-macro

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

impl_trait_overcapture_suggestion anchored every suggestion on tcx.def_span(opaque_def_id) with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the MachineApplicable suggestion produces:

error: expected item after attributes

the obvious patch of calling can_be_used_for_suggestions() directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps DesugaringKind::OpaqueTy onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making from_expansion() unconditionally true (SyntaxContext::in_external_macro already lists this kind for the same reason). the fix calls parent_callsite() to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a macro_rules! body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no .fixed file: run-rustfix requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes #139567

r? @oli-obk

@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 Oct 1, 2026
@Albab-Hasan Albab-Hasan changed the title No use bound suggestion in macro do not suggest precise capturing when the opaque span is in a macro expansion Oct 1, 2026

@oli-obk oli-obk Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pull this to the start of this function and reuse it in both sites

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

the test records what the compiler emits today: impl_trait_overcapture_suggestion anchors its suggestion on the opaque def span, which for an opaque inside an attribute macro expansion is the attribute itself, not a type position. the suggestion is machine-applicable, so edition migration applies it and produces error: expected item after attributes
…ro expansion

impl_trait_overcapture_suggestion anchored every suggestion on tcx.def_span(opaque_def_id) with no expansion check. for an opaque created inside an attribute macro expansion that span is the attribute, which is not a type position, so applying the machine-applicable suggestion breaks the file

the obvious patch of calling can_be_used_for_suggestions() on that span directly suppresses all suggestions including for ordinary code, because ast lowering stamps DesugaringKind::OpaqueTy onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making from_expansion() unconditionally true. the fix calls parent_callsite() to peel that single desugaring layer and asks can_be_used_for_suggestions() about the span underneath

the guard sits at function entry rather than beside the rpit_span push because the apit rename and the generics-list insertion are anchored on the same span, so one check covers all three

fixes rust-lang#139567
@Albab-Hasan
Albab-Hasan force-pushed the no-use-bound-suggestion-in-macro branch from fc8a360 to 057e810 Compare October 1, 2026 06:19
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@Albab-Hasan
Albab-Hasan requested a review from oli-obk October 1, 2026 06:22

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 057e810 has been tentatively approved by oli-obk

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 1, 2026
…n-in-macro, r=oli-obk

do not suggest precise capturing when the opaque span is in a macro expansion

`impl_trait_overcapture_suggestion` anchored every suggestion on `tcx.def_span(opaque_def_id)` with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the `MachineApplicable` suggestion produces:

```
error: expected item after attributes
```

the obvious patch of calling `can_be_used_for_suggestions()` directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps `DesugaringKind::OpaqueTy` onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making `from_expansion()` unconditionally true (`SyntaxContext::in_external_macro` already lists this kind for the same reason). the fix calls `parent_callsite()` to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a `macro_rules!` body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no `.fixed` file: `run-rustfix` requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes rust-lang#139567

r? @oli-obk
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #162782 (Fix rustdoc ICE caused by mishandling of ambiguity errors)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163405 (Remove some #[linkage] options)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 1, 2026
…n-in-macro, r=oli-obk

do not suggest precise capturing when the opaque span is in a macro expansion

`impl_trait_overcapture_suggestion` anchored every suggestion on `tcx.def_span(opaque_def_id)` with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the `MachineApplicable` suggestion produces:

```
error: expected item after attributes
```

the obvious patch of calling `can_be_used_for_suggestions()` directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps `DesugaringKind::OpaqueTy` onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making `from_expansion()` unconditionally true (`SyntaxContext::in_external_macro` already lists this kind for the same reason). the fix calls `parent_callsite()` to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a `macro_rules!` body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no `.fixed` file: `run-rustfix` requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes rust-lang#139567

r? @oli-obk
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
…n-in-macro, r=oli-obk

do not suggest precise capturing when the opaque span is in a macro expansion

`impl_trait_overcapture_suggestion` anchored every suggestion on `tcx.def_span(opaque_def_id)` with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the `MachineApplicable` suggestion produces:

```
error: expected item after attributes
```

the obvious patch of calling `can_be_used_for_suggestions()` directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps `DesugaringKind::OpaqueTy` onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making `from_expansion()` unconditionally true (`SyntaxContext::in_external_macro` already lists this kind for the same reason). the fix calls `parent_callsite()` to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a `macro_rules!` body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no `.fixed` file: `run-rustfix` requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes rust-lang#139567

r? @oli-obk
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 1, 2026
…n-in-macro, r=oli-obk

do not suggest precise capturing when the opaque span is in a macro expansion

`impl_trait_overcapture_suggestion` anchored every suggestion on `tcx.def_span(opaque_def_id)` with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the `MachineApplicable` suggestion produces:

```
error: expected item after attributes
```

the obvious patch of calling `can_be_used_for_suggestions()` directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps `DesugaringKind::OpaqueTy` onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making `from_expansion()` unconditionally true (`SyntaxContext::in_external_macro` already lists this kind for the same reason). the fix calls `parent_callsite()` to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a `macro_rules!` body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no `.fixed` file: `run-rustfix` requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes rust-lang#139567

r? @oli-obk
@Albab-Hasan

Albab-Hasan commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

thanks!

rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
Rollup of 11 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 1, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #163483 (Bump bootstrap compiler to 1.100.0 beta)
 - #161380 (only rerun const eval in next-solver if the const actually references opaques)
 - #162900 (Some refactorings around metadata encoding)
 - #163461 (Improve diagnostic deduplication)
 - #163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - #163584 ([triagebot] Ping me for debugger visualizer changes)
 - #159021 (windows-gnu: enable native TLS)
 - #161467 (wfcheck: name the item that discards an unused type parameter)
 - #162618 (trait_selection: Preserve eager normalization failures)
 - #162904 (Fix ICE for ambiguous candidates on method probing)
 - #163064 (Avoid computing overflowed goal chains for crate dependencies)
 - #163281 (Add `f16` inline ASM support to `spirv.rs`)
 - #163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - #163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - #163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - #163405 (Remove some #[linkage] options)
 - #163530 (`const impl PartialEq` for `f16b`)
 - #163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - #163590 (Make `AllocatorNightly` less clever)
 - #163599 (Add union pattern reference change to relnotes)
@rust-bors
rust-bors Bot merged commit 2dfd15d into rust-lang:main Oct 2, 2026
13 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 2, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 2, 2026
Rollup merge of #163581 - Albab-Hasan:no-use-bound-suggestion-in-macro, r=oli-obk

do not suggest precise capturing when the opaque span is in a macro expansion

`impl_trait_overcapture_suggestion` anchored every suggestion on `tcx.def_span(opaque_def_id)` with no expansion check. for an opaque inside an attribute macro expansion that span is the attribute itself, so applying the `MachineApplicable` suggestion produces:

```
error: expected item after attributes
```

the obvious patch of calling `can_be_used_for_suggestions()` directly on that span suppresses all suggestions including for ordinary code, because AST lowering stamps `DesugaringKind::OpaqueTy` onto the opaque span at compiler/rustc_ast_lowering/src/lib.rs:1825, making `from_expansion()` unconditionally true (`SyntaxContext::in_external_macro` already lists this kind for the same reason). the fix calls `parent_callsite()` to peel that layer first. the guard sits at function entry because the APIT rename and generics-list insertion share the same span.

notes. a function written inside a `macro_rules!` body also loses its suggestion under this guard even though the edit would be valid in the macro definition; a token passed as an argument keeps its suggestion because it retains the callers syntax context. and there is no `.fixed` file: `run-rustfix` requires exit 0 but this change removes a suggestion rather than correcting one.

no existing baseline was re-blessed.

fixes #139567

r? @oli-obk
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 3, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#163483 (Bump bootstrap compiler to 1.100.0 beta)
 - rust-lang/rust#161380 (only rerun const eval in next-solver if the const actually references opaques)
 - rust-lang/rust#162900 (Some refactorings around metadata encoding)
 - rust-lang/rust#163461 (Improve diagnostic deduplication)
 - rust-lang/rust#163580 (Provide better doc code example for `UnixDatagram::bind_addr` and `UnixListener::bind_addr`)
 - rust-lang/rust#163584 ([triagebot] Ping me for debugger visualizer changes)
 - rust-lang/rust#159021 (windows-gnu: enable native TLS)
 - rust-lang/rust#161467 (wfcheck: name the item that discards an unused type parameter)
 - rust-lang/rust#162618 (trait_selection: Preserve eager normalization failures)
 - rust-lang/rust#162904 (Fix ICE for ambiguous candidates on method probing)
 - rust-lang/rust#163064 (Avoid computing overflowed goal chains for crate dependencies)
 - rust-lang/rust#163281 (Add `f16` inline ASM support to `spirv.rs`)
 - rust-lang/rust#163314 (move `#[macro_export]` on declarative macro check to `rustc_attr_parsing`)
 - rust-lang/rust#163360 ([rustdoc] Correctly handle rustc_allow_incoherent_impl on primitive methods)
 - rust-lang/rust#163385 (GVN transmutes of Immediate::Uninit to Immediate::Uninit)
 - rust-lang/rust#163405 (Remove some #[linkage] options)
 - rust-lang/rust#163530 (`const impl PartialEq` for `f16b`)
 - rust-lang/rust#163581 (do not suggest precise capturing when the opaque span is in a macro expansion)
 - rust-lang/rust#163590 (Make `AllocatorNightly` less clever)
 - rust-lang/rust#163599 (Add union pattern reference change to relnotes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

cargo fix --edition failed: error: expected item after attributes

3 participants