-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Support trailing self in paths
#152996
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
base: main
Are you sure you want to change the base?
Support trailing self in paths
#152996
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -953,12 +953,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| ) -> Result<Decl<'ra>, Determinacy> { | ||
| match module { | ||
| ModuleOrUniformRoot::Module(module) => { | ||
| if ns == TypeNS | ||
| && ident.name == kw::Super | ||
| && let Some(module) = | ||
| self.resolve_super_in_module(ident, Some(module), parent_scope) | ||
| { | ||
| return Ok(module.self_decl.unwrap()); | ||
| if ns == TypeNS { | ||
| if ident.name == kw::SelfLower { | ||
| return Ok(module.self_decl.unwrap()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, why doesn't this enable paths like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we can support
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated, |
||
| } | ||
| if ident.name == kw::Super | ||
| && let Some(module) = | ||
| self.resolve_super_in_module(ident, Some(module), parent_scope) | ||
| { | ||
| return Ok(module.self_decl.unwrap()); | ||
| } | ||
| } | ||
|
|
||
| let (ident_key, def) = IdentKey::new_adjusted(ident, module.expansion); | ||
|
|
@@ -1018,7 +1022,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| { | ||
| let module = self.resolve_crate_root(ident); | ||
| return Ok(module.self_decl.unwrap()); | ||
| } else if ident.name == kw::Super || ident.name == kw::SelfLower { | ||
| } else if ident.name == kw::Super { | ||
| // FIXME: Implement these with renaming requirements so that e.g. | ||
| // `use super;` doesn't work, but `use super as name;` does. | ||
| // Fall through here to get an error from `early_resolve_...`. | ||
|
|
@@ -1827,6 +1831,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| }, | ||
| ); | ||
| } | ||
|
|
||
| if segment_idx == 0 { | ||
| if name == kw::SelfLower { | ||
| let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0(); | ||
|
|
@@ -1860,6 +1865,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |
| continue; | ||
| } | ||
| } | ||
|
|
||
| // Support `...::self`, but deny `::self` after edition 2018 | ||
| if is_last | ||
| && name == kw::SelfLower | ||
| && segment_idx > 0 | ||
| && (path[segment_idx - 1].ident.name != kw::PathRoot | ||
| || self.path_root_is_crate_root(path[segment_idx - 1].ident)) | ||
| { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| // Report special messages for path segment keywords in wrong positions. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| use std::fmt::self; //~ ERROR E0429 | ||
| //@ check-pass | ||
|
|
||
| use std::fmt::self; | ||
|
|
||
| fn main () { | ||
| } |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So things like
foo::self::selfare still unsupported and will be reported byUnnamedImport.Seems fine for a start.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
use foo::self::self as nameis probably supported now, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated,
use foo::self::self;is allowed.