Skip to content

impl restriction lowering - #153556

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
CoCo-Japan-pan:impl-restriction-lowering
Mar 20, 2026
Merged

impl restriction lowering#153556
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
CoCo-Japan-pan:impl-restriction-lowering

Conversation

@CoCo-Japan-pan

@CoCo-Japan-panCoCo-Japan-pan commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

This PR is linked to a GSoC proposal and is part of the progress toward implementing impl restrictions proposed in RFC 3323.
This PR implements path resolution for impl restrictions. The resolution is performed in rustc_resolve/src/late.rs using smart_resolve_path.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s AncestorOnly error.

r? @Urgau
cc @jhpratt

@rustbotrustbot 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 Mar 8, 2026
@CoCo-Japan-panCoCo-Japan-pan changed the title Impl restriction loweringimpl restriction loweringMar 8, 2026

@UrgauUrgau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks pretty good. Only some nits.

View changes since this review

Comment threadcompiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment threadcompiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment threadtests/ui/impl-restriction/restriction_resolution_errors.rs Outdated
Comment threadtests/ui/impl-restriction/restriction_resolution_errors.rs Outdated
Comment threadtests/ui/impl-restriction/restriction_resolution_2018.rs Outdated
Comment threadcompiler/rustc_resolve/src/lib.rs
@UrgauUrgau added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2026
@CoCo-Japan-pan
CoCo-Japan-panforce-pushed the impl-restriction-lowering branch 2 times, most recently from deed8e1 to 596133bCompareMarch 8, 2026 13:38
@CoCo-Japan-pan

Copy link
Copy Markdown
ContributorAuthor

Thanks for the review!
@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 8, 2026

@UrgauUrgau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks mostly good, just need some positive tests now.

View changes since this review

Comment threadtests/ui/impl-restriction/restriction_resolution_2018.rs Outdated
Comment threadtests/ui/impl-restriction/restriction_resolution_2018.rs Outdated
@CoCo-Japan-pan
CoCo-Japan-panforce-pushed the impl-restriction-lowering branch from 596133b to 40df631CompareMarch 9, 2026 06:47

@UrgauUrgau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. I will let @jhpratt do the final review.

View changes since this review

Comment threadcompiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment threadcompiler/rustc_resolve/src/late.rs
Comment threadcompiler/rustc_middle/src/hir/map.rs Outdated
@petrochenkovpetrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 16, 2026
@CoCo-Japan-pan
CoCo-Japan-panforce-pushed the impl-restriction-lowering branch 2 times, most recently from f1ef729 to 020ae2bCompareMarch 16, 2026 17:01
@CoCo-Japan-pan

Copy link
Copy Markdown
ContributorAuthor

The current implementation uses smart_resolve_path.
I added a new variant, PathSource::Module.

I kept the ancestor check and pushed it into use_injections to keep the error emission order consistent with its occurrence.
Currently, the "too many leading super keywords" error is emitted first regardless of the occurrence order, but this seems to be a separate issue.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=05164a046abf4e1c123793c0037c06a7

@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 16, 2026
@CoCo-Japan-pan
CoCo-Japan-panforce-pushed the impl-restriction-lowering branch 2 times, most recently from 482cd56 to 54e564cCompareMarch 17, 2026 13:57
Comment threadtests/ui/impl-restriction/restriction_resolution_use.rs Outdated
Comment threadtests/ui/impl-restriction/restriction_resolution_errors.rs Outdated
Comment threadcompiler/rustc_resolve/src/lib.rs Outdated
Comment threadcompiler/rustc_middle/src/ty/mod.rs Outdated
Comment threadcompiler/rustc_resolve/src/late.rs Outdated
Comment threadcompiler/rustc_resolve/src/late.rs Outdated
@CoCo-Japan-pan
CoCo-Japan-panforce-pushed the impl-restriction-lowering branch from 8cfbc47 to 4a60daeCompareMarch 19, 2026 10:11
@CoCo-Japan-pan

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 19, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-borsBot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4a60dae has been approved by petrochenkov

It is now in the queue for this repository.

@rust-borsrust-borsBot 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 Mar 19, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…wering, r=petrochenkov
`impl` restriction lowering
This PR is linked to a [GSoC proposal](https://github.com/rust-lang/google-summer-of-code?tab=readme-ov-file#implementing-impl-and-mut-restrictions) and is part of the progress toward implementing `impl` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
This PR implements path resolution for `impl` restrictions. The resolution is performed in `rustc_resolve/src/late.rs` using `smart_resolve_path`.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s `AncestorOnly` error.
r? @Urgau
cc @jhpratt
rust-borsBot pushed a commit that referenced this pull request Mar 19, 2026
…uwer
Rollup of 9 pull requests
Successful merges:
- #153556 (`impl` restriction lowering)
- #153992 (bootstrap: Optionally print a backtrace if a command fails)
- #154019 (two smaller feature cleanups)
- #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
- #154075 (Rewrite `query_ensure_result`.)
- #154082 (Updates derive_where and removes workaround)
- #154084 (Preserve braces around `self` in use tree pretty printing)
- #154086 (Insert space after float literal ending with `.` in pretty printer)
- #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
rust-borsBot pushed a commit that referenced this pull request Mar 19, 2026
…uwer
Rollup of 9 pull requests
Successful merges:
- #153556 (`impl` restriction lowering)
- #153992 (bootstrap: Optionally print a backtrace if a command fails)
- #154019 (two smaller feature cleanups)
- #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
- #154075 (Rewrite `query_ensure_result`.)
- #154082 (Updates derive_where and removes workaround)
- #154084 (Preserve braces around `self` in use tree pretty printing)
- #154086 (Insert space after float literal ending with `.` in pretty printer)
- #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…wering, r=petrochenkov
`impl` restriction lowering
This PR is linked to a [GSoC proposal](https://github.com/rust-lang/google-summer-of-code?tab=readme-ov-file#implementing-impl-and-mut-restrictions) and is part of the progress toward implementing `impl` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
This PR implements path resolution for `impl` restrictions. The resolution is performed in `rustc_resolve/src/late.rs` using `smart_resolve_path`.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s `AncestorOnly` error.
r? @Urgau
cc @jhpratt
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…wering, r=petrochenkov
`impl` restriction lowering
This PR is linked to a [GSoC proposal](https://github.com/rust-lang/google-summer-of-code?tab=readme-ov-file#implementing-impl-and-mut-restrictions) and is part of the progress toward implementing `impl` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
This PR implements path resolution for `impl` restrictions. The resolution is performed in `rustc_resolve/src/late.rs` using `smart_resolve_path`.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s `AncestorOnly` error.
r? @Urgau
cc @jhpratt
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…wering, r=petrochenkov
`impl` restriction lowering
This PR is linked to a [GSoC proposal](https://github.com/rust-lang/google-summer-of-code?tab=readme-ov-file#implementing-impl-and-mut-restrictions) and is part of the progress toward implementing `impl` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
This PR implements path resolution for `impl` restrictions. The resolution is performed in `rustc_resolve/src/late.rs` using `smart_resolve_path`.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s `AncestorOnly` error.
r? @Urgau
cc @jhpratt
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 19, 2026
…wering, r=petrochenkov
`impl` restriction lowering
This PR is linked to a [GSoC proposal](https://github.com/rust-lang/google-summer-of-code?tab=readme-ov-file#implementing-impl-and-mut-restrictions) and is part of the progress toward implementing `impl` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
This PR implements path resolution for `impl` restrictions. The resolution is performed in `rustc_resolve/src/late.rs` using `smart_resolve_path`.
This PR also checks whether the restricted module or crate is an ancestor. If it is not, it emits a restriction-specific counterpart to visibility’s `AncestorOnly` error.
r? @Urgau
cc @jhpratt
rust-borsBot pushed a commit that referenced this pull request Mar 20, 2026
…uwer
Rollup of 12 pull requests
Successful merges:
- #152909 (sess: `-Zbranch-protection` is a target modifier)
- #153556 (`impl` restriction lowering)
- #154048 (Don't emit rustdoc `missing_doc_code_examples` lint on impl items)
- #153992 (bootstrap: Optionally print a backtrace if a command fails)
- #154019 (two smaller feature cleanups)
- #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
- #154075 (Rewrite `query_ensure_result`.)
- #154082 (Updates derive_where and removes workaround)
- #154084 (Preserve braces around `self` in use tree pretty printing)
- #154086 (Insert space after float literal ending with `.` in pretty printer)
- #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
- #154109 (tests: Add regression test for async closures involving HRTBs)
@ZalatharZalathar mentioned this pull request Mar 20, 2026
rust-borsBot pushed a commit that referenced this pull request Mar 20, 2026
Rollup of 15 pull requests
Successful merges:
- #152909 (sess: `-Zbranch-protection` is a target modifier)
- #153556 (`impl` restriction lowering)
- #154048 (Don't emit rustdoc `missing_doc_code_examples` lint on impl items)
- #150935 (Introduce #[diagnostic::on_move(message)])
- #152973 (remove -Csoft-float)
- #153862 (Rename `cycle_check` to `find_cycle`)
- #153992 (bootstrap: Optionally print a backtrace if a command fails)
- #154019 (two smaller feature cleanups)
- #154059 (tests: Activate `must_not_suspend` test for `MutexGuard` dropped before `await`)
- #154075 (Rewrite `query_ensure_result`.)
- #154082 (Updates derive_where and removes workaround)
- #154084 (Preserve braces around `self` in use tree pretty printing)
- #154086 (Insert space after float literal ending with `.` in pretty printer)
- #154087 (Fix whitespace after fragment specifiers in macro pretty printing)
- #154109 (tests: Add regression test for async closures involving HRTBs)
@rust-bors
rust-borsBot merged commit 85b8c32 into rust-lang:mainMar 20, 2026
11 checks passed
@rustbotrustbot added this to the 1.96.0 milestone Mar 20, 2026
@UrgauUrgau mentioned this pull request Apr 5, 2026
11 tasks
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 11, 2026
…eck, r=jhpratt,Urgau
Semantic checks of `impl` restrictions
This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).
It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang#152943) and path resolution (rust-lang#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.
r? @Urgau
cc @jhpratt
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 11, 2026
…eck, r=jhpratt,Urgau
Semantic checks of `impl` restrictions
This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).
It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang#152943) and path resolution (rust-lang#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.
r? @Urgau
cc @jhpratt
rust-timer added a commit that referenced this pull request Apr 11, 2026
Rollup merge of #154661 - CoCo-Japan-pan:impl-restriction-check, r=jhpratt,Urgau
Semantic checks of `impl` restrictions
This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue #105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).
It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (#152943) and path resolution (#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.
r? @Urgau
cc @jhpratt
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Apr 16, 2026
…pratt,Urgau
Semantic checks of `impl` restrictions
This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang/rust#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).
It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang/rust#152943) and path resolution (rust-lang/rust#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.
r? @Urgau
cc @jhpratt
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
…pratt,Urgau
Semantic checks of `impl` restrictions
This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang/rust#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).
It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang/rust#152943) and path resolution (rust-lang/rust#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.
r? @Urgau
cc @jhpratt
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

6 participants

@CoCo-Japan-pan@petrochenkov@rustbot@jhpratt@Urgau@xonx4l