-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
impl restriction lowering
#153556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rust-bors
merged 2 commits into
rust-lang:main
from
CoCo-Japan-pan:impl-restriction-lowering
Mar 20, 2026
+268
−4
Merged
impl restriction lowering
#153556
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
85 changes: 85 additions & 0 deletions
85
tests/ui/impl-restriction/restriction_resolution_errors.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #![feature(impl_restriction)] | ||
| #![expect(incomplete_features)] | ||
|
|
||
| pub mod a { | ||
| pub enum E {} | ||
| pub mod d {} | ||
| pub mod b { | ||
| pub mod c {} | ||
|
|
||
| // We do not use crate-relative paths here, since we follow the | ||
| // "uniform paths" approach used for type/expression paths. | ||
| pub impl(in a::b) trait T1 {} //~ ERROR cannot find module or crate `a` in this scope [E0433] | ||
|
|
||
| pub impl(in ::std) trait T2 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in self::c) trait T3 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in super::d) trait T4 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in crate::c) trait T5 {} //~ ERROR cannot find module `c` in the crate root [E0433] | ||
|
|
||
| pub impl(in super::E) trait T6 {} //~ ERROR expected module, found enum `super::E` [E0577] | ||
|
|
||
| pub impl(in super::super::super) trait T7 {} //~ ERROR too many leading `super` keywords [E0433] | ||
|
|
||
| // OK paths | ||
| pub impl(crate) trait T8 {} | ||
| pub impl(self) trait T9 {} | ||
| pub impl(super) trait T10 {} | ||
| pub impl(in crate::a) trait T11 {} | ||
| pub impl(in super::super) trait T12 {} | ||
|
|
||
| // Check if we can resolve paths referring to modules declared later. | ||
| pub impl(in self::f) trait L1 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in super::G) trait L2 {} //~ ERROR expected module, found enum `super::G` [E0577] | ||
|
|
||
| pub impl(in super::h) trait L3 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub mod f {} | ||
| } | ||
|
|
||
| pub enum G {} | ||
| pub mod h {} | ||
| } | ||
|
|
||
| pub impl(in crate::a) trait T13 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in crate::a::E) trait T14 {} //~ ERROR expected module, found enum `crate::a::E` [E0577] | ||
|
|
||
| pub impl(crate) trait T15 {} | ||
| pub impl(self) trait T16 {} | ||
|
|
||
| pub impl(super) trait T17 {} //~ ERROR too many leading `super` keywords [E0433] | ||
|
|
||
| // Check if we can resolve paths referring to modules declared later. | ||
| pub impl(in crate::j) trait L4 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
|
|
||
| pub impl(in crate::I) trait L5 {} //~ ERROR expected module, found enum `crate::I` [E0577] | ||
|
|
||
| pub enum I {} | ||
| pub mod j {} | ||
|
|
||
| // Check if we can resolve `use`d paths. | ||
| mod m1 { | ||
| pub impl(in crate::m2) trait U1 {} // OK | ||
| } | ||
|
|
||
| use m1 as m2; | ||
|
|
||
| mod m3 { | ||
| mod m4 { | ||
| pub impl(in crate::m2) trait U2 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
| pub impl(in m6) trait U3 {} // OK | ||
| pub impl(in m6::m5) trait U4 {} //~ ERROR trait implementation can only be restricted to ancestor modules | ||
| pub impl(in m7) trait U5 {} //~ ERROR expected module, found enum `m7` [E0577] | ||
|
|
||
| use crate::m3 as m6; | ||
| use crate::m3::E as m7; | ||
| } | ||
| mod m5 {} | ||
| pub enum E {} | ||
| } | ||
|
|
||
| fn main() {} |
140 changes: 140 additions & 0 deletions
140
tests/ui/impl-restriction/restriction_resolution_errors.stderr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:14:21 | ||
| | | ||
| LL | pub impl(in ::std) trait T2 {} | ||
| | ^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:16:21 | ||
| | | ||
| LL | pub impl(in self::c) trait T3 {} | ||
| | ^^^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:18:21 | ||
| | | ||
| LL | pub impl(in super::d) trait T4 {} | ||
| | ^^^^^^^^ | ||
|
|
||
| error[E0433]: too many leading `super` keywords | ||
| --> $DIR/restriction_resolution_errors.rs:24:35 | ||
| | | ||
| LL | pub impl(in super::super::super) trait T7 {} | ||
| | ^^^^^ there are too many leading `super` keywords | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:34:21 | ||
| | | ||
| LL | pub impl(in self::f) trait L1 {} | ||
| | ^^^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:38:21 | ||
| | | ||
| LL | pub impl(in super::h) trait L3 {} | ||
| | ^^^^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:47:13 | ||
| | | ||
| LL | pub impl(in crate::a) trait T13 {} | ||
| | ^^^^^^^^ | ||
|
|
||
| error[E0433]: too many leading `super` keywords | ||
| --> $DIR/restriction_resolution_errors.rs:54:10 | ||
| | | ||
| LL | pub impl(super) trait T17 {} | ||
| | ^^^^^ there are too many leading `super` keywords | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:57:13 | ||
| | | ||
| LL | pub impl(in crate::j) trait L4 {} | ||
| | ^^^^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:73:21 | ||
| | | ||
| LL | pub impl(in crate::m2) trait U2 {} | ||
| | ^^^^^^^^^ | ||
|
|
||
| error: trait implementation can only be restricted to ancestor modules | ||
| --> $DIR/restriction_resolution_errors.rs:75:21 | ||
| | | ||
| LL | pub impl(in m6::m5) trait U4 {} | ||
| | ^^^^^^ | ||
|
|
||
| error[E0433]: cannot find module or crate `a` in this scope | ||
| --> $DIR/restriction_resolution_errors.rs:12:21 | ||
| | | ||
| LL | pub impl(in a::b) trait T1 {} | ||
| | ^ use of unresolved module or unlinked crate `a` | ||
| | | ||
| help: there is a crate or module with a similar name | ||
| | | ||
| LL - pub impl(in a::b) trait T1 {} | ||
| LL + pub impl(in c::b) trait T1 {} | ||
| | | ||
| help: consider importing this module | ||
| | | ||
| LL + use a; | ||
| | | ||
|
|
||
| error[E0433]: cannot find module `c` in the crate root | ||
| --> $DIR/restriction_resolution_errors.rs:20:28 | ||
| | | ||
| LL | pub impl(in crate::c) trait T5 {} | ||
| | ^ not found in the crate root | ||
|
|
||
| error[E0577]: expected module, found enum `super::E` | ||
| --> $DIR/restriction_resolution_errors.rs:22:21 | ||
| | | ||
| LL | pub impl(in super::E) trait T6 {} | ||
| | ^^^^^^^^ not a module | ||
|
|
||
| error[E0577]: expected module, found enum `super::G` | ||
| --> $DIR/restriction_resolution_errors.rs:36:21 | ||
| | | ||
| LL | pub impl(in super::G) trait L2 {} | ||
| | ^^^^^^^^ not a module | ||
|
|
||
| error[E0577]: expected module, found enum `crate::a::E` | ||
| --> $DIR/restriction_resolution_errors.rs:49:13 | ||
| | | ||
| LL | pub mod b { | ||
| | --------- similarly named module `b` defined here | ||
| ... | ||
| LL | pub impl(in crate::a::E) trait T14 {} | ||
| | ^^^^^^^^^^^ | ||
| | | ||
| help: a module with a similar name exists | ||
| | | ||
| LL - pub impl(in crate::a::E) trait T14 {} | ||
| LL + pub impl(in crate::a::b) trait T14 {} | ||
| | | ||
|
|
||
| error[E0577]: expected module, found enum `crate::I` | ||
| --> $DIR/restriction_resolution_errors.rs:59:13 | ||
| | | ||
| LL | pub mod a { | ||
| | --------- similarly named module `a` defined here | ||
| ... | ||
| LL | pub impl(in crate::I) trait L5 {} | ||
| | ^^^^^^^^ | ||
| | | ||
| help: a module with a similar name exists | ||
| | | ||
| LL - pub impl(in crate::I) trait L5 {} | ||
| LL + pub impl(in crate::a) trait L5 {} | ||
| | | ||
|
|
||
| error[E0577]: expected module, found enum `m7` | ||
| --> $DIR/restriction_resolution_errors.rs:76:21 | ||
| | | ||
| LL | pub impl(in m7) trait U5 {} | ||
| | ^^ not a module | ||
|
|
||
| error: aborting due to 18 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0433, E0577. | ||
| For more information about an error, try `rustc --explain E0433`. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.