Auto merge of #95255 - petrochenkov:suggresolve, r=michaelwoerister
resolve: Do not build expensive suggestions if they are not actually used And remove a bunch of (conditionally) unused parameters from path resolution functions. This helps with performance issues in https://github.com/rust-lang/rust/pull/94857, and should be helpful in general even without that.
This commit is contained in:
commit
903427b2e8
@ -9,7 +9,7 @@ use crate::def_collector::collect_definitions;
|
||||
use crate::imports::{Import, ImportKind};
|
||||
use crate::macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
||||
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
|
||||
use crate::{CrateLint, Determinacy, ExternPreludeEntry, Module, ModuleKind, ModuleOrUniformRoot};
|
||||
use crate::{Determinacy, ExternPreludeEntry, Finalize, Module, ModuleKind, ModuleOrUniformRoot};
|
||||
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PerNS, ResolutionError};
|
||||
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, VisResolutionError};
|
||||
|
||||
@ -235,16 +235,16 @@ impl<'a> AsMut<Resolver<'a>> for BuildReducedGraphVisitor<'a, '_> {
|
||||
|
||||
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility {
|
||||
self.resolve_visibility_speculative(vis, false).unwrap_or_else(|err| {
|
||||
self.try_resolve_visibility(vis, true).unwrap_or_else(|err| {
|
||||
self.r.report_vis_error(err);
|
||||
ty::Visibility::Public
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_visibility_speculative<'ast>(
|
||||
fn try_resolve_visibility<'ast>(
|
||||
&mut self,
|
||||
vis: &'ast ast::Visibility,
|
||||
speculative: bool,
|
||||
finalize: bool,
|
||||
) -> Result<ty::Visibility, VisResolutionError<'ast>> {
|
||||
let parent_scope = &self.parent_scope;
|
||||
match vis.kind {
|
||||
@ -296,13 +296,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
&segments,
|
||||
Some(TypeNS),
|
||||
parent_scope,
|
||||
!speculative,
|
||||
path.span,
|
||||
CrateLint::SimplePath(id),
|
||||
if finalize { Finalize::SimplePath(id, path.span) } else { Finalize::No },
|
||||
) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
|
||||
let res = module.res().expect("visibility resolved to unnamed block");
|
||||
if !speculative {
|
||||
if finalize {
|
||||
self.r.record_partial_res(id, PartialRes::new(res));
|
||||
}
|
||||
if module.is_normal() {
|
||||
@ -772,7 +770,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
// correct visibilities for unnamed field placeholders specifically, so the
|
||||
// constructor visibility should still be determined correctly.
|
||||
let field_vis = self
|
||||
.resolve_visibility_speculative(&field.vis, true)
|
||||
.try_resolve_visibility(&field.vis, false)
|
||||
.unwrap_or(ty::Visibility::Public);
|
||||
if ctor_vis.is_at_least(field_vis, &*self.r) {
|
||||
ctor_vis = field_vis;
|
||||
@ -1131,8 +1129,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
ident,
|
||||
MacroNS,
|
||||
&self.parent_scope,
|
||||
false,
|
||||
ident.span,
|
||||
None,
|
||||
);
|
||||
if let Ok(binding) = result {
|
||||
let import = macro_use_import(self, ident.span);
|
||||
@ -1272,9 +1269,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
let vis = match item.kind {
|
||||
// Visibilities must not be resolved non-speculatively twice
|
||||
// and we already resolved this one as a `fn` item visibility.
|
||||
ItemKind::Fn(..) => self
|
||||
.resolve_visibility_speculative(&item.vis, true)
|
||||
.unwrap_or(ty::Visibility::Public),
|
||||
ItemKind::Fn(..) => {
|
||||
self.try_resolve_visibility(&item.vis, false).unwrap_or(ty::Visibility::Public)
|
||||
}
|
||||
_ => self.resolve_visibility(&item.vis),
|
||||
};
|
||||
if vis != ty::Visibility::Public {
|
||||
|
@ -24,10 +24,8 @@ use tracing::debug;
|
||||
use crate::imports::{Import, ImportKind, ImportResolver};
|
||||
use crate::path_names_to_string;
|
||||
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
|
||||
use crate::{
|
||||
BindingError, CrateLint, HasGenericParams, MacroRulesScope, Module, ModuleOrUniformRoot,
|
||||
};
|
||||
use crate::{NameBinding, NameBindingKind, PrivacyError, VisResolutionError};
|
||||
use crate::{BindingError, HasGenericParams, MacroRulesScope, Module, ModuleOrUniformRoot};
|
||||
use crate::{Finalize, NameBinding, NameBindingKind, PrivacyError, VisResolutionError};
|
||||
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet, Segment};
|
||||
|
||||
type Res = def::Res<ast::NodeId>;
|
||||
@ -1076,9 +1074,8 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ScopeSet::All(ns, false),
|
||||
&parent_scope,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
ident.span,
|
||||
) {
|
||||
let desc = match binding.res() {
|
||||
Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
|
||||
@ -1405,10 +1402,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
_ => return None,
|
||||
}
|
||||
|
||||
self.make_missing_self_suggestion(span, path.clone(), parent_scope)
|
||||
.or_else(|| self.make_missing_crate_suggestion(span, path.clone(), parent_scope))
|
||||
.or_else(|| self.make_missing_super_suggestion(span, path.clone(), parent_scope))
|
||||
.or_else(|| self.make_external_crate_suggestion(span, path, parent_scope))
|
||||
self.make_missing_self_suggestion(path.clone(), parent_scope)
|
||||
.or_else(|| self.make_missing_crate_suggestion(path.clone(), parent_scope))
|
||||
.or_else(|| self.make_missing_super_suggestion(path.clone(), parent_scope))
|
||||
.or_else(|| self.make_external_crate_suggestion(path, parent_scope))
|
||||
}
|
||||
|
||||
/// Suggest a missing `self::` if that resolves to an correct module.
|
||||
@ -1420,13 +1417,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
/// ```
|
||||
fn make_missing_self_suggestion(
|
||||
&mut self,
|
||||
span: Span,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// Replace first ident with `self` and check if that is valid.
|
||||
path[0].ident.name = kw::SelfLower;
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
|
||||
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
|
||||
}
|
||||
@ -1440,13 +1436,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
/// ```
|
||||
fn make_missing_crate_suggestion(
|
||||
&mut self,
|
||||
span: Span,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// Replace first ident with `crate` and check if that is valid.
|
||||
path[0].ident.name = kw::Crate;
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
|
||||
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result {
|
||||
Some((
|
||||
@ -1472,13 +1467,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
/// ```
|
||||
fn make_missing_super_suggestion(
|
||||
&mut self,
|
||||
span: Span,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
// Replace first ident with `crate` and check if that is valid.
|
||||
path[0].ident.name = kw::Super;
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
|
||||
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
|
||||
}
|
||||
@ -1495,7 +1489,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
/// name as the first part of path.
|
||||
fn make_external_crate_suggestion(
|
||||
&mut self,
|
||||
span: Span,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
) -> Option<(Vec<Segment>, Vec<String>)> {
|
||||
@ -1513,7 +1506,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
for name in extern_crate_names.into_iter() {
|
||||
// Replace first ident with a crate name and check if that is valid.
|
||||
path[0].ident.name = name;
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, false, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
|
||||
debug!(
|
||||
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
|
||||
name, path, result
|
||||
|
@ -6,7 +6,7 @@ use crate::Namespace::{self, MacroNS, TypeNS};
|
||||
use crate::{module_to_string, names_to_string};
|
||||
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
|
||||
use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
|
||||
use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak};
|
||||
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak};
|
||||
use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding};
|
||||
|
||||
use rustc_ast::NodeId;
|
||||
@ -123,10 +123,6 @@ impl<'a> Import<'a> {
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
crate fn crate_lint(&self) -> CrateLint {
|
||||
CrateLint::UsePath { root_id: self.root_id, root_span: self.root_span }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug)]
|
||||
@ -179,8 +175,7 @@ impl<'a> Resolver<'a> {
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
finalize: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_unadjusted_ext(
|
||||
module,
|
||||
@ -188,14 +183,13 @@ impl<'a> Resolver<'a> {
|
||||
ns,
|
||||
parent_scope,
|
||||
false,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
||||
/// Attempts to resolve `ident` in namespaces `ns` of `module`.
|
||||
/// Invariant: if `record_used` is `Some`, expansion and import resolution must be complete.
|
||||
/// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete.
|
||||
crate fn resolve_ident_in_module_unadjusted_ext(
|
||||
&mut self,
|
||||
module: ModuleOrUniformRoot<'a>,
|
||||
@ -203,8 +197,7 @@ impl<'a> Resolver<'a> {
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
restricted_shadowing: bool,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
finalize: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let module = match module {
|
||||
ModuleOrUniformRoot::Module(module) => module,
|
||||
@ -214,9 +207,8 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ScopeSet::AbsolutePath(ns),
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
@ -224,7 +216,7 @@ impl<'a> Resolver<'a> {
|
||||
assert!(!restricted_shadowing);
|
||||
return if ns != TypeNS {
|
||||
Err((Determined, Weak::No))
|
||||
} else if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
|
||||
} else if let Some(binding) = self.extern_prelude_get(ident, finalize.is_some()) {
|
||||
Ok(binding)
|
||||
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
|
||||
// Macro-expanded `extern crate` items can add names to extern prelude.
|
||||
@ -254,9 +246,8 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
scopes,
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
@ -266,7 +257,7 @@ impl<'a> Resolver<'a> {
|
||||
let resolution =
|
||||
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
|
||||
|
||||
if let Some(binding) = resolution.binding {
|
||||
if let Some(binding) = resolution.binding && let Some(path_span) = finalize {
|
||||
if !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
|
||||
if let NameBindingKind::Res(_, true) = binding.kind {
|
||||
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
|
||||
@ -284,7 +275,7 @@ impl<'a> Resolver<'a> {
|
||||
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
|
||||
};
|
||||
|
||||
if record_used {
|
||||
if let Some(path_span) = finalize {
|
||||
return resolution
|
||||
.binding
|
||||
.and_then(|binding| {
|
||||
@ -357,14 +348,8 @@ impl<'a> Resolver<'a> {
|
||||
let ImportKind::Single { source: ident, .. } = single_import.kind else {
|
||||
unreachable!();
|
||||
};
|
||||
match self.resolve_ident_in_module(
|
||||
module,
|
||||
ident,
|
||||
ns,
|
||||
&single_import.parent_scope,
|
||||
false,
|
||||
path_span,
|
||||
) {
|
||||
match self.resolve_ident_in_module(module, ident, ns, &single_import.parent_scope, None)
|
||||
{
|
||||
Err(Determined) => continue,
|
||||
Ok(binding)
|
||||
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
|
||||
@ -438,8 +423,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ns,
|
||||
adjusted_parent_scope,
|
||||
false,
|
||||
path_span,
|
||||
None,
|
||||
);
|
||||
|
||||
match result {
|
||||
@ -787,14 +771,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
// For better failure detection, pretend that the import will
|
||||
// not define any names while resolving its module path.
|
||||
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
|
||||
let path_res = self.r.resolve_path(
|
||||
&import.module_path,
|
||||
None,
|
||||
&import.parent_scope,
|
||||
false,
|
||||
import.span,
|
||||
import.crate_lint(),
|
||||
);
|
||||
let path_res =
|
||||
self.r.resolve_path(&import.module_path, None, &import.parent_scope, Finalize::No);
|
||||
import.vis.set(orig_vis);
|
||||
|
||||
match path_res {
|
||||
@ -833,8 +811,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
source,
|
||||
ns,
|
||||
&import.parent_scope,
|
||||
false,
|
||||
import.span,
|
||||
None,
|
||||
);
|
||||
import.vis.set(orig_vis);
|
||||
source_bindings[ns].set(binding);
|
||||
@ -887,14 +864,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
_ => None,
|
||||
};
|
||||
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
|
||||
let path_res = self.r.resolve_path(
|
||||
&import.module_path,
|
||||
None,
|
||||
&import.parent_scope,
|
||||
true,
|
||||
import.span,
|
||||
import.crate_lint(),
|
||||
);
|
||||
let finalize = Finalize::UsePath {
|
||||
root_id: import.root_id,
|
||||
root_span: import.root_span,
|
||||
path_span: import.span,
|
||||
};
|
||||
let path_res =
|
||||
self.r.resolve_path(&import.module_path, None, &import.parent_scope, finalize);
|
||||
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
|
||||
if let Some(orig_unusable_binding) = orig_unusable_binding {
|
||||
self.r.unusable_binding = orig_unusable_binding;
|
||||
@ -981,12 +957,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||
let mut full_path = import.module_path.clone();
|
||||
full_path.push(Segment::from_ident(Ident::empty()));
|
||||
self.r.lint_if_path_starts_with_module(
|
||||
import.crate_lint(),
|
||||
&full_path,
|
||||
import.span,
|
||||
None,
|
||||
);
|
||||
self.r.lint_if_path_starts_with_module(finalize, &full_path, None);
|
||||
}
|
||||
|
||||
if let ModuleOrUniformRoot::Module(module) = module {
|
||||
@ -1024,8 +995,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
ident,
|
||||
ns,
|
||||
&import.parent_scope,
|
||||
true,
|
||||
import.span,
|
||||
Some(import.span),
|
||||
);
|
||||
this.last_import_segment = orig_last_import_segment;
|
||||
this.unusable_binding = orig_unusable_binding;
|
||||
@ -1086,8 +1056,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
ident,
|
||||
ns,
|
||||
&import.parent_scope,
|
||||
true,
|
||||
import.span,
|
||||
Some(import.span),
|
||||
);
|
||||
if binding.is_ok() {
|
||||
all_ns_failed = false;
|
||||
@ -1253,12 +1222,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
full_path.push(Segment::from_ident(ident));
|
||||
self.r.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
this.lint_if_path_starts_with_module(
|
||||
import.crate_lint(),
|
||||
&full_path,
|
||||
import.span,
|
||||
Some(binding),
|
||||
);
|
||||
this.lint_if_path_starts_with_module(finalize, &full_path, Some(binding));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1314,9 +1278,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
target,
|
||||
ScopeSet::All(ns, false),
|
||||
&import.parent_scope,
|
||||
None,
|
||||
false,
|
||||
false,
|
||||
import.span,
|
||||
) {
|
||||
Ok(other_binding) => {
|
||||
is_redundant[ns] = Some(
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
use RibKind::*;
|
||||
|
||||
use crate::{path_names_to_string, BindingError, CrateLint, LexicalScopeBinding};
|
||||
use crate::{path_names_to_string, BindingError, Finalize, LexicalScopeBinding};
|
||||
use crate::{Module, ModuleOrUniformRoot, ParentScope, PathResult};
|
||||
use crate::{ResolutionError, Resolver, Segment, UseError};
|
||||
|
||||
@ -483,7 +483,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||
TyKind::ImplicitSelf => {
|
||||
let self_ty = Ident::with_dummy_span(kw::SelfUpper);
|
||||
let res = self
|
||||
.resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span)
|
||||
.resolve_ident_in_lexical_scope(
|
||||
self_ty,
|
||||
TypeNS,
|
||||
Finalize::SimplePath(ty.id, ty.span),
|
||||
)
|
||||
.map_or(Res::Err, |d| d.res());
|
||||
self.r.record_partial_res(ty.id, PartialRes::new(res));
|
||||
}
|
||||
@ -675,8 +679,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||
self.resolve_ident_in_lexical_scope(
|
||||
path.segments[0].ident,
|
||||
ns,
|
||||
None,
|
||||
path.span,
|
||||
Finalize::No,
|
||||
)
|
||||
.is_some()
|
||||
};
|
||||
@ -751,15 +754,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
record_used_id: Option<NodeId>,
|
||||
path_span: Span,
|
||||
finalize: Finalize,
|
||||
) -> Option<LexicalScopeBinding<'a>> {
|
||||
self.r.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ns,
|
||||
&self.parent_scope,
|
||||
record_used_id,
|
||||
path_span,
|
||||
finalize,
|
||||
&self.ribs[ns],
|
||||
)
|
||||
}
|
||||
@ -768,19 +769,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
&mut self,
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
) -> PathResult<'a> {
|
||||
self.r.resolve_path_with_ribs(
|
||||
path,
|
||||
opt_ns,
|
||||
&self.parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
crate_lint,
|
||||
Some(&self.ribs),
|
||||
)
|
||||
self.r.resolve_path_with_ribs(path, opt_ns, &self.parent_scope, finalize, Some(&self.ribs))
|
||||
}
|
||||
|
||||
// AST resolution
|
||||
@ -943,15 +934,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
};
|
||||
|
||||
for &ns in nss {
|
||||
match self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
|
||||
match self.resolve_ident_in_lexical_scope(ident, ns, Finalize::No) {
|
||||
Some(LexicalScopeBinding::Res(..)) => {
|
||||
report_error(self, ns);
|
||||
}
|
||||
Some(LexicalScopeBinding::Item(binding)) => {
|
||||
let orig_unusable_binding =
|
||||
replace(&mut self.r.unusable_binding, Some(binding));
|
||||
if let Some(LexicalScopeBinding::Res(..)) = self
|
||||
.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span)
|
||||
if let Some(LexicalScopeBinding::Res(..)) =
|
||||
self.resolve_ident_in_lexical_scope(ident, ns, Finalize::No)
|
||||
{
|
||||
report_error(self, ns);
|
||||
}
|
||||
@ -1246,25 +1237,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
if let Some(trait_ref) = opt_trait_ref {
|
||||
let path: Vec<_> = Segment::from_path(&trait_ref.path);
|
||||
let res = self.smart_resolve_path_fragment(
|
||||
trait_ref.ref_id,
|
||||
None,
|
||||
&path,
|
||||
trait_ref.path.span,
|
||||
PathSource::Trait(AliasPossibility::No),
|
||||
CrateLint::SimplePath(trait_ref.ref_id),
|
||||
Finalize::SimplePath(trait_ref.ref_id, trait_ref.path.span),
|
||||
);
|
||||
let res = res.base_res();
|
||||
if res != Res::Err {
|
||||
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = self.resolve_path(
|
||||
&path,
|
||||
Some(TypeNS),
|
||||
true,
|
||||
trait_ref.path.span,
|
||||
CrateLint::SimplePath(trait_ref.ref_id),
|
||||
) {
|
||||
new_id = Some(res.def_id());
|
||||
new_val = Some((module, trait_ref.clone()));
|
||||
}
|
||||
if let Some(def_id) = res.base_res().opt_def_id() {
|
||||
new_id = Some(def_id);
|
||||
new_val = Some((self.r.expect_module(def_id), trait_ref.clone()));
|
||||
}
|
||||
}
|
||||
let original_trait_ref = replace(&mut self.current_trait_ref, new_val);
|
||||
@ -1702,7 +1682,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// then fall back to a fresh binding.
|
||||
let has_sub = sub.is_some();
|
||||
let res = self
|
||||
.try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub)
|
||||
.try_resolve_as_non_binding(pat_src, bmode, ident, has_sub)
|
||||
.unwrap_or_else(|| self.fresh_binding(ident, pat.id, pat_src, bindings));
|
||||
self.r.record_partial_res(pat.id, PartialRes::new(res));
|
||||
self.r.record_pat_span(pat.id, pat.span);
|
||||
@ -1813,7 +1793,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
fn try_resolve_as_non_binding(
|
||||
&mut self,
|
||||
pat_src: PatternSource,
|
||||
pat: &Pat,
|
||||
bm: BindingMode,
|
||||
ident: Ident,
|
||||
has_sub: bool,
|
||||
@ -1823,7 +1802,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// also be interpreted as a path to e.g. a constant, variant, etc.
|
||||
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);
|
||||
|
||||
let ls_binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, pat.span)?;
|
||||
let ls_binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, Finalize::No)?;
|
||||
let (res, binding) = match ls_binding {
|
||||
LexicalScopeBinding::Item(binding)
|
||||
if is_syntactic_ambiguity && binding.is_ambiguity() =>
|
||||
@ -1912,35 +1891,34 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
source: PathSource<'ast>,
|
||||
) {
|
||||
self.smart_resolve_path_fragment(
|
||||
id,
|
||||
qself,
|
||||
&Segment::from_path(path),
|
||||
path.span,
|
||||
source,
|
||||
CrateLint::SimplePath(id),
|
||||
Finalize::SimplePath(id, path.span),
|
||||
);
|
||||
}
|
||||
|
||||
fn smart_resolve_path_fragment(
|
||||
&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Segment],
|
||||
span: Span,
|
||||
source: PathSource<'ast>,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
) -> PartialRes {
|
||||
tracing::debug!(
|
||||
"smart_resolve_path_fragment(id={:?}, qself={:?}, path={:?})",
|
||||
id,
|
||||
"smart_resolve_path_fragment(qself={:?}, path={:?}, finalize={:?})",
|
||||
qself,
|
||||
path
|
||||
path,
|
||||
finalize,
|
||||
);
|
||||
let ns = source.namespace();
|
||||
|
||||
let (id, path_span) =
|
||||
finalize.node_id_and_path_span().expect("unexpected speculative resolution");
|
||||
let report_errors = |this: &mut Self, res: Option<Res>| {
|
||||
if this.should_report_errs() {
|
||||
let (err, candidates) = this.smart_resolve_report_errors(path, span, source, res);
|
||||
let (err, candidates) =
|
||||
this.smart_resolve_report_errors(path, path_span, source, res);
|
||||
|
||||
let def_id = this.parent_scope.module.nearest_parent_mod();
|
||||
let instead = res.is_some();
|
||||
@ -1978,7 +1956,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
};
|
||||
|
||||
let (mut err, candidates) =
|
||||
this.smart_resolve_report_errors(path, span, PathSource::Type, None);
|
||||
this.smart_resolve_report_errors(path, path_span, PathSource::Type, None);
|
||||
|
||||
if candidates.is_empty() {
|
||||
err.cancel();
|
||||
@ -2027,13 +2005,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
};
|
||||
|
||||
let partial_res = match self.resolve_qpath_anywhere(
|
||||
id,
|
||||
qself,
|
||||
path,
|
||||
ns,
|
||||
span,
|
||||
path_span,
|
||||
source.defer_to_typeck(),
|
||||
crate_lint,
|
||||
finalize,
|
||||
) {
|
||||
Ok(Some(partial_res)) if partial_res.unresolved_segments() == 0 => {
|
||||
if source.is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err
|
||||
@ -2060,14 +2037,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
|
||||
std_path.extend(path);
|
||||
if let PathResult::Module(_) | PathResult::NonModule(_) =
|
||||
self.resolve_path(&std_path, Some(ns), false, span, CrateLint::No)
|
||||
self.resolve_path(&std_path, Some(ns), Finalize::No)
|
||||
{
|
||||
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
|
||||
let item_span =
|
||||
path.iter().last().map_or(span, |segment| segment.ident.span);
|
||||
path.iter().last().map_or(path_span, |segment| segment.ident.span);
|
||||
|
||||
self.r.confused_type_with_std_module.insert(item_span, span);
|
||||
self.r.confused_type_with_std_module.insert(span, span);
|
||||
self.r.confused_type_with_std_module.insert(item_span, path_span);
|
||||
self.r.confused_type_with_std_module.insert(path_span, path_span);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2093,19 +2070,18 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
partial_res
|
||||
}
|
||||
|
||||
fn self_type_is_available(&mut self, span: Span) -> bool {
|
||||
fn self_type_is_available(&mut self) -> bool {
|
||||
let binding = self.resolve_ident_in_lexical_scope(
|
||||
Ident::with_dummy_span(kw::SelfUpper),
|
||||
TypeNS,
|
||||
None,
|
||||
span,
|
||||
Finalize::No,
|
||||
);
|
||||
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
||||
}
|
||||
|
||||
fn self_value_is_available(&mut self, self_span: Span, path_span: Span) -> bool {
|
||||
fn self_value_is_available(&mut self, self_span: Span) -> bool {
|
||||
let ident = Ident::new(kw::SelfLower, self_span);
|
||||
let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, None, path_span);
|
||||
let binding = self.resolve_ident_in_lexical_scope(ident, ValueNS, Finalize::No);
|
||||
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
||||
}
|
||||
|
||||
@ -2127,19 +2103,18 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// Resolve in alternative namespaces if resolution in the primary namespace fails.
|
||||
fn resolve_qpath_anywhere(
|
||||
&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Segment],
|
||||
primary_ns: Namespace,
|
||||
span: Span,
|
||||
defer_to_typeck: bool,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
|
||||
let mut fin_res = None;
|
||||
|
||||
for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
|
||||
if i == 0 || ns != primary_ns {
|
||||
match self.resolve_qpath(id, qself, path, ns, span, crate_lint)? {
|
||||
match self.resolve_qpath(qself, path, ns, finalize)? {
|
||||
Some(partial_res)
|
||||
if partial_res.unresolved_segments() == 0 || defer_to_typeck =>
|
||||
{
|
||||
@ -2172,16 +2147,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
/// Handles paths that may refer to associated items.
|
||||
fn resolve_qpath(
|
||||
&mut self,
|
||||
id: NodeId,
|
||||
qself: Option<&QSelf>,
|
||||
path: &[Segment],
|
||||
ns: Namespace,
|
||||
span: Span,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
|
||||
debug!(
|
||||
"resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})",
|
||||
id, qself, path, ns, span,
|
||||
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",
|
||||
qself, path, ns, finalize,
|
||||
);
|
||||
|
||||
if let Some(qself) = qself {
|
||||
@ -2208,15 +2181,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// *actually* appears, so for the purposes of the crate
|
||||
// lint we pass along information that this is the trait
|
||||
// name from a fully qualified path, and this also
|
||||
// contains the full span (the `CrateLint::QPathTrait`).
|
||||
// contains the full span (the `Finalize::QPathTrait`).
|
||||
let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
|
||||
let partial_res = self.smart_resolve_path_fragment(
|
||||
id,
|
||||
None,
|
||||
&path[..=qself.position],
|
||||
span,
|
||||
PathSource::TraitItem(ns),
|
||||
CrateLint::QPathTrait { qpath_id: id, qpath_span: qself.path_span },
|
||||
finalize.node_id_and_path_span().map_or(Finalize::No, |(qpath_id, path_span)| {
|
||||
Finalize::QPathTrait { qpath_id, qpath_span: qself.path_span, path_span }
|
||||
}),
|
||||
);
|
||||
|
||||
// The remaining segments (the `C` in our example) will
|
||||
@ -2228,7 +2201,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
)));
|
||||
}
|
||||
|
||||
let result = match self.resolve_path(&path, Some(ns), true, span, crate_lint) {
|
||||
let result = match self.resolve_path(&path, Some(ns), finalize) {
|
||||
PathResult::NonModule(path_res) => path_res,
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
|
||||
PartialRes::new(module.res().unwrap())
|
||||
@ -2266,15 +2239,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
&& result.base_res() != Res::Err
|
||||
&& path[0].ident.name != kw::PathRoot
|
||||
&& path[0].ident.name != kw::DollarCrate
|
||||
&& let Some((id, path_span)) = finalize.node_id_and_path_span()
|
||||
{
|
||||
let unqualified_result = {
|
||||
match self.resolve_path(
|
||||
&[*path.last().unwrap()],
|
||||
Some(ns),
|
||||
false,
|
||||
span,
|
||||
CrateLint::No,
|
||||
) {
|
||||
match self.resolve_path(&[*path.last().unwrap()], Some(ns), Finalize::No) {
|
||||
PathResult::NonModule(path_res) => path_res.base_res(),
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
|
||||
module.res().unwrap()
|
||||
@ -2284,7 +2252,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
};
|
||||
if result.base_res() == unqualified_result {
|
||||
let lint = lint::builtin::UNUSED_QUALIFICATIONS;
|
||||
self.r.lint_buffer.buffer_lint(lint, id, span, "unnecessary qualification")
|
||||
self.r.lint_buffer.buffer_lint(lint, id, path_span, "unnecessary qualification")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use crate::diagnostics::{ImportSuggestion, LabelSuggestion, TypoSuggestion};
|
||||
use crate::late::lifetimes::{ElisionFailureInfo, LifetimeContext};
|
||||
use crate::late::{AliasPossibility, LateResolutionVisitor, RibKind};
|
||||
use crate::path_names_to_string;
|
||||
use crate::{CrateLint, Module, ModuleKind, ModuleOrUniformRoot};
|
||||
use crate::{Finalize, Module, ModuleKind, ModuleOrUniformRoot};
|
||||
use crate::{PathResult, PathSource, Segment};
|
||||
|
||||
use rustc_ast::visit::FnKind;
|
||||
@ -187,12 +187,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
(String::new(), "the crate root".to_string())
|
||||
} else {
|
||||
let mod_path = &path[..path.len() - 1];
|
||||
let mod_prefix =
|
||||
match self.resolve_path(mod_path, Some(TypeNS), false, span, CrateLint::No) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
|
||||
_ => None,
|
||||
}
|
||||
.map_or_else(String::new, |res| format!("{} ", res.descr()));
|
||||
let mod_prefix = match self.resolve_path(mod_path, Some(TypeNS), Finalize::No) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
|
||||
_ => None,
|
||||
}
|
||||
.map_or_else(String::new, |res| format!("{} ", res.descr()));
|
||||
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)))
|
||||
};
|
||||
(
|
||||
@ -232,7 +231,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let is_assoc_fn = self.self_type_is_available(span);
|
||||
let is_assoc_fn = self.self_type_is_available();
|
||||
// Emit help message for fake-self from other languages (e.g., `this` in Javascript).
|
||||
if ["this", "my"].contains(&item_str.as_str()) && is_assoc_fn {
|
||||
err.span_suggestion_short(
|
||||
@ -241,7 +240,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
"self".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
if !self.self_value_is_available(path[0].ident.span, span) {
|
||||
if !self.self_value_is_available(path[0].ident.span) {
|
||||
if let Some((FnKind::Fn(_, _, sig, ..), fn_span)) =
|
||||
&self.diagnostic_metadata.current_function
|
||||
{
|
||||
@ -402,9 +401,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
);
|
||||
}
|
||||
}
|
||||
if path.len() == 1 && self.self_type_is_available(span) {
|
||||
if path.len() == 1 && self.self_type_is_available() {
|
||||
if let Some(candidate) = self.lookup_assoc_candidate(ident, ns, is_expected) {
|
||||
let self_is_available = self.self_value_is_available(path[0].ident.span, span);
|
||||
let self_is_available = self.self_value_is_available(path[0].ident.span);
|
||||
match candidate {
|
||||
AssocSuggestion::Field => {
|
||||
if self_is_available {
|
||||
@ -461,7 +460,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
}
|
||||
|
||||
// Try Levenshtein algorithm.
|
||||
let typo_sugg = self.lookup_typo_candidate(path, ns, is_expected, span);
|
||||
let typo_sugg = self.lookup_typo_candidate(path, ns, is_expected);
|
||||
// Try context-dependent help if relaxed lookup didn't work.
|
||||
if let Some(res) = res {
|
||||
if self.smart_resolve_context_dependent_help(
|
||||
@ -562,7 +561,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
}
|
||||
|
||||
// If the trait has a single item (which wasn't matched by Levenshtein), suggest it
|
||||
let suggestion = self.get_single_associated_item(&path, span, &source, is_expected);
|
||||
let suggestion = self.get_single_associated_item(&path, &source, is_expected);
|
||||
self.r.add_typo_suggestion(&mut err, suggestion, ident_span);
|
||||
}
|
||||
if fallback {
|
||||
@ -641,14 +640,13 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
fn get_single_associated_item(
|
||||
&mut self,
|
||||
path: &[Segment],
|
||||
span: Span,
|
||||
source: &PathSource<'_>,
|
||||
filter_fn: &impl Fn(Res) -> bool,
|
||||
) -> Option<TypoSuggestion> {
|
||||
if let crate::PathSource::TraitItem(_) = source {
|
||||
let mod_path = &path[..path.len() - 1];
|
||||
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) =
|
||||
self.resolve_path(mod_path, None, false, span, CrateLint::No)
|
||||
self.resolve_path(mod_path, None, Finalize::No)
|
||||
{
|
||||
let resolutions = self.r.resolutions(module).borrow();
|
||||
let targets: Vec<_> =
|
||||
@ -699,13 +697,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
{
|
||||
// use this to verify that ident is a type param.
|
||||
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
|
||||
bounded_ty.id,
|
||||
None,
|
||||
&Segment::from_path(path),
|
||||
Namespace::TypeNS,
|
||||
span,
|
||||
true,
|
||||
CrateLint::No,
|
||||
Finalize::No,
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
@ -724,13 +721,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
if let ast::TyKind::Path(None, type_param_path) = &ty.peel_refs().kind {
|
||||
// Confirm that the `SelfTy` is a type parameter.
|
||||
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
|
||||
bounded_ty.id,
|
||||
None,
|
||||
&Segment::from_path(type_param_path),
|
||||
Namespace::TypeNS,
|
||||
span,
|
||||
true,
|
||||
CrateLint::No,
|
||||
Finalize::No,
|
||||
) else {
|
||||
return false;
|
||||
};
|
||||
@ -1292,8 +1288,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
ident,
|
||||
ns,
|
||||
&self.parent_scope,
|
||||
false,
|
||||
module.span,
|
||||
None,
|
||||
) {
|
||||
let res = binding.res();
|
||||
if filter_fn(res) {
|
||||
@ -1323,7 +1318,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
path: &[Segment],
|
||||
ns: Namespace,
|
||||
filter_fn: &impl Fn(Res) -> bool,
|
||||
span: Span,
|
||||
) -> Option<TypoSuggestion> {
|
||||
let mut names = Vec::new();
|
||||
if path.len() == 1 {
|
||||
@ -1384,7 +1378,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
||||
// Search in module.
|
||||
let mod_path = &path[..path.len() - 1];
|
||||
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) =
|
||||
self.resolve_path(mod_path, Some(TypeNS), false, span, CrateLint::No)
|
||||
self.resolve_path(mod_path, Some(TypeNS), Finalize::No)
|
||||
{
|
||||
self.r.add_module_candidates(module, &mut names, &filter_fn);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#![feature(drain_filter)]
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(let_else)]
|
||||
#![feature(never_type)]
|
||||
#![feature(nll)]
|
||||
@ -54,9 +55,9 @@ use rustc_index::vec::IndexVec;
|
||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::privacy::AccessLevels;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
|
||||
use rustc_session::lint;
|
||||
@ -71,7 +72,7 @@ use rustc_span::{Span, DUMMY_SP};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::BTreeSet;
|
||||
use std::{cmp, fmt, iter, mem, ptr};
|
||||
use std::{cmp, fmt, mem, ptr};
|
||||
use tracing::debug;
|
||||
|
||||
use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding};
|
||||
@ -449,6 +450,19 @@ enum PathResult<'a> {
|
||||
},
|
||||
}
|
||||
|
||||
impl<'a> PathResult<'a> {
|
||||
fn failed(
|
||||
span: Span,
|
||||
is_error_from_last_segment: bool,
|
||||
finalize: bool,
|
||||
label_and_suggestion: impl FnOnce() -> (String, Option<Suggestion>),
|
||||
) -> PathResult<'a> {
|
||||
let (label, suggestion) =
|
||||
if finalize { label_and_suggestion() } else { (String::new(), None) };
|
||||
PathResult::Failed { span, label, suggestion, is_error_from_last_segment }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ModuleKind {
|
||||
/// An anonymous module; e.g., just a block.
|
||||
@ -1936,8 +1950,7 @@ impl<'a> Resolver<'a> {
|
||||
mut ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used_id: Option<NodeId>,
|
||||
path_span: Span,
|
||||
finalize_full: Finalize,
|
||||
ribs: &[Rib<'a>],
|
||||
) -> Option<LexicalScopeBinding<'a>> {
|
||||
assert!(ns == TypeNS || ns == ValueNS);
|
||||
@ -1959,7 +1972,7 @@ impl<'a> Resolver<'a> {
|
||||
let normalized_ident = Ident { span: normalized_span, ..ident };
|
||||
|
||||
// Walk backwards up the ribs in scope.
|
||||
let record_used = record_used_id.is_some();
|
||||
let finalize = finalize_full.path_span();
|
||||
let mut module = self.graph_root;
|
||||
for i in (0..ribs.len()).rev() {
|
||||
debug!("walk rib\n{:?}", ribs[i].bindings);
|
||||
@ -1973,8 +1986,7 @@ impl<'a> Resolver<'a> {
|
||||
i,
|
||||
rib_ident,
|
||||
*res,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
*original_rib_ident_def,
|
||||
ribs,
|
||||
)));
|
||||
@ -2001,8 +2013,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
);
|
||||
if let Ok(binding) = item {
|
||||
// The ident resolves to an item.
|
||||
@ -2011,11 +2022,10 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
self.early_resolve_ident_in_lexical_scope(
|
||||
orig_ident,
|
||||
ScopeSet::Late(ns, module, record_used_id),
|
||||
ScopeSet::Late(ns, module, finalize_full.node_id()),
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
)
|
||||
.ok()
|
||||
.map(LexicalScopeBinding::Item)
|
||||
@ -2075,10 +2085,9 @@ impl<'a> Resolver<'a> {
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
finalize: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, record_used, path_span)
|
||||
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, finalize)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
||||
@ -2088,8 +2097,7 @@ impl<'a> Resolver<'a> {
|
||||
mut ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
finalize: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let tmp_parent_scope;
|
||||
let mut adjusted_parent_scope = parent_scope;
|
||||
@ -2114,8 +2122,7 @@ impl<'a> Resolver<'a> {
|
||||
ns,
|
||||
adjusted_parent_scope,
|
||||
false,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
)
|
||||
}
|
||||
|
||||
@ -2206,19 +2213,9 @@ impl<'a> Resolver<'a> {
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
) -> PathResult<'a> {
|
||||
self.resolve_path_with_ribs(
|
||||
path,
|
||||
opt_ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
crate_lint,
|
||||
None,
|
||||
)
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, finalize, None)
|
||||
}
|
||||
|
||||
fn resolve_path_with_ribs(
|
||||
@ -2226,25 +2223,20 @@ impl<'a> Resolver<'a> {
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
finalize_full: Finalize,
|
||||
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
|
||||
) -> PathResult<'a> {
|
||||
debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize_full);
|
||||
|
||||
let finalize = finalize_full.path_span();
|
||||
let mut module = None;
|
||||
let mut allow_super = true;
|
||||
let mut second_binding = None;
|
||||
|
||||
debug!(
|
||||
"resolve_path(path={:?}, opt_ns={:?}, record_used={:?}, \
|
||||
path_span={:?}, crate_lint={:?})",
|
||||
path, opt_ns, record_used, path_span, crate_lint,
|
||||
);
|
||||
|
||||
for (i, &Segment { ident, id, has_generic_args: _ }) in path.iter().enumerate() {
|
||||
debug!("resolve_path ident {} {:?} {:?}", i, ident, id);
|
||||
let record_segment_res = |this: &mut Self, res| {
|
||||
if record_used {
|
||||
if finalize.is_some() {
|
||||
if let Some(id) = id {
|
||||
if !this.partial_res_map.contains_key(&id) {
|
||||
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
|
||||
@ -2278,13 +2270,9 @@ impl<'a> Resolver<'a> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let msg = "there are too many leading `super` keywords".to_string();
|
||||
return PathResult::Failed {
|
||||
span: ident.span,
|
||||
label: msg,
|
||||
suggestion: None,
|
||||
is_error_from_last_segment: false,
|
||||
};
|
||||
return PathResult::failed(ident.span, false, finalize.is_some(), || {
|
||||
("there are too many leading `super` keywords".to_string(), None)
|
||||
});
|
||||
}
|
||||
if i == 0 {
|
||||
if name == kw::SelfLower {
|
||||
@ -2313,22 +2301,19 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// Report special messages for path segment keywords in wrong positions.
|
||||
if ident.is_path_segment_keyword() && i != 0 {
|
||||
let name_str = if name == kw::PathRoot {
|
||||
"crate root".to_string()
|
||||
} else {
|
||||
format!("`{}`", name)
|
||||
};
|
||||
let label = if i == 1 && path[0].ident.name == kw::PathRoot {
|
||||
format!("global paths cannot start with {}", name_str)
|
||||
} else {
|
||||
format!("{} in paths can only be used in start position", name_str)
|
||||
};
|
||||
return PathResult::Failed {
|
||||
span: ident.span,
|
||||
label,
|
||||
suggestion: None,
|
||||
is_error_from_last_segment: false,
|
||||
};
|
||||
return PathResult::failed(ident.span, false, finalize.is_some(), || {
|
||||
let name_str = if name == kw::PathRoot {
|
||||
"crate root".to_string()
|
||||
} else {
|
||||
format!("`{}`", name)
|
||||
};
|
||||
let label = if i == 1 && path[0].ident.name == kw::PathRoot {
|
||||
format!("global paths cannot start with {}", name_str)
|
||||
} else {
|
||||
format!("{} in paths can only be used in start position", name_str)
|
||||
};
|
||||
(label, None)
|
||||
});
|
||||
}
|
||||
|
||||
enum FindBindingResult<'a> {
|
||||
@ -2337,36 +2322,22 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
let find_binding_in_ns = |this: &mut Self, ns| {
|
||||
let binding = if let Some(module) = module {
|
||||
this.resolve_ident_in_module(
|
||||
module,
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
)
|
||||
this.resolve_ident_in_module(module, ident, ns, parent_scope, finalize)
|
||||
} else if ribs.is_none() || opt_ns.is_none() || opt_ns == Some(MacroNS) {
|
||||
let scopes = ScopeSet::All(ns, opt_ns.is_none());
|
||||
this.early_resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
scopes,
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
finalize.is_some(),
|
||||
)
|
||||
} else {
|
||||
let record_used_id = if record_used {
|
||||
crate_lint.node_id().or(Some(CRATE_NODE_ID))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
match this.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used_id,
|
||||
path_span,
|
||||
finalize_full,
|
||||
&ribs.unwrap()[ns],
|
||||
) {
|
||||
// we found a locally-imported or available item/module
|
||||
@ -2380,7 +2351,7 @@ impl<'a> Resolver<'a> {
|
||||
PartialRes::with_unresolved_segments(res, path.len() - 1),
|
||||
));
|
||||
}
|
||||
_ => Err(Determinacy::determined(record_used)),
|
||||
_ => Err(Determinacy::determined(finalize.is_some())),
|
||||
}
|
||||
};
|
||||
FindBindingResult::Binding(binding)
|
||||
@ -2414,30 +2385,20 @@ impl<'a> Resolver<'a> {
|
||||
} else if res == Res::Err {
|
||||
return PathResult::NonModule(PartialRes::new(Res::Err));
|
||||
} else if opt_ns.is_some() && (is_last || maybe_assoc) {
|
||||
self.lint_if_path_starts_with_module(
|
||||
crate_lint,
|
||||
path,
|
||||
path_span,
|
||||
second_binding,
|
||||
);
|
||||
self.lint_if_path_starts_with_module(finalize_full, path, second_binding);
|
||||
return PathResult::NonModule(PartialRes::with_unresolved_segments(
|
||||
res,
|
||||
path.len() - i - 1,
|
||||
));
|
||||
} else {
|
||||
let label = format!(
|
||||
"`{}` is {} {}, not a module",
|
||||
ident,
|
||||
res.article(),
|
||||
res.descr(),
|
||||
);
|
||||
|
||||
return PathResult::Failed {
|
||||
span: ident.span,
|
||||
label,
|
||||
suggestion: None,
|
||||
is_error_from_last_segment: is_last,
|
||||
};
|
||||
return PathResult::failed(ident.span, is_last, finalize.is_some(), || {
|
||||
let label = format!(
|
||||
"`{ident}` is {} {}, not a module",
|
||||
res.article(),
|
||||
res.descr()
|
||||
);
|
||||
(label, None)
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(Undetermined) => return PathResult::Indeterminate,
|
||||
@ -2450,196 +2411,192 @@ impl<'a> Resolver<'a> {
|
||||
));
|
||||
}
|
||||
}
|
||||
let module_res = match module {
|
||||
Some(ModuleOrUniformRoot::Module(module)) => module.res(),
|
||||
_ => None,
|
||||
};
|
||||
let (label, suggestion) = if module_res == self.graph_root.res() {
|
||||
let is_mod = |res| matches!(res, Res::Def(DefKind::Mod, _));
|
||||
// Don't look up import candidates if this is a speculative resolve
|
||||
let mut candidates = if record_used {
|
||||
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod)
|
||||
} else {
|
||||
Vec::new()
|
||||
|
||||
return PathResult::failed(ident.span, is_last, finalize.is_some(), || {
|
||||
let module_res = match module {
|
||||
Some(ModuleOrUniformRoot::Module(module)) => module.res(),
|
||||
_ => None,
|
||||
};
|
||||
candidates.sort_by_cached_key(|c| {
|
||||
(c.path.segments.len(), pprust::path_to_string(&c.path))
|
||||
});
|
||||
if let Some(candidate) = candidates.get(0) {
|
||||
(
|
||||
String::from("unresolved import"),
|
||||
Some((
|
||||
vec![(ident.span, pprust::path_to_string(&candidate.path))],
|
||||
String::from("a similar path exists"),
|
||||
Applicability::MaybeIncorrect,
|
||||
)),
|
||||
)
|
||||
} else if self.session.edition() == Edition::Edition2015 {
|
||||
(format!("maybe a missing crate `{}`?", ident), None)
|
||||
} else {
|
||||
(format!("could not find `{}` in the crate root", ident), None)
|
||||
}
|
||||
} else if i == 0 {
|
||||
if ident
|
||||
.name
|
||||
.as_str()
|
||||
.chars()
|
||||
.next()
|
||||
.map_or(false, |c| c.is_ascii_uppercase())
|
||||
{
|
||||
// Check whether the name refers to an item in the value namespace.
|
||||
let suggestion = if ribs.is_some() {
|
||||
let match_span = match self.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ValueNS,
|
||||
parent_scope,
|
||||
None,
|
||||
path_span,
|
||||
&ribs.unwrap()[ValueNS],
|
||||
) {
|
||||
// Name matches a local variable. For example:
|
||||
// ```
|
||||
// fn f() {
|
||||
// let Foo: &str = "";
|
||||
// println!("{}", Foo::Bar); // Name refers to local
|
||||
// // variable `Foo`.
|
||||
// }
|
||||
// ```
|
||||
Some(LexicalScopeBinding::Res(Res::Local(id))) => {
|
||||
Some(*self.pat_span_map.get(&id).unwrap())
|
||||
}
|
||||
|
||||
// Name matches item from a local name binding
|
||||
// created by `use` declaration. For example:
|
||||
// ```
|
||||
// pub Foo: &str = "";
|
||||
//
|
||||
// mod submod {
|
||||
// use super::Foo;
|
||||
// println!("{}", Foo::Bar); // Name refers to local
|
||||
// // binding `Foo`.
|
||||
// }
|
||||
// ```
|
||||
Some(LexicalScopeBinding::Item(name_binding)) => {
|
||||
Some(name_binding.span)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(span) = match_span {
|
||||
if module_res == self.graph_root.res() {
|
||||
let is_mod = |res| matches!(res, Res::Def(DefKind::Mod, _));
|
||||
let mut candidates =
|
||||
self.lookup_import_candidates(ident, TypeNS, parent_scope, is_mod);
|
||||
candidates.sort_by_cached_key(|c| {
|
||||
(c.path.segments.len(), pprust::path_to_string(&c.path))
|
||||
});
|
||||
if let Some(candidate) = candidates.get(0) {
|
||||
(
|
||||
String::from("unresolved import"),
|
||||
Some((
|
||||
vec![(span, String::from(""))],
|
||||
format!("`{}` is defined here, but is not a type", ident),
|
||||
vec![(ident.span, pprust::path_to_string(&candidate.path))],
|
||||
String::from("a similar path exists"),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
)),
|
||||
)
|
||||
} else if self.session.edition() == Edition::Edition2015 {
|
||||
(format!("maybe a missing crate `{}`?", ident), None)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(format!("could not find `{}` in the crate root", ident), None)
|
||||
}
|
||||
} else if i == 0 {
|
||||
if ident
|
||||
.name
|
||||
.as_str()
|
||||
.chars()
|
||||
.next()
|
||||
.map_or(false, |c| c.is_ascii_uppercase())
|
||||
{
|
||||
// Check whether the name refers to an item in the value namespace.
|
||||
let suggestion = if ribs.is_some() {
|
||||
let match_span = match self.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ValueNS,
|
||||
parent_scope,
|
||||
Finalize::No,
|
||||
&ribs.unwrap()[ValueNS],
|
||||
) {
|
||||
// Name matches a local variable. For example:
|
||||
// ```
|
||||
// fn f() {
|
||||
// let Foo: &str = "";
|
||||
// println!("{}", Foo::Bar); // Name refers to local
|
||||
// // variable `Foo`.
|
||||
// }
|
||||
// ```
|
||||
Some(LexicalScopeBinding::Res(Res::Local(id))) => {
|
||||
Some(*self.pat_span_map.get(&id).unwrap())
|
||||
}
|
||||
|
||||
(format!("use of undeclared type `{}`", ident), suggestion)
|
||||
} else {
|
||||
(
|
||||
format!("use of undeclared crate or module `{}`", ident),
|
||||
if ident.name == sym::alloc {
|
||||
Some((
|
||||
vec![],
|
||||
String::from(
|
||||
"add `extern crate alloc` to use the `alloc` crate",
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
} else {
|
||||
self.find_similarly_named_module_or_crate(
|
||||
ident.name,
|
||||
&parent_scope.module,
|
||||
)
|
||||
.map(|sugg| {
|
||||
(
|
||||
vec![(ident.span, sugg.to_string())],
|
||||
String::from(
|
||||
"there is a crate or module with a similar name",
|
||||
// Name matches item from a local name binding
|
||||
// created by `use` declaration. For example:
|
||||
// ```
|
||||
// pub Foo: &str = "";
|
||||
//
|
||||
// mod submod {
|
||||
// use super::Foo;
|
||||
// println!("{}", Foo::Bar); // Name refers to local
|
||||
// // binding `Foo`.
|
||||
// }
|
||||
// ```
|
||||
Some(LexicalScopeBinding::Item(name_binding)) => {
|
||||
Some(name_binding.span)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(span) = match_span {
|
||||
Some((
|
||||
vec![(span, String::from(""))],
|
||||
format!(
|
||||
"`{}` is defined here, but is not a type",
|
||||
ident
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
} else {
|
||||
let parent = path[i - 1].ident.name;
|
||||
let parent = match parent {
|
||||
// ::foo is mounted at the crate root for 2015, and is the extern
|
||||
// prelude for 2018+
|
||||
kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
|
||||
"the list of imported crates".to_owned()
|
||||
}
|
||||
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
|
||||
_ => {
|
||||
format!("`{}`", parent)
|
||||
}
|
||||
};
|
||||
|
||||
let mut msg = format!("could not find `{}` in {}", ident, parent);
|
||||
if ns == TypeNS || ns == ValueNS {
|
||||
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
|
||||
if let FindBindingResult::Binding(Ok(binding)) =
|
||||
find_binding_in_ns(self, ns_to_try)
|
||||
{
|
||||
let mut found = |what| {
|
||||
msg = format!(
|
||||
"expected {}, found {} `{}` in {}",
|
||||
ns.descr(),
|
||||
what,
|
||||
ident,
|
||||
parent
|
||||
)
|
||||
};
|
||||
if binding.module().is_some() {
|
||||
found("module")
|
||||
} else {
|
||||
match binding.res() {
|
||||
def::Res::<NodeId>::Def(kind, id) => found(kind.descr(id)),
|
||||
_ => found(ns_to_try.descr()),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
(format!("use of undeclared type `{}`", ident), suggestion)
|
||||
} else {
|
||||
(
|
||||
format!("use of undeclared crate or module `{}`", ident),
|
||||
if ident.name == sym::alloc {
|
||||
Some((
|
||||
vec![],
|
||||
String::from(
|
||||
"add `extern crate alloc` to use the `alloc` crate",
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
))
|
||||
} else {
|
||||
self.find_similarly_named_module_or_crate(
|
||||
ident.name,
|
||||
&parent_scope.module,
|
||||
)
|
||||
.map(|sugg| {
|
||||
(
|
||||
vec![(ident.span, sugg.to_string())],
|
||||
String::from(
|
||||
"there is a crate or module with a similar name",
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
} else {
|
||||
let parent = path[i - 1].ident.name;
|
||||
let parent = match parent {
|
||||
// ::foo is mounted at the crate root for 2015, and is the extern
|
||||
// prelude for 2018+
|
||||
kw::PathRoot if self.session.edition() > Edition::Edition2015 => {
|
||||
"the list of imported crates".to_owned()
|
||||
}
|
||||
kw::PathRoot | kw::Crate => "the crate root".to_owned(),
|
||||
_ => {
|
||||
format!("`{}`", parent)
|
||||
}
|
||||
};
|
||||
|
||||
let mut msg = format!("could not find `{}` in {}", ident, parent);
|
||||
if ns == TypeNS || ns == ValueNS {
|
||||
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
|
||||
if let FindBindingResult::Binding(Ok(binding)) =
|
||||
find_binding_in_ns(self, ns_to_try)
|
||||
{
|
||||
let mut found = |what| {
|
||||
msg = format!(
|
||||
"expected {}, found {} `{}` in {}",
|
||||
ns.descr(),
|
||||
what,
|
||||
ident,
|
||||
parent
|
||||
)
|
||||
};
|
||||
if binding.module().is_some() {
|
||||
found("module")
|
||||
} else {
|
||||
match binding.res() {
|
||||
def::Res::<NodeId>::Def(kind, id) => {
|
||||
found(kind.descr(id))
|
||||
}
|
||||
_ => found(ns_to_try.descr()),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
(msg, None)
|
||||
}
|
||||
(msg, None)
|
||||
};
|
||||
return PathResult::Failed {
|
||||
span: ident.span,
|
||||
label,
|
||||
suggestion,
|
||||
is_error_from_last_segment: is_last,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.lint_if_path_starts_with_module(crate_lint, path, path_span, second_binding);
|
||||
self.lint_if_path_starts_with_module(finalize_full, path, second_binding);
|
||||
|
||||
PathResult::Module(match module {
|
||||
Some(module) => module,
|
||||
None if path.is_empty() => ModuleOrUniformRoot::CurrentScope,
|
||||
_ => span_bug!(path_span, "resolve_path: non-empty path `{:?}` has no module", path),
|
||||
_ => bug!("resolve_path: non-empty path `{:?}` has no module", path),
|
||||
})
|
||||
}
|
||||
|
||||
fn lint_if_path_starts_with_module(
|
||||
&mut self,
|
||||
crate_lint: CrateLint,
|
||||
finalize: Finalize,
|
||||
path: &[Segment],
|
||||
path_span: Span,
|
||||
second_binding: Option<&NameBinding<'_>>,
|
||||
) {
|
||||
let (diag_id, diag_span) = match crate_lint {
|
||||
CrateLint::No => return,
|
||||
CrateLint::SimplePath(id) => (id, path_span),
|
||||
CrateLint::UsePath { root_id, root_span } => (root_id, root_span),
|
||||
CrateLint::QPathTrait { qpath_id, qpath_span } => (qpath_id, qpath_span),
|
||||
let (diag_id, diag_span) = match finalize {
|
||||
Finalize::No => return,
|
||||
Finalize::SimplePath(id, path_span) => (id, path_span),
|
||||
Finalize::UsePath { root_id, root_span, .. } => (root_id, root_span),
|
||||
Finalize::QPathTrait { qpath_id, qpath_span, .. } => (qpath_id, qpath_span),
|
||||
};
|
||||
|
||||
let first_name = match path.get(0) {
|
||||
@ -2694,8 +2651,7 @@ impl<'a> Resolver<'a> {
|
||||
rib_index: usize,
|
||||
rib_ident: Ident,
|
||||
mut res: Res,
|
||||
record_used: bool,
|
||||
span: Span,
|
||||
finalize: Option<Span>,
|
||||
original_rib_ident_def: Ident,
|
||||
all_ribs: &[Rib<'a>],
|
||||
) -> Res {
|
||||
@ -2705,7 +2661,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// An invalid forward use of a generic parameter from a previous default.
|
||||
if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||
ResolutionError::SelfInGenericParamDefault
|
||||
} else {
|
||||
@ -2735,17 +2691,17 @@ impl<'a> Resolver<'a> {
|
||||
// This was an attempt to access an upvar inside a
|
||||
// named function item. This is not allowed, so we
|
||||
// report an error.
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
// We don't immediately trigger a resolve error, because
|
||||
// we want certain other resolution errors (namely those
|
||||
// emitted for `ConstantItemRibKind` below) to take
|
||||
// precedence.
|
||||
res_err = Some(CannotCaptureDynamicEnvironmentInFnItem);
|
||||
res_err = Some((span, CannotCaptureDynamicEnvironmentInFnItem));
|
||||
}
|
||||
}
|
||||
ConstantItemRibKind(_, item) => {
|
||||
// Still doesn't deal with upvars
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
let (span, resolution_error) =
|
||||
if let Some((ident, constant_item_kind)) = item {
|
||||
let kind_str = match constant_item_kind {
|
||||
@ -2773,14 +2729,14 @@ impl<'a> Resolver<'a> {
|
||||
return Res::Err;
|
||||
}
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(span, ParamInTyOfConstParam(rib_ident.name));
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(res_err) = res_err {
|
||||
if let Some((span, res_err)) = res_err {
|
||||
self.report_error(span, res_err);
|
||||
return Res::Err;
|
||||
}
|
||||
@ -2808,7 +2764,7 @@ impl<'a> Resolver<'a> {
|
||||
if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res {
|
||||
res = Res::SelfTy { trait_, alias_to: Some((def, true)) }
|
||||
} else {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
@ -2816,9 +2772,9 @@ impl<'a> Resolver<'a> {
|
||||
is_type: true,
|
||||
},
|
||||
);
|
||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
||||
}
|
||||
|
||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
||||
return Res::Err;
|
||||
}
|
||||
}
|
||||
@ -2830,7 +2786,7 @@ impl<'a> Resolver<'a> {
|
||||
ItemRibKind(has_generic_params) => has_generic_params,
|
||||
FnItemRibKind => HasGenericParams::Yes,
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam(rib_ident.name),
|
||||
@ -2840,7 +2796,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::GenericParamsFromOuterFunction(
|
||||
@ -2874,7 +2830,7 @@ impl<'a> Resolver<'a> {
|
||||
let features = self.session.features_untracked();
|
||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||
if !(trivial || features.generic_const_exprs) {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
@ -2882,9 +2838,9 @@ impl<'a> Resolver<'a> {
|
||||
is_type: false,
|
||||
},
|
||||
);
|
||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
||||
}
|
||||
|
||||
self.session.delay_span_bug(span, CG_BUG_STR);
|
||||
return Res::Err;
|
||||
}
|
||||
|
||||
@ -2894,7 +2850,7 @@ impl<'a> Resolver<'a> {
|
||||
ItemRibKind(has_generic_params) => has_generic_params,
|
||||
FnItemRibKind => HasGenericParams::Yes,
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam(rib_ident.name),
|
||||
@ -2905,7 +2861,7 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
|
||||
// This was an attempt to use a const parameter outside its scope.
|
||||
if record_used {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::GenericParamsFromOuterFunction(
|
||||
@ -3293,23 +3249,19 @@ impl<'a> Resolver<'a> {
|
||||
err.span_suggestion(span, message, String::new(), Applicability::MachineApplicable);
|
||||
}
|
||||
|
||||
fn extern_prelude_get(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
speculative: bool,
|
||||
) -> Option<&'a NameBinding<'a>> {
|
||||
fn extern_prelude_get(&mut self, ident: Ident, finalize: bool) -> Option<&'a NameBinding<'a>> {
|
||||
if ident.is_path_segment_keyword() {
|
||||
// Make sure `self`, `super` etc produce an error when passed to here.
|
||||
return None;
|
||||
}
|
||||
self.extern_prelude.get(&ident.normalize_to_macros_2_0()).cloned().and_then(|entry| {
|
||||
if let Some(binding) = entry.extern_crate_item {
|
||||
if !speculative && entry.introduced_by_item {
|
||||
if finalize && entry.introduced_by_item {
|
||||
self.record_use(ident, binding, false);
|
||||
}
|
||||
Some(binding)
|
||||
} else {
|
||||
let crate_id = if !speculative {
|
||||
let crate_id = if finalize {
|
||||
let Some(crate_id) =
|
||||
self.crate_loader.process_path_extern(ident.name, ident.span) else { return Some(self.dummy_binding); };
|
||||
crate_id
|
||||
@ -3325,81 +3277,36 @@ impl<'a> Resolver<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Rustdoc uses this to resolve things in a recoverable way. `ResolutionError<'a>`
|
||||
/// Rustdoc uses this to resolve doc link paths in a recoverable way. `PathResult<'a>`
|
||||
/// isn't something that can be returned because it can't be made to live that long,
|
||||
/// and also it's a private type. Fortunately rustdoc doesn't need to know the error,
|
||||
/// just that an error occurred.
|
||||
// FIXME(Manishearth): intra-doc links won't get warned of epoch changes.
|
||||
pub fn resolve_str_path_error(
|
||||
pub fn resolve_rustdoc_path(
|
||||
&mut self,
|
||||
span: Span,
|
||||
path_str: &str,
|
||||
ns: Namespace,
|
||||
module_id: DefId,
|
||||
) -> Result<(ast::Path, Res), ()> {
|
||||
let path = if path_str.starts_with("::") {
|
||||
ast::Path {
|
||||
span,
|
||||
segments: iter::once(Ident::with_dummy_span(kw::PathRoot))
|
||||
.chain(path_str.split("::").skip(1).map(Ident::from_str))
|
||||
.map(|i| self.new_ast_path_segment(i))
|
||||
.collect(),
|
||||
tokens: None,
|
||||
}
|
||||
} else {
|
||||
ast::Path {
|
||||
span,
|
||||
segments: path_str
|
||||
.split("::")
|
||||
.map(Ident::from_str)
|
||||
.map(|i| self.new_ast_path_segment(i))
|
||||
.collect(),
|
||||
tokens: None,
|
||||
}
|
||||
};
|
||||
let module = self.expect_module(module_id);
|
||||
let parent_scope = &ParentScope::module(module, self);
|
||||
let res = self.resolve_ast_path(&path, ns, parent_scope).map_err(|_| ())?;
|
||||
Ok((path, res))
|
||||
}
|
||||
|
||||
// Resolve a path passed from rustdoc or HIR lowering.
|
||||
fn resolve_ast_path(
|
||||
&mut self,
|
||||
path: &ast::Path,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Result<Res, (Span, ResolutionError<'a>)> {
|
||||
match self.resolve_path(
|
||||
&Segment::from_path(path),
|
||||
Some(ns),
|
||||
parent_scope,
|
||||
false,
|
||||
path.span,
|
||||
CrateLint::No,
|
||||
) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Ok(module.res().unwrap()),
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
Ok(path_res.base_res())
|
||||
}
|
||||
PathResult::NonModule(..) => Err((
|
||||
path.span,
|
||||
ResolutionError::FailedToResolve {
|
||||
label: String::from("type-relative paths are not supported in this context"),
|
||||
suggestion: None,
|
||||
},
|
||||
)),
|
||||
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
|
||||
PathResult::Failed { span, label, suggestion, .. } => {
|
||||
Err((span, ResolutionError::FailedToResolve { label, suggestion }))
|
||||
}
|
||||
) -> Option<Res> {
|
||||
let mut segments =
|
||||
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
|
||||
if path_str.starts_with("::") {
|
||||
segments[0].ident.name = kw::PathRoot;
|
||||
}
|
||||
}
|
||||
|
||||
fn new_ast_path_segment(&mut self, ident: Ident) -> ast::PathSegment {
|
||||
let mut seg = ast::PathSegment::from_ident(ident);
|
||||
seg.id = self.next_node_id();
|
||||
seg
|
||||
let module = self.expect_module(module_id);
|
||||
match self.resolve_path(
|
||||
&segments,
|
||||
Some(ns),
|
||||
&ParentScope::module(module, self),
|
||||
Finalize::No,
|
||||
) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
Some(path_res.base_res())
|
||||
}
|
||||
PathResult::NonModule(..) | PathResult::Failed { .. } => None,
|
||||
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
// For rustdoc.
|
||||
@ -3485,8 +3392,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ValueNS,
|
||||
parent_scope,
|
||||
false,
|
||||
DUMMY_SP,
|
||||
None
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
@ -3544,35 +3450,43 @@ fn module_to_string(module: Module<'_>) -> Option<String> {
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
enum CrateLint {
|
||||
enum Finalize {
|
||||
/// Do not issue the lint.
|
||||
No,
|
||||
|
||||
/// This lint applies to some arbitrary path; e.g., `impl ::foo::Bar`.
|
||||
/// In this case, we can take the span of that path.
|
||||
SimplePath(NodeId),
|
||||
SimplePath(NodeId, Span),
|
||||
|
||||
/// This lint comes from a `use` statement. In this case, what we
|
||||
/// care about really is the *root* `use` statement; e.g., if we
|
||||
/// have nested things like `use a::{b, c}`, we care about the
|
||||
/// `use a` part.
|
||||
UsePath { root_id: NodeId, root_span: Span },
|
||||
UsePath { root_id: NodeId, root_span: Span, path_span: Span },
|
||||
|
||||
/// This is the "trait item" from a fully qualified path. For example,
|
||||
/// we might be resolving `X::Y::Z` from a path like `<T as X::Y>::Z`.
|
||||
/// The `path_span` is the span of the to the trait itself (`X::Y`).
|
||||
QPathTrait { qpath_id: NodeId, qpath_span: Span },
|
||||
QPathTrait { qpath_id: NodeId, qpath_span: Span, path_span: Span },
|
||||
}
|
||||
|
||||
impl CrateLint {
|
||||
fn node_id(&self) -> Option<NodeId> {
|
||||
impl Finalize {
|
||||
fn node_id_and_path_span(&self) -> Option<(NodeId, Span)> {
|
||||
match *self {
|
||||
CrateLint::No => None,
|
||||
CrateLint::SimplePath(id)
|
||||
| CrateLint::UsePath { root_id: id, .. }
|
||||
| CrateLint::QPathTrait { qpath_id: id, .. } => Some(id),
|
||||
Finalize::No => None,
|
||||
Finalize::SimplePath(id, path_span)
|
||||
| Finalize::UsePath { root_id: id, path_span, .. }
|
||||
| Finalize::QPathTrait { qpath_id: id, path_span, .. } => Some((id, path_span)),
|
||||
}
|
||||
}
|
||||
|
||||
fn node_id(&self) -> Option<NodeId> {
|
||||
self.node_id_and_path_span().map(|(id, _)| id)
|
||||
}
|
||||
|
||||
fn path_span(&self) -> Option<Span> {
|
||||
self.node_id_and_path_span().map(|(_, path_span)| path_span)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -4,7 +4,7 @@
|
||||
use crate::imports::ImportResolver;
|
||||
use crate::Namespace::*;
|
||||
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BuiltinMacroState, Determinacy};
|
||||
use crate::{CrateLint, DeriveData, ParentScope, ResolutionError, Resolver, Scope, ScopeSet, Weak};
|
||||
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, Scope, ScopeSet, Weak};
|
||||
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment, ToNameBinding};
|
||||
use rustc_ast::{self as ast, Inline, ItemKind, ModKind, NodeId};
|
||||
use rustc_ast_lowering::ResolverAstLowering;
|
||||
@ -415,7 +415,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
|
||||
|
||||
let mut indeterminate = false;
|
||||
for ns in [TypeNS, ValueNS, MacroNS].iter().copied() {
|
||||
match self.resolve_path(path, Some(ns), &parent_scope, false, span, CrateLint::No) {
|
||||
match self.resolve_path(path, Some(ns), &parent_scope, Finalize::No) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(_)) => return Ok(true),
|
||||
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
|
||||
return Ok(true);
|
||||
@ -575,14 +575,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
let res = if path.len() > 1 {
|
||||
let res = match self.resolve_path(
|
||||
&path,
|
||||
Some(MacroNS),
|
||||
parent_scope,
|
||||
false,
|
||||
path_span,
|
||||
CrateLint::No,
|
||||
) {
|
||||
let res = match self.resolve_path(&path, Some(MacroNS), parent_scope, Finalize::No) {
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
Ok(path_res.base_res())
|
||||
}
|
||||
@ -612,9 +605,8 @@ impl<'a> Resolver<'a> {
|
||||
path[0].ident,
|
||||
scope_set,
|
||||
parent_scope,
|
||||
false,
|
||||
None,
|
||||
force,
|
||||
path_span,
|
||||
);
|
||||
if let Err(Determinacy::Undetermined) = binding {
|
||||
return Err(Determinacy::Undetermined);
|
||||
@ -648,9 +640,8 @@ impl<'a> Resolver<'a> {
|
||||
orig_ident: Ident,
|
||||
scope_set: ScopeSet<'a>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
finalize: Option<Span>,
|
||||
force: bool,
|
||||
path_span: Span,
|
||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||
bitflags::bitflags! {
|
||||
struct Flags: u8 {
|
||||
@ -662,7 +653,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
assert!(force || !record_used); // `record_used` implies `force`
|
||||
assert!(force || !finalize.is_some()); // `finalize` implies `force`
|
||||
|
||||
// Make sure `self`, `super` etc produce an error when passed to here.
|
||||
if orig_ident.is_path_segment_keyword() {
|
||||
@ -769,8 +760,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
|
||||
@ -791,8 +781,7 @@ impl<'a> Resolver<'a> {
|
||||
ns,
|
||||
adjusted_parent_scope,
|
||||
!matches!(scope_set, ScopeSet::Late(..)),
|
||||
record_used,
|
||||
path_span,
|
||||
finalize,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => {
|
||||
@ -856,12 +845,14 @@ impl<'a> Resolver<'a> {
|
||||
Err(Determinacy::Determined)
|
||||
}
|
||||
}
|
||||
Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) {
|
||||
Some(binding) => Ok((binding, Flags::empty())),
|
||||
None => Err(Determinacy::determined(
|
||||
this.graph_root.unexpanded_invocations.borrow().is_empty(),
|
||||
)),
|
||||
},
|
||||
Scope::ExternPrelude => {
|
||||
match this.extern_prelude_get(ident, finalize.is_some()) {
|
||||
Some(binding) => Ok((binding, Flags::empty())),
|
||||
None => Err(Determinacy::determined(
|
||||
this.graph_root.unexpanded_invocations.borrow().is_empty(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
Scope::ToolPrelude => match this.registered_tools.get(&ident).cloned() {
|
||||
Some(ident) => ok(Res::ToolMod, ident.span, this.arenas),
|
||||
None => Err(Determinacy::Determined),
|
||||
@ -874,8 +865,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
false,
|
||||
path_span,
|
||||
None,
|
||||
) {
|
||||
if use_prelude || this.is_builtin_macro(binding.res()) {
|
||||
result = Ok((binding, Flags::MISC_FROM_PRELUDE));
|
||||
@ -894,7 +884,7 @@ impl<'a> Resolver<'a> {
|
||||
Ok((binding, flags))
|
||||
if sub_namespace_match(binding.macro_kind(), macro_kind) =>
|
||||
{
|
||||
if !record_used || matches!(scope_set, ScopeSet::Late(..)) {
|
||||
if finalize.is_none() || matches!(scope_set, ScopeSet::Late(..)) {
|
||||
return Some(Ok(binding));
|
||||
}
|
||||
|
||||
@ -1033,9 +1023,7 @@ impl<'a> Resolver<'a> {
|
||||
&path,
|
||||
Some(MacroNS),
|
||||
&parent_scope,
|
||||
true,
|
||||
path_span,
|
||||
CrateLint::No,
|
||||
Finalize::SimplePath(ast::CRATE_NODE_ID, path_span),
|
||||
) {
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
let res = path_res.base_res();
|
||||
@ -1069,9 +1057,8 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ScopeSet::Macro(kind),
|
||||
&parent_scope,
|
||||
Some(ident.span),
|
||||
true,
|
||||
true,
|
||||
ident.span,
|
||||
) {
|
||||
Ok(binding) => {
|
||||
let initial_res = initial_binding.map(|initial_binding| {
|
||||
@ -1111,9 +1098,8 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ScopeSet::Macro(MacroKind::Attr),
|
||||
&parent_scope,
|
||||
Some(ident.span),
|
||||
true,
|
||||
true,
|
||||
ident.span,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -568,7 +568,7 @@ fn configure_cmake(
|
||||
// We also do this if the user explicitly requested static libstdc++.
|
||||
if builder.config.llvm_static_stdcpp {
|
||||
if !target.contains("msvc") && !target.contains("netbsd") {
|
||||
if target.contains("apple") {
|
||||
if target.contains("apple") || target.contains("windows") {
|
||||
ldflags.push_all("-static-libstdc++");
|
||||
} else {
|
||||
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
|
||||
|
@ -487,12 +487,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||
module_id: DefId,
|
||||
) -> Result<Res, ResolutionFailure<'a>> {
|
||||
self.cx.enter_resolver(|resolver| {
|
||||
// NOTE: this needs 2 separate lookups because `resolve_str_path_error` doesn't take
|
||||
// NOTE: this needs 2 separate lookups because `resolve_rustdoc_path` doesn't take
|
||||
// lexical scope into account (it ignores all macros not defined at the mod-level)
|
||||
debug!("resolving {} as a macro in the module {:?}", path_str, module_id);
|
||||
if let Ok((_, res)) =
|
||||
resolver.resolve_str_path_error(DUMMY_SP, path_str, MacroNS, module_id)
|
||||
{
|
||||
if let Some(res) = resolver.resolve_rustdoc_path(path_str, MacroNS, module_id) {
|
||||
// don't resolve builtins like `#[derive]`
|
||||
if let Ok(res) = res.try_into() {
|
||||
return Ok(res);
|
||||
@ -540,10 +538,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Convenience wrapper around `resolve_str_path_error`.
|
||||
/// Convenience wrapper around `resolve_rustdoc_path`.
|
||||
///
|
||||
/// This also handles resolving `true` and `false` as booleans.
|
||||
/// NOTE: `resolve_str_path_error` knows only about paths, not about types.
|
||||
/// NOTE: `resolve_rustdoc_path` knows only about paths, not about types.
|
||||
/// Associated items will never be resolved by this function.
|
||||
fn resolve_path(
|
||||
&self,
|
||||
@ -556,18 +554,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
|
||||
return res;
|
||||
}
|
||||
|
||||
let result = self.cx.enter_resolver(|resolver| {
|
||||
resolver
|
||||
.resolve_str_path_error(DUMMY_SP, path_str, ns, module_id)
|
||||
.and_then(|(_, res)| res.try_into())
|
||||
});
|
||||
// Resolver doesn't know about true, false, and types that aren't paths (e.g. `()`).
|
||||
let result = self
|
||||
.cx
|
||||
.enter_resolver(|resolver| resolver.resolve_rustdoc_path(path_str, ns, module_id))
|
||||
.and_then(|res| res.try_into().ok())
|
||||
.or_else(|| resolve_primitive(path_str, ns));
|
||||
debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns);
|
||||
match result {
|
||||
// resolver doesn't know about true, false, and types that aren't paths (e.g. `()`)
|
||||
// manually as bool
|
||||
Err(()) => resolve_primitive(path_str, ns),
|
||||
Ok(res) => Some(res),
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Resolves a string as a path within a particular namespace. Returns an
|
||||
|
@ -13,7 +13,7 @@ use rustc_hir::TraitCandidate;
|
||||
use rustc_middle::ty::{DefIdTree, Visibility};
|
||||
use rustc_resolve::{ParentScope, Resolver};
|
||||
use rustc_session::config::Externs;
|
||||
use rustc_span::{Span, SyntaxContext, DUMMY_SP};
|
||||
use rustc_span::SyntaxContext;
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::mem;
|
||||
@ -39,7 +39,7 @@ crate fn early_resolve_intra_doc_links(
|
||||
|
||||
// Overridden `visit_item` below doesn't apply to the crate root,
|
||||
// so we have to visit its attributes and reexports separately.
|
||||
loader.load_links_in_attrs(&krate.attrs, krate.spans.inner_span);
|
||||
loader.load_links_in_attrs(&krate.attrs);
|
||||
loader.process_module_children_or_reexports(CRATE_DEF_ID.to_def_id());
|
||||
visit::walk_crate(&mut loader, krate);
|
||||
loader.add_foreign_traits_in_scope();
|
||||
@ -49,12 +49,7 @@ crate fn early_resolve_intra_doc_links(
|
||||
// DO NOT REMOVE THIS without first testing on the reproducer in
|
||||
// https://github.com/jyn514/objr/commit/edcee7b8124abf0e4c63873e8422ff81beb11ebb
|
||||
for (extern_name, _) in externs.iter().filter(|(_, entry)| entry.add_prelude) {
|
||||
let _ = loader.resolver.resolve_str_path_error(
|
||||
DUMMY_SP,
|
||||
extern_name,
|
||||
TypeNS,
|
||||
CRATE_DEF_ID.to_def_id(),
|
||||
);
|
||||
loader.resolver.resolve_rustdoc_path(extern_name, TypeNS, CRATE_DEF_ID.to_def_id());
|
||||
}
|
||||
|
||||
ResolverCaches {
|
||||
@ -151,7 +146,7 @@ impl IntraLinkCrateLoader<'_, '_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_links_in_attrs(&mut self, attrs: &[ast::Attribute], span: Span) {
|
||||
fn load_links_in_attrs(&mut self, attrs: &[ast::Attribute]) {
|
||||
// FIXME: this needs to consider reexport inlining.
|
||||
let attrs = clean::Attributes::from_ast(attrs, None);
|
||||
for (parent_module, doc) in attrs.collapsed_doc_value_by_module_level() {
|
||||
@ -165,7 +160,7 @@ impl IntraLinkCrateLoader<'_, '_> {
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
let _ = self.resolver.resolve_str_path_error(span, &path_str, TypeNS, module_id);
|
||||
self.resolver.resolve_rustdoc_path(&path_str, TypeNS, module_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,7 +196,7 @@ impl Visitor<'_> for IntraLinkCrateLoader<'_, '_> {
|
||||
// loaded, even if the module itself has no doc comments.
|
||||
self.add_traits_in_parent_scope(self.current_mod.to_def_id());
|
||||
|
||||
self.load_links_in_attrs(&item.attrs, item.span);
|
||||
self.load_links_in_attrs(&item.attrs);
|
||||
self.process_module_children_or_reexports(self.current_mod.to_def_id());
|
||||
visit::walk_item(self, item);
|
||||
|
||||
@ -216,28 +211,28 @@ impl Visitor<'_> for IntraLinkCrateLoader<'_, '_> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.load_links_in_attrs(&item.attrs, item.span);
|
||||
self.load_links_in_attrs(&item.attrs);
|
||||
visit::walk_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_assoc_item(&mut self, item: &ast::AssocItem, ctxt: AssocCtxt) {
|
||||
self.load_links_in_attrs(&item.attrs, item.span);
|
||||
self.load_links_in_attrs(&item.attrs);
|
||||
visit::walk_assoc_item(self, item, ctxt)
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &ast::ForeignItem) {
|
||||
self.load_links_in_attrs(&item.attrs, item.span);
|
||||
self.load_links_in_attrs(&item.attrs);
|
||||
visit::walk_foreign_item(self, item)
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &ast::Variant) {
|
||||
self.load_links_in_attrs(&v.attrs, v.span);
|
||||
self.load_links_in_attrs(&v.attrs);
|
||||
visit::walk_variant(self, v)
|
||||
}
|
||||
|
||||
fn visit_field_def(&mut self, field: &ast::FieldDef) {
|
||||
self.load_links_in_attrs(&field.attrs, field.span);
|
||||
self.load_links_in_attrs(&field.attrs);
|
||||
visit::walk_field_def(self, field)
|
||||
}
|
||||
|
||||
|
@ -17,28 +17,18 @@ crate mod foo {
|
||||
use crate::foo::{bar::{baz::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use crate::foo::{bar::{XX, baz::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use crate::foo::{bar::{baz::{}, baz1::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -17,28 +17,18 @@ crate mod foo {
|
||||
use foo::{bar::{baz::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use foo::{bar::{XX, baz::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use foo::{bar::{baz::{}, baz1::{}}};
|
||||
//~^ ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
@ -13,16 +13,7 @@ LL | #![deny(absolute_paths_not_starting_with_crate)]
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:17:5
|
||||
|
|
||||
LL | use foo::{bar::{baz::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}}}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:23:5
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:21:5
|
||||
|
|
||||
LL | use foo::{bar::{XX, baz::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{XX, baz::{}}}`
|
||||
@ -31,7 +22,7 @@ LL | use foo::{bar::{XX, baz::{}}};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:23:5
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:21:5
|
||||
|
|
||||
LL | use foo::{bar::{XX, baz::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{XX, baz::{}}}`
|
||||
@ -40,25 +31,7 @@ LL | use foo::{bar::{XX, baz::{}}};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:23:5
|
||||
|
|
||||
LL | use foo::{bar::{XX, baz::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{XX, baz::{}}}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:23:5
|
||||
|
|
||||
LL | use foo::{bar::{XX, baz::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{XX, baz::{}}}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:33:5
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:27:5
|
||||
|
|
||||
LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}, baz1::{}}}`
|
||||
@ -67,7 +40,7 @@ LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:33:5
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:27:5
|
||||
|
|
||||
LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}, baz1::{}}}`
|
||||
@ -75,23 +48,5 @@ LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:33:5
|
||||
|
|
||||
LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}, baz1::{}}}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-empty-paths.rs:33:5
|
||||
|
|
||||
LL | use foo::{bar::{baz::{}, baz1::{}}};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}, baz1::{}}}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
@ -8,10 +8,6 @@ use crate::foo::{a, b};
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
|
||||
mod foo {
|
||||
crate fn a() {}
|
||||
@ -29,8 +25,6 @@ fn main() {
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
x::a();
|
||||
c();
|
||||
}
|
||||
|
@ -8,10 +8,6 @@ use foo::{a, b};
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
|
||||
mod foo {
|
||||
crate fn a() {}
|
||||
@ -29,8 +25,6 @@ fn main() {
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start with
|
||||
//~| this is accepted in the current edition
|
||||
x::a();
|
||||
c();
|
||||
}
|
||||
|
@ -22,25 +22,7 @@ LL | use foo::{a, b};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-paths.rs:6:5
|
||||
|
|
||||
LL | use foo::{a, b};
|
||||
| ^^^^^^^^^^^ help: use `crate`: `crate::foo::{a, b}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-paths.rs:6:5
|
||||
|
|
||||
LL | use foo::{a, b};
|
||||
| ^^^^^^^^^^^ help: use `crate`: `crate::foo::{a, b}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-paths.rs:27:13
|
||||
--> $DIR/edition-lint-nested-paths.rs:23:13
|
||||
|
|
||||
LL | use foo::{self as x, c};
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{self as x, c}`
|
||||
@ -49,7 +31,7 @@ LL | use foo::{self as x, c};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-paths.rs:27:13
|
||||
--> $DIR/edition-lint-nested-paths.rs:23:13
|
||||
|
|
||||
LL | use foo::{self as x, c};
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{self as x, c}`
|
||||
@ -57,14 +39,5 @@ LL | use foo::{self as x, c};
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-nested-paths.rs:27:13
|
||||
|
|
||||
LL | use foo::{self as x, c};
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{self as x, c}`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -12,8 +12,6 @@ pub mod foo {
|
||||
use crate::bar::Bar;
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use super::bar::Bar2;
|
||||
use crate::bar::Bar3;
|
||||
@ -42,8 +40,6 @@ pub mod foo {
|
||||
use crate::bar::Bar;
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
pub mod bar {
|
||||
use edition_lint_paths as foo;
|
||||
@ -61,8 +57,6 @@ mod baz {
|
||||
impl crate::foo::SomeTrait for u32 {}
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
let x = crate::bar::Bar;
|
||||
|
@ -12,8 +12,6 @@ pub mod foo {
|
||||
use bar::Bar;
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
use super::bar::Bar2;
|
||||
use crate::bar::Bar3;
|
||||
@ -42,8 +40,6 @@ pub mod foo {
|
||||
use bar::Bar;
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
pub mod bar {
|
||||
use edition_lint_paths as foo;
|
||||
@ -61,8 +57,6 @@ mod baz {
|
||||
impl ::foo::SomeTrait for u32 {}
|
||||
//~^ ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
//~| ERROR absolute
|
||||
//~| WARN this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
let x = ::bar::Bar;
|
||||
|
@ -13,16 +13,7 @@ LL | #![deny(absolute_paths_not_starting_with_crate)]
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:12:9
|
||||
|
|
||||
LL | use bar::Bar;
|
||||
| ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:21:9
|
||||
--> $DIR/edition-lint-paths.rs:19:9
|
||||
|
|
||||
LL | use bar;
|
||||
| ^^^ help: use `crate`: `crate::bar`
|
||||
@ -31,7 +22,7 @@ LL | use bar;
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:27:9
|
||||
--> $DIR/edition-lint-paths.rs:25:9
|
||||
|
|
||||
LL | use {main, Bar as SomethingElse};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::{main, Bar as SomethingElse}`
|
||||
@ -40,7 +31,7 @@ LL | use {main, Bar as SomethingElse};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:27:9
|
||||
--> $DIR/edition-lint-paths.rs:25:9
|
||||
|
|
||||
LL | use {main, Bar as SomethingElse};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::{main, Bar as SomethingElse}`
|
||||
@ -49,7 +40,7 @@ LL | use {main, Bar as SomethingElse};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:27:9
|
||||
--> $DIR/edition-lint-paths.rs:25:9
|
||||
|
|
||||
LL | use {main, Bar as SomethingElse};
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::{main, Bar as SomethingElse}`
|
||||
@ -58,7 +49,7 @@ LL | use {main, Bar as SomethingElse};
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:42:5
|
||||
--> $DIR/edition-lint-paths.rs:40:5
|
||||
|
|
||||
LL | use bar::Bar;
|
||||
| ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
|
||||
@ -67,16 +58,7 @@ LL | use bar::Bar;
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:42:5
|
||||
|
|
||||
LL | use bar::Bar;
|
||||
| ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:56:9
|
||||
--> $DIR/edition-lint-paths.rs:52:9
|
||||
|
|
||||
LL | use *;
|
||||
| ^ help: use `crate`: `crate::*`
|
||||
@ -85,7 +67,7 @@ LL | use *;
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:61:6
|
||||
--> $DIR/edition-lint-paths.rs:57:6
|
||||
|
|
||||
LL | impl ::foo::SomeTrait for u32 {}
|
||||
| ^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::SomeTrait`
|
||||
@ -94,16 +76,7 @@ LL | impl ::foo::SomeTrait for u32 {}
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:61:6
|
||||
|
|
||||
LL | impl ::foo::SomeTrait for u32 {}
|
||||
| ^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::SomeTrait`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/edition-lint-paths.rs:68:13
|
||||
--> $DIR/edition-lint-paths.rs:62:13
|
||||
|
|
||||
LL | let x = ::bar::Bar;
|
||||
| ^^^^^^^^^^ help: use `crate`: `crate::bar::Bar`
|
||||
@ -111,5 +84,5 @@ LL | let x = ::bar::Bar;
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
@ -12,8 +12,6 @@ extern crate edition_lint_paths as my_crate;
|
||||
use crate::my_crate::foo;
|
||||
//~^ ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
|
@ -12,8 +12,6 @@ extern crate edition_lint_paths as my_crate;
|
||||
use my_crate::foo;
|
||||
//~^ ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
|
@ -12,14 +12,5 @@ LL | #![deny(absolute_paths_not_starting_with_crate)]
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/extern-crate-rename.rs:12:5
|
||||
|
|
||||
LL | use my_crate::foo;
|
||||
| ^^^^^^^^^^^^^ help: use `crate`: `crate::my_crate::foo`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -19,9 +19,6 @@ mod m {
|
||||
use crate::m::edition_lint_paths::foo;
|
||||
//~^ ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
|
@ -19,9 +19,6 @@ mod m {
|
||||
use m::edition_lint_paths::foo;
|
||||
//~^ ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
//~| ERROR absolute paths must start
|
||||
//~| WARNING this is accepted in the current edition
|
||||
|
||||
|
||||
fn main() {
|
||||
foo();
|
||||
|
@ -12,14 +12,5 @@ LL | #![deny(absolute_paths_not_starting_with_crate)]
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
|
||||
--> $DIR/extern-crate-submod.rs:19:5
|
||||
|
|
||||
LL | use m::edition_lint_paths::foo;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::m::edition_lint_paths::foo`
|
||||
|
|
||||
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
|
||||
= note: for more information, see issue #53130 <https://github.com/rust-lang/rust/issues/53130>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user