mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Replacing self overwriting with proper resolution
This commit is contained in:
@@ -626,42 +626,42 @@ fn build_reduced_graph_for_use_tree(
|
||||
|
||||
match use_tree.kind {
|
||||
ast::UseTreeKind::Simple(rename) => {
|
||||
let mut ident = use_tree.ident();
|
||||
let mut module_path = prefix;
|
||||
let mut source = module_path.pop().unwrap();
|
||||
let source = module_path.pop().unwrap();
|
||||
|
||||
// `true` for `...::{self [as target]}` imports, `false` otherwise.
|
||||
let type_ns_only = nested && source.ident.name == kw::SelfLower;
|
||||
|
||||
// Suggest `use prefix::{self};` for `use prefix::self;`
|
||||
if source.ident.name == kw::SelfLower
|
||||
&& let Some(parent) = module_path.pop()
|
||||
&& let Some(parent) = module_path.last()
|
||||
&& !type_ns_only
|
||||
&& (parent.ident.name != kw::PathRoot
|
||||
|| self.r.path_root_is_crate_root(parent.ident))
|
||||
{
|
||||
// Suggest `use prefix::{self};` for `use prefix::self;`
|
||||
if !type_ns_only
|
||||
&& (parent.ident.name != kw::PathRoot
|
||||
|| self.r.path_root_is_crate_root(parent.ident))
|
||||
{
|
||||
let span_with_rename = match rename {
|
||||
Some(rename) => source.ident.span.to(rename.span),
|
||||
None => source.ident.span,
|
||||
};
|
||||
let span_with_rename = match rename {
|
||||
Some(rename) => source.ident.span.to(rename.span),
|
||||
None => source.ident.span,
|
||||
};
|
||||
|
||||
self.r.report_error(
|
||||
parent.ident.span.shrink_to_hi().to(source.ident.span),
|
||||
ResolutionError::SelfImportsOnlyAllowedWithin {
|
||||
root: parent.ident.name == kw::PathRoot,
|
||||
span_with_rename,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let self_span = source.ident.span;
|
||||
source = parent;
|
||||
if rename.is_none() {
|
||||
ident = Ident::new(source.ident.name, self_span);
|
||||
}
|
||||
self.r.report_error(
|
||||
parent.ident.span.shrink_to_hi().to(source.ident.span),
|
||||
ResolutionError::SelfImportsOnlyAllowedWithin {
|
||||
root: parent.ident.name == kw::PathRoot,
|
||||
span_with_rename,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let ident = if source.ident.name == kw::SelfLower
|
||||
&& rename.is_none()
|
||||
&& let Some(parent) = module_path.last()
|
||||
{
|
||||
Ident::new(parent.ident.name, source.ident.span)
|
||||
} else {
|
||||
use_tree.ident()
|
||||
};
|
||||
|
||||
match source.ident.name {
|
||||
kw::DollarCrate => {
|
||||
if !module_path.is_empty() {
|
||||
@@ -698,7 +698,11 @@ fn build_reduced_graph_for_use_tree(
|
||||
}
|
||||
}
|
||||
// Deny `use ::{self};` after edition 2015
|
||||
kw::PathRoot if !self.r.path_root_is_crate_root(source.ident) => {
|
||||
kw::SelfLower
|
||||
if let Some(parent) = module_path.last()
|
||||
&& parent.ident.name == kw::PathRoot
|
||||
&& !self.r.path_root_is_crate_root(parent.ident) =>
|
||||
{
|
||||
self.r.dcx().span_err(use_tree.span(), "extern prelude cannot be imported");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -959,12 +959,16 @@ pub(crate) fn resolve_ident_in_module<'r>(
|
||||
) -> 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());
|
||||
}
|
||||
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);
|
||||
@@ -1032,7 +1036,7 @@ pub(crate) fn resolve_ident_in_module<'r>(
|
||||
{
|
||||
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_...`.
|
||||
|
||||
Reference in New Issue
Block a user