mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-29 16:13:40 +00:00
resolve: Stop passing unused spans and node ids to path resolution functions
This commit is contained in:
parent
15a8b981e0
commit
74d079d566
@ -296,8 +296,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||
&segments,
|
||||
Some(TypeNS),
|
||||
parent_scope,
|
||||
path.span,
|
||||
if speculative { CrateLint::No } else { CrateLint::SimplePath(id) },
|
||||
if speculative { CrateLint::No } else { CrateLint::SimplePath(id, path.span) },
|
||||
) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
|
||||
let res = module.res().expect("visibility resolved to unnamed block");
|
||||
@ -1130,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);
|
||||
|
@ -1076,9 +1076,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 +1404,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 +1419,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, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
|
||||
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
|
||||
}
|
||||
@ -1440,13 +1438,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, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
|
||||
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result {
|
||||
Some((
|
||||
@ -1472,13 +1469,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, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
|
||||
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
|
||||
}
|
||||
@ -1495,7 +1491,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 +1508,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, span, CrateLint::No);
|
||||
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
|
||||
debug!(
|
||||
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
|
||||
name, path, result
|
||||
|
@ -175,8 +175,7 @@ impl<'a> Resolver<'a> {
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
record_used: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_unadjusted_ext(
|
||||
module,
|
||||
@ -185,7 +184,6 @@ impl<'a> Resolver<'a> {
|
||||
parent_scope,
|
||||
false,
|
||||
record_used,
|
||||
path_span,
|
||||
)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
@ -199,8 +197,7 @@ impl<'a> Resolver<'a> {
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
restricted_shadowing: bool,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
record_used: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let module = match module {
|
||||
ModuleOrUniformRoot::Module(module) => module,
|
||||
@ -211,8 +208,7 @@ impl<'a> Resolver<'a> {
|
||||
ScopeSet::AbsolutePath(ns),
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
record_used.is_some(),
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
@ -220,7 +216,8 @@ 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, record_used.is_none())
|
||||
{
|
||||
Ok(binding)
|
||||
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
|
||||
// Macro-expanded `extern crate` items can add names to extern prelude.
|
||||
@ -251,8 +248,7 @@ impl<'a> Resolver<'a> {
|
||||
scopes,
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
record_used.is_some(),
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
@ -262,7 +258,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) = record_used {
|
||||
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));
|
||||
@ -280,7 +276,7 @@ impl<'a> Resolver<'a> {
|
||||
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
|
||||
};
|
||||
|
||||
if record_used {
|
||||
if let Some(path_span) = record_used {
|
||||
return resolution
|
||||
.binding
|
||||
.and_then(|binding| {
|
||||
@ -353,14 +349,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) =>
|
||||
@ -434,8 +424,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ns,
|
||||
adjusted_parent_scope,
|
||||
false,
|
||||
path_span,
|
||||
None,
|
||||
);
|
||||
|
||||
match result {
|
||||
@ -783,13 +772,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,
|
||||
import.span,
|
||||
CrateLint::No,
|
||||
);
|
||||
let path_res =
|
||||
self.r.resolve_path(&import.module_path, None, &import.parent_scope, CrateLint::No);
|
||||
import.vis.set(orig_vis);
|
||||
|
||||
match path_res {
|
||||
@ -828,8 +812,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);
|
||||
@ -882,15 +865,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||
_ => None,
|
||||
};
|
||||
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
|
||||
let crate_lint =
|
||||
CrateLint::UsePath { root_id: import.root_id, root_span: import.root_span };
|
||||
let path_res = self.r.resolve_path(
|
||||
&import.module_path,
|
||||
None,
|
||||
&import.parent_scope,
|
||||
import.span,
|
||||
crate_lint,
|
||||
);
|
||||
let crate_lint = CrateLint::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, crate_lint);
|
||||
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;
|
||||
@ -977,12 +958,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(
|
||||
crate_lint,
|
||||
&full_path,
|
||||
import.span,
|
||||
None,
|
||||
);
|
||||
self.r.lint_if_path_starts_with_module(crate_lint, &full_path, None);
|
||||
}
|
||||
|
||||
if let ModuleOrUniformRoot::Module(module) = module {
|
||||
@ -1020,8 +996,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;
|
||||
@ -1082,8 +1057,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;
|
||||
@ -1249,12 +1223,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(
|
||||
crate_lint,
|
||||
&full_path,
|
||||
import.span,
|
||||
Some(binding),
|
||||
);
|
||||
this.lint_if_path_starts_with_module(crate_lint, &full_path, Some(binding));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1310,9 +1279,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(
|
||||
|
@ -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,
|
||||
CrateLint::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,
|
||||
CrateLint::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,
|
||||
crate_lint: CrateLint,
|
||||
) -> Option<LexicalScopeBinding<'a>> {
|
||||
self.r.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ns,
|
||||
&self.parent_scope,
|
||||
record_used_id,
|
||||
path_span,
|
||||
crate_lint,
|
||||
&self.ribs[ns],
|
||||
)
|
||||
}
|
||||
@ -768,14 +769,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
&mut self,
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
) -> PathResult<'a> {
|
||||
self.r.resolve_path_with_ribs(
|
||||
path,
|
||||
opt_ns,
|
||||
&self.parent_scope,
|
||||
path_span,
|
||||
crate_lint,
|
||||
Some(&self.ribs),
|
||||
)
|
||||
@ -941,15 +940,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, CrateLint::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, CrateLint::No)
|
||||
{
|
||||
report_error(self, ns);
|
||||
}
|
||||
@ -1244,12 +1243,10 @@ 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),
|
||||
CrateLint::SimplePath(trait_ref.ref_id, trait_ref.path.span),
|
||||
);
|
||||
if let Some(def_id) = res.base_res().opt_def_id() {
|
||||
new_id = Some(def_id);
|
||||
@ -1691,7 +1688,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);
|
||||
@ -1802,7 +1799,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,
|
||||
@ -1812,7 +1808,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, CrateLint::No)?;
|
||||
let (res, binding) = match ls_binding {
|
||||
LexicalScopeBinding::Item(binding)
|
||||
if is_syntactic_ambiguity && binding.is_ambiguity() =>
|
||||
@ -1901,35 +1897,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),
|
||||
CrateLint::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,
|
||||
) -> PartialRes {
|
||||
tracing::debug!(
|
||||
"smart_resolve_path_fragment(id={:?}, qself={:?}, path={:?})",
|
||||
id,
|
||||
"smart_resolve_path_fragment(qself={:?}, path={:?}, crate_lint={:?})",
|
||||
qself,
|
||||
path
|
||||
path,
|
||||
crate_lint,
|
||||
);
|
||||
let ns = source.namespace();
|
||||
|
||||
let (id, path_span) =
|
||||
crate_lint.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();
|
||||
@ -1967,7 +1962,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();
|
||||
@ -2015,13 +2010,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
None
|
||||
};
|
||||
|
||||
assert_ne!(crate_lint, CrateLint::No);
|
||||
let partial_res = match self.resolve_qpath_anywhere(
|
||||
id,
|
||||
qself,
|
||||
path,
|
||||
ns,
|
||||
span,
|
||||
path_span,
|
||||
source.defer_to_typeck(),
|
||||
crate_lint,
|
||||
) {
|
||||
@ -2050,14 +2043,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), span, CrateLint::No)
|
||||
self.resolve_path(&std_path, Some(ns), CrateLint::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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2083,19 +2076,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,
|
||||
CrateLint::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, CrateLint::No);
|
||||
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false }
|
||||
}
|
||||
|
||||
@ -2117,7 +2109,6 @@ 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,
|
||||
@ -2129,7 +2120,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
|
||||
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, crate_lint)? {
|
||||
Some(partial_res)
|
||||
if partial_res.unresolved_segments() == 0 || defer_to_typeck =>
|
||||
{
|
||||
@ -2162,16 +2153,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,
|
||||
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
|
||||
debug!(
|
||||
"resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})",
|
||||
id, qself, path, ns, span,
|
||||
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, crate_lint={:?})",
|
||||
qself, path, ns, crate_lint,
|
||||
);
|
||||
|
||||
if let Some(qself) = qself {
|
||||
@ -2201,12 +2190,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
// contains the full span (the `CrateLint::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 },
|
||||
crate_lint.node_id_and_path_span().map_or(
|
||||
CrateLint::No,
|
||||
|(qpath_id, path_span)| CrateLint::QPathTrait {
|
||||
qpath_id,
|
||||
qpath_span: qself.path_span,
|
||||
path_span,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// The remaining segments (the `C` in our example) will
|
||||
@ -2218,7 +2212,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
)));
|
||||
}
|
||||
|
||||
let result = match self.resolve_path(&path, Some(ns), span, crate_lint) {
|
||||
let result = match self.resolve_path(&path, Some(ns), crate_lint) {
|
||||
PathResult::NonModule(path_res) => path_res,
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
|
||||
PartialRes::new(module.res().unwrap())
|
||||
@ -2256,9 +2250,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)) = crate_lint.node_id_and_path_span()
|
||||
{
|
||||
let unqualified_result = {
|
||||
match self.resolve_path(&[*path.last().unwrap()], Some(ns), span, CrateLint::No) {
|
||||
match self.resolve_path(&[*path.last().unwrap()], Some(ns), CrateLint::No) {
|
||||
PathResult::NonModule(path_res) => path_res.base_res(),
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
|
||||
module.res().unwrap()
|
||||
@ -2268,7 +2263,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")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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), 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), CrateLint::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, span, CrateLint::No)
|
||||
self.resolve_path(mod_path, None, CrateLint::No)
|
||||
{
|
||||
let resolutions = self.r.resolutions(module).borrow();
|
||||
let targets: Vec<_> =
|
||||
@ -699,7 +697,6 @@ 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,
|
||||
@ -724,7 +721,6 @@ 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,
|
||||
@ -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), span, CrateLint::No)
|
||||
self.resolve_path(mod_path, Some(TypeNS), CrateLint::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;
|
||||
@ -1949,8 +1950,7 @@ impl<'a> Resolver<'a> {
|
||||
mut ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used_id: Option<NodeId>,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
ribs: &[Rib<'a>],
|
||||
) -> Option<LexicalScopeBinding<'a>> {
|
||||
assert!(ns == TypeNS || ns == ValueNS);
|
||||
@ -1972,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 record_used = crate_lint.path_span();
|
||||
let mut module = self.graph_root;
|
||||
for i in (0..ribs.len()).rev() {
|
||||
debug!("walk rib\n{:?}", ribs[i].bindings);
|
||||
@ -1987,7 +1987,6 @@ impl<'a> Resolver<'a> {
|
||||
rib_ident,
|
||||
*res,
|
||||
record_used,
|
||||
path_span,
|
||||
*original_rib_ident_def,
|
||||
ribs,
|
||||
)));
|
||||
@ -2015,7 +2014,6 @@ impl<'a> Resolver<'a> {
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
);
|
||||
if let Ok(binding) = item {
|
||||
// The ident resolves to an item.
|
||||
@ -2024,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, crate_lint.node_id()),
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
record_used.is_some(),
|
||||
)
|
||||
.ok()
|
||||
.map(LexicalScopeBinding::Item)
|
||||
@ -2088,10 +2085,9 @@ impl<'a> Resolver<'a> {
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
record_used: 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, record_used)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
||||
@ -2101,8 +2097,7 @@ impl<'a> Resolver<'a> {
|
||||
mut ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
path_span: Span,
|
||||
record_used: Option<Span>,
|
||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let tmp_parent_scope;
|
||||
let mut adjusted_parent_scope = parent_scope;
|
||||
@ -2128,7 +2123,6 @@ impl<'a> Resolver<'a> {
|
||||
adjusted_parent_scope,
|
||||
false,
|
||||
record_used,
|
||||
path_span,
|
||||
)
|
||||
}
|
||||
|
||||
@ -2219,10 +2213,9 @@ impl<'a> Resolver<'a> {
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'a>,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
) -> PathResult<'a> {
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, path_span, crate_lint, None)
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, crate_lint, None)
|
||||
}
|
||||
|
||||
fn resolve_path_with_ribs(
|
||||
@ -2230,24 +2223,20 @@ impl<'a> Resolver<'a> {
|
||||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'a>,
|
||||
path_span: Span,
|
||||
crate_lint: CrateLint,
|
||||
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
|
||||
) -> PathResult<'a> {
|
||||
let record_used = crate_lint != CrateLint::No;
|
||||
debug!("resolve_path(path={:?}, opt_ns={:?}, crate_lint={:?})", path, opt_ns, crate_lint);
|
||||
|
||||
let record_used = crate_lint.path_span();
|
||||
let mut module = None;
|
||||
let mut allow_super = true;
|
||||
let mut second_binding = None;
|
||||
|
||||
debug!(
|
||||
"resolve_path(path={:?}, opt_ns={:?}, path_span={:?}, crate_lint={:?})",
|
||||
path, opt_ns, 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 record_used.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");
|
||||
@ -2281,7 +2270,7 @@ impl<'a> Resolver<'a> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return PathResult::failed(ident.span, false, record_used, || {
|
||||
return PathResult::failed(ident.span, false, record_used.is_some(), || {
|
||||
("there are too many leading `super` keywords".to_string(), None)
|
||||
});
|
||||
}
|
||||
@ -2312,7 +2301,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// Report special messages for path segment keywords in wrong positions.
|
||||
if ident.is_path_segment_keyword() && i != 0 {
|
||||
return PathResult::failed(ident.span, false, record_used, || {
|
||||
return PathResult::failed(ident.span, false, record_used.is_some(), || {
|
||||
let name_str = if name == kw::PathRoot {
|
||||
"crate root".to_string()
|
||||
} else {
|
||||
@ -2333,14 +2322,7 @@ 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, record_used)
|
||||
} 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(
|
||||
@ -2348,16 +2330,14 @@ impl<'a> Resolver<'a> {
|
||||
scopes,
|
||||
parent_scope,
|
||||
record_used,
|
||||
record_used,
|
||||
path_span,
|
||||
record_used.is_some(),
|
||||
)
|
||||
} else {
|
||||
match this.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
crate_lint.node_id(),
|
||||
path_span,
|
||||
crate_lint,
|
||||
&ribs.unwrap()[ns],
|
||||
) {
|
||||
// we found a locally-imported or available item/module
|
||||
@ -2371,7 +2351,7 @@ impl<'a> Resolver<'a> {
|
||||
PartialRes::with_unresolved_segments(res, path.len() - 1),
|
||||
));
|
||||
}
|
||||
_ => Err(Determinacy::determined(record_used)),
|
||||
_ => Err(Determinacy::determined(record_used.is_some())),
|
||||
}
|
||||
};
|
||||
FindBindingResult::Binding(binding)
|
||||
@ -2405,25 +2385,25 @@ 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(crate_lint, path, second_binding);
|
||||
return PathResult::NonModule(PartialRes::with_unresolved_segments(
|
||||
res,
|
||||
path.len() - i - 1,
|
||||
));
|
||||
} else {
|
||||
return PathResult::failed(ident.span, is_last, record_used, || {
|
||||
let label = format!(
|
||||
"`{ident}` is {} {}, not a module",
|
||||
res.article(),
|
||||
res.descr()
|
||||
);
|
||||
(label, None)
|
||||
});
|
||||
return PathResult::failed(
|
||||
ident.span,
|
||||
is_last,
|
||||
record_used.is_some(),
|
||||
|| {
|
||||
let label = format!(
|
||||
"`{ident}` is {} {}, not a module",
|
||||
res.article(),
|
||||
res.descr()
|
||||
);
|
||||
(label, None)
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(Undetermined) => return PathResult::Indeterminate,
|
||||
@ -2437,7 +2417,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
return PathResult::failed(ident.span, is_last, record_used, || {
|
||||
return PathResult::failed(ident.span, is_last, record_used.is_some(), || {
|
||||
let module_res = match module {
|
||||
Some(ModuleOrUniformRoot::Module(module)) => module.res(),
|
||||
_ => None,
|
||||
@ -2477,8 +2457,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ValueNS,
|
||||
parent_scope,
|
||||
None,
|
||||
path_span,
|
||||
CrateLint::No,
|
||||
&ribs.unwrap()[ValueNS],
|
||||
) {
|
||||
// Name matches a local variable. For example:
|
||||
@ -2603,12 +2582,12 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
self.lint_if_path_starts_with_module(crate_lint, path, path_span, second_binding);
|
||||
self.lint_if_path_starts_with_module(crate_lint, 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),
|
||||
})
|
||||
}
|
||||
|
||||
@ -2616,14 +2595,13 @@ impl<'a> Resolver<'a> {
|
||||
&mut self,
|
||||
crate_lint: CrateLint,
|
||||
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),
|
||||
CrateLint::SimplePath(id, path_span) => (id, path_span),
|
||||
CrateLint::UsePath { root_id, root_span, .. } => (root_id, root_span),
|
||||
CrateLint::QPathTrait { qpath_id, qpath_span, .. } => (qpath_id, qpath_span),
|
||||
};
|
||||
|
||||
let first_name = match path.get(0) {
|
||||
@ -2678,8 +2656,7 @@ impl<'a> Resolver<'a> {
|
||||
rib_index: usize,
|
||||
rib_ident: Ident,
|
||||
mut res: Res,
|
||||
record_used: bool,
|
||||
span: Span,
|
||||
record_used: Option<Span>,
|
||||
original_rib_ident_def: Ident,
|
||||
all_ribs: &[Rib<'a>],
|
||||
) -> Res {
|
||||
@ -2689,7 +2666,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) = record_used {
|
||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||
ResolutionError::SelfInGenericParamDefault
|
||||
} else {
|
||||
@ -2719,17 +2696,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) = record_used {
|
||||
// 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) = record_used {
|
||||
let (span, resolution_error) =
|
||||
if let Some((ident, constant_item_kind)) = item {
|
||||
let kind_str = match constant_item_kind {
|
||||
@ -2757,14 +2734,14 @@ impl<'a> Resolver<'a> {
|
||||
return Res::Err;
|
||||
}
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = record_used {
|
||||
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;
|
||||
}
|
||||
@ -2792,7 +2769,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) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
@ -2800,9 +2777,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;
|
||||
}
|
||||
}
|
||||
@ -2814,7 +2791,7 @@ impl<'a> Resolver<'a> {
|
||||
ItemRibKind(has_generic_params) => has_generic_params,
|
||||
FnItemRibKind => HasGenericParams::Yes,
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam(rib_ident.name),
|
||||
@ -2824,7 +2801,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
};
|
||||
|
||||
if record_used {
|
||||
if let Some(span) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::GenericParamsFromOuterFunction(
|
||||
@ -2858,7 +2835,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) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
@ -2866,9 +2843,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;
|
||||
}
|
||||
|
||||
@ -2878,7 +2855,7 @@ impl<'a> Resolver<'a> {
|
||||
ItemRibKind(has_generic_params) => has_generic_params,
|
||||
FnItemRibKind => HasGenericParams::Yes,
|
||||
ConstParamTyRibKind => {
|
||||
if record_used {
|
||||
if let Some(span) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInTyOfConstParam(rib_ident.name),
|
||||
@ -2889,7 +2866,7 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
|
||||
// This was an attempt to use a const parameter outside its scope.
|
||||
if record_used {
|
||||
if let Some(span) = record_used {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::GenericParamsFromOuterFunction(
|
||||
@ -3330,7 +3307,6 @@ impl<'a> Resolver<'a> {
|
||||
&segments,
|
||||
Some(ns),
|
||||
&ParentScope::module(module, self),
|
||||
DUMMY_SP,
|
||||
CrateLint::No,
|
||||
) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
|
||||
@ -3425,8 +3401,7 @@ impl<'a> Resolver<'a> {
|
||||
ident,
|
||||
ValueNS,
|
||||
parent_scope,
|
||||
false,
|
||||
DUMMY_SP,
|
||||
None
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
@ -3490,29 +3465,37 @@ enum CrateLint {
|
||||
|
||||
/// 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> {
|
||||
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),
|
||||
CrateLint::SimplePath(id, path_span)
|
||||
| CrateLint::UsePath { root_id: id, path_span, .. }
|
||||
| CrateLint::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) {
|
||||
|
@ -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, span, CrateLint::No) {
|
||||
match self.resolve_path(path, Some(ns), &parent_scope, CrateLint::No) {
|
||||
PathResult::Module(ModuleOrUniformRoot::Module(_)) => return Ok(true),
|
||||
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
|
||||
return Ok(true);
|
||||
@ -575,13 +575,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
let res = if path.len() > 1 {
|
||||
let res = match self.resolve_path(
|
||||
&path,
|
||||
Some(MacroNS),
|
||||
parent_scope,
|
||||
path_span,
|
||||
CrateLint::No,
|
||||
) {
|
||||
let res = match self.resolve_path(&path, Some(MacroNS), parent_scope, CrateLint::No) {
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
Ok(path_res.base_res())
|
||||
}
|
||||
@ -611,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);
|
||||
@ -647,9 +640,8 @@ impl<'a> Resolver<'a> {
|
||||
orig_ident: Ident,
|
||||
scope_set: ScopeSet<'a>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
record_used: bool,
|
||||
record_used: Option<Span>,
|
||||
force: bool,
|
||||
path_span: Span,
|
||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||
bitflags::bitflags! {
|
||||
struct Flags: u8 {
|
||||
@ -661,7 +653,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
assert!(force || !record_used); // `record_used` implies `force`
|
||||
assert!(force || !record_used.is_some()); // `record_used` implies `force`
|
||||
|
||||
// Make sure `self`, `super` etc produce an error when passed to here.
|
||||
if orig_ident.is_path_segment_keyword() {
|
||||
@ -769,7 +761,6 @@ impl<'a> Resolver<'a> {
|
||||
ns,
|
||||
parent_scope,
|
||||
record_used,
|
||||
path_span,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
|
||||
@ -791,7 +782,6 @@ impl<'a> Resolver<'a> {
|
||||
adjusted_parent_scope,
|
||||
!matches!(scope_set, ScopeSet::Late(..)),
|
||||
record_used,
|
||||
path_span,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => {
|
||||
@ -855,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, record_used.is_none()) {
|
||||
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),
|
||||
@ -873,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));
|
||||
@ -893,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 record_used.is_none() || matches!(scope_set, ScopeSet::Late(..)) {
|
||||
return Some(Ok(binding));
|
||||
}
|
||||
|
||||
@ -1032,8 +1023,7 @@ impl<'a> Resolver<'a> {
|
||||
&path,
|
||||
Some(MacroNS),
|
||||
&parent_scope,
|
||||
path_span,
|
||||
CrateLint::SimplePath(ast::CRATE_NODE_ID),
|
||||
CrateLint::SimplePath(ast::CRATE_NODE_ID, path_span),
|
||||
) {
|
||||
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
|
||||
let res = path_res.base_res();
|
||||
@ -1067,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| {
|
||||
@ -1109,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++");
|
||||
|
Loading…
Reference in New Issue
Block a user