1
Fork 0

resolve: Stop passing unused spans and node ids to path resolution functions

This commit is contained in:
Vadim Petrochenkov 2022-03-24 00:32:00 +03:00
parent 15a8b981e0
commit 74d079d566
8 changed files with 189 additions and 268 deletions

View file

@ -296,8 +296,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
&segments, &segments,
Some(TypeNS), Some(TypeNS),
parent_scope, parent_scope,
path.span, if speculative { CrateLint::No } else { CrateLint::SimplePath(id, path.span) },
if speculative { CrateLint::No } else { CrateLint::SimplePath(id) },
) { ) {
PathResult::Module(ModuleOrUniformRoot::Module(module)) => { PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
let res = module.res().expect("visibility resolved to unnamed block"); let res = module.res().expect("visibility resolved to unnamed block");
@ -1130,8 +1129,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
ident, ident,
MacroNS, MacroNS,
&self.parent_scope, &self.parent_scope,
false, None,
ident.span,
); );
if let Ok(binding) = result { if let Ok(binding) = result {
let import = macro_use_import(self, ident.span); let import = macro_use_import(self, ident.span);

View file

@ -1076,9 +1076,8 @@ impl<'a> Resolver<'a> {
ident, ident,
ScopeSet::All(ns, false), ScopeSet::All(ns, false),
&parent_scope, &parent_scope,
None,
false, false,
false,
ident.span,
) { ) {
let desc = match binding.res() { let desc = match binding.res() {
Res::Def(DefKind::Macro(MacroKind::Bang), _) => { Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
@ -1405,10 +1404,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
_ => return None, _ => return None,
} }
self.make_missing_self_suggestion(span, path.clone(), parent_scope) self.make_missing_self_suggestion(path.clone(), parent_scope)
.or_else(|| self.make_missing_crate_suggestion(span, path.clone(), parent_scope)) .or_else(|| self.make_missing_crate_suggestion(path.clone(), parent_scope))
.or_else(|| self.make_missing_super_suggestion(span, path.clone(), parent_scope)) .or_else(|| self.make_missing_super_suggestion(path.clone(), parent_scope))
.or_else(|| self.make_external_crate_suggestion(span, path, parent_scope)) .or_else(|| self.make_external_crate_suggestion(path, parent_scope))
} }
/// Suggest a missing `self::` if that resolves to an correct module. /// 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( fn make_missing_self_suggestion(
&mut self, &mut self,
span: Span,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Vec<String>)> {
// Replace first ident with `self` and check if that is valid. // Replace first ident with `self` and check if that is valid.
path[0].ident.name = kw::SelfLower; 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); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } 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( fn make_missing_crate_suggestion(
&mut self, &mut self,
span: Span,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Vec<String>)> {
// Replace first ident with `crate` and check if that is valid. // Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Crate; 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); debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { if let PathResult::Module(..) = result {
Some(( Some((
@ -1472,13 +1469,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
/// ``` /// ```
fn make_missing_super_suggestion( fn make_missing_super_suggestion(
&mut self, &mut self,
span: Span,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Vec<String>)> {
// Replace first ident with `crate` and check if that is valid. // Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Super; 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); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } 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. /// name as the first part of path.
fn make_external_crate_suggestion( fn make_external_crate_suggestion(
&mut self, &mut self,
span: Span,
mut path: Vec<Segment>, mut path: Vec<Segment>,
parent_scope: &ParentScope<'b>, parent_scope: &ParentScope<'b>,
) -> Option<(Vec<Segment>, Vec<String>)> { ) -> Option<(Vec<Segment>, Vec<String>)> {
@ -1513,7 +1508,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
for name in extern_crate_names.into_iter() { for name in extern_crate_names.into_iter() {
// Replace first ident with a crate name and check if that is valid. // Replace first ident with a crate name and check if that is valid.
path[0].ident.name = name; 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!( debug!(
"make_external_crate_suggestion: name={:?} path={:?} result={:?}", "make_external_crate_suggestion: name={:?} path={:?} result={:?}",
name, path, result name, path, result

View file

@ -175,8 +175,7 @@ impl<'a> Resolver<'a> {
ident: Ident, ident: Ident,
ns: Namespace, ns: Namespace,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
record_used: bool, record_used: Option<Span>,
path_span: Span,
) -> Result<&'a NameBinding<'a>, Determinacy> { ) -> Result<&'a NameBinding<'a>, Determinacy> {
self.resolve_ident_in_module_unadjusted_ext( self.resolve_ident_in_module_unadjusted_ext(
module, module,
@ -185,7 +184,6 @@ impl<'a> Resolver<'a> {
parent_scope, parent_scope,
false, false,
record_used, record_used,
path_span,
) )
.map_err(|(determinacy, _)| determinacy) .map_err(|(determinacy, _)| determinacy)
} }
@ -199,8 +197,7 @@ impl<'a> Resolver<'a> {
ns: Namespace, ns: Namespace,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
restricted_shadowing: bool, restricted_shadowing: bool,
record_used: bool, record_used: Option<Span>,
path_span: Span,
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
let module = match module { let module = match module {
ModuleOrUniformRoot::Module(module) => module, ModuleOrUniformRoot::Module(module) => module,
@ -211,8 +208,7 @@ impl<'a> Resolver<'a> {
ScopeSet::AbsolutePath(ns), ScopeSet::AbsolutePath(ns),
parent_scope, parent_scope,
record_used, record_used,
record_used, record_used.is_some(),
path_span,
); );
return binding.map_err(|determinacy| (determinacy, Weak::No)); return binding.map_err(|determinacy| (determinacy, Weak::No));
} }
@ -220,7 +216,8 @@ impl<'a> Resolver<'a> {
assert!(!restricted_shadowing); assert!(!restricted_shadowing);
return if ns != TypeNS { return if ns != TypeNS {
Err((Determined, Weak::No)) 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) Ok(binding)
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() { } else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
// Macro-expanded `extern crate` items can add names to extern prelude. // Macro-expanded `extern crate` items can add names to extern prelude.
@ -251,8 +248,7 @@ impl<'a> Resolver<'a> {
scopes, scopes,
parent_scope, parent_scope,
record_used, record_used,
record_used, record_used.is_some(),
path_span,
); );
return binding.map_err(|determinacy| (determinacy, Weak::No)); return binding.map_err(|determinacy| (determinacy, Weak::No));
} }
@ -262,7 +258,7 @@ impl<'a> Resolver<'a> {
let resolution = let resolution =
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. 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 !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
if let NameBindingKind::Res(_, true) = binding.kind { if let NameBindingKind::Res(_, true) = binding.kind {
self.macro_expanded_macro_export_errors.insert((path_span, binding.span)); 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 usable { Ok(binding) } else { Err((Determined, Weak::No)) }
}; };
if record_used { if let Some(path_span) = record_used {
return resolution return resolution
.binding .binding
.and_then(|binding| { .and_then(|binding| {
@ -353,14 +349,8 @@ impl<'a> Resolver<'a> {
let ImportKind::Single { source: ident, .. } = single_import.kind else { let ImportKind::Single { source: ident, .. } = single_import.kind else {
unreachable!(); unreachable!();
}; };
match self.resolve_ident_in_module( match self.resolve_ident_in_module(module, ident, ns, &single_import.parent_scope, None)
module, {
ident,
ns,
&single_import.parent_scope,
false,
path_span,
) {
Err(Determined) => continue, Err(Determined) => continue,
Ok(binding) Ok(binding)
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) => if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
@ -434,8 +424,7 @@ impl<'a> Resolver<'a> {
ident, ident,
ns, ns,
adjusted_parent_scope, adjusted_parent_scope,
false, None,
path_span,
); );
match result { match result {
@ -783,13 +772,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
// For better failure detection, pretend that the import will // For better failure detection, pretend that the import will
// not define any names while resolving its module path. // not define any names while resolving its module path.
let orig_vis = import.vis.replace(ty::Visibility::Invisible); let orig_vis = import.vis.replace(ty::Visibility::Invisible);
let path_res = self.r.resolve_path( let path_res =
&import.module_path, self.r.resolve_path(&import.module_path, None, &import.parent_scope, CrateLint::No);
None,
&import.parent_scope,
import.span,
CrateLint::No,
);
import.vis.set(orig_vis); import.vis.set(orig_vis);
match path_res { match path_res {
@ -828,8 +812,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
source, source,
ns, ns,
&import.parent_scope, &import.parent_scope,
false, None,
import.span,
); );
import.vis.set(orig_vis); import.vis.set(orig_vis);
source_bindings[ns].set(binding); source_bindings[ns].set(binding);
@ -882,15 +865,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
_ => None, _ => None,
}; };
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len(); let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
let crate_lint = let crate_lint = CrateLint::UsePath {
CrateLint::UsePath { root_id: import.root_id, root_span: import.root_span }; root_id: import.root_id,
let path_res = self.r.resolve_path( root_span: import.root_span,
&import.module_path, path_span: import.span,
None, };
&import.parent_scope, let path_res =
import.span, self.r.resolve_path(&import.module_path, None, &import.parent_scope, crate_lint);
crate_lint,
);
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len; let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
if let Some(orig_unusable_binding) = orig_unusable_binding { if let Some(orig_unusable_binding) = orig_unusable_binding {
self.r.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. // 2 segments, so the `resolve_path` above won't trigger it.
let mut full_path = import.module_path.clone(); let mut full_path = import.module_path.clone();
full_path.push(Segment::from_ident(Ident::empty())); full_path.push(Segment::from_ident(Ident::empty()));
self.r.lint_if_path_starts_with_module( self.r.lint_if_path_starts_with_module(crate_lint, &full_path, None);
crate_lint,
&full_path,
import.span,
None,
);
} }
if let ModuleOrUniformRoot::Module(module) = module { if let ModuleOrUniformRoot::Module(module) = module {
@ -1020,8 +996,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
ident, ident,
ns, ns,
&import.parent_scope, &import.parent_scope,
true, Some(import.span),
import.span,
); );
this.last_import_segment = orig_last_import_segment; this.last_import_segment = orig_last_import_segment;
this.unusable_binding = orig_unusable_binding; this.unusable_binding = orig_unusable_binding;
@ -1082,8 +1057,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
ident, ident,
ns, ns,
&import.parent_scope, &import.parent_scope,
true, Some(import.span),
import.span,
); );
if binding.is_ok() { if binding.is_ok() {
all_ns_failed = false; all_ns_failed = false;
@ -1249,12 +1223,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
full_path.push(Segment::from_ident(ident)); full_path.push(Segment::from_ident(ident));
self.r.per_ns(|this, ns| { self.r.per_ns(|this, ns| {
if let Ok(binding) = source_bindings[ns].get() { if let Ok(binding) = source_bindings[ns].get() {
this.lint_if_path_starts_with_module( this.lint_if_path_starts_with_module(crate_lint, &full_path, Some(binding));
crate_lint,
&full_path,
import.span,
Some(binding),
);
} }
}); });
} }
@ -1310,9 +1279,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
target, target,
ScopeSet::All(ns, false), ScopeSet::All(ns, false),
&import.parent_scope, &import.parent_scope,
None,
false, false,
false,
import.span,
) { ) {
Ok(other_binding) => { Ok(other_binding) => {
is_redundant[ns] = Some( is_redundant[ns] = Some(

View file

@ -483,7 +483,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
TyKind::ImplicitSelf => { TyKind::ImplicitSelf => {
let self_ty = Ident::with_dummy_span(kw::SelfUpper); let self_ty = Ident::with_dummy_span(kw::SelfUpper);
let res = self 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()); .map_or(Res::Err, |d| d.res());
self.r.record_partial_res(ty.id, PartialRes::new(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( self.resolve_ident_in_lexical_scope(
path.segments[0].ident, path.segments[0].ident,
ns, ns,
None, CrateLint::No,
path.span,
) )
.is_some() .is_some()
}; };
@ -751,15 +754,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
&mut self, &mut self,
ident: Ident, ident: Ident,
ns: Namespace, ns: Namespace,
record_used_id: Option<NodeId>, crate_lint: CrateLint,
path_span: Span,
) -> Option<LexicalScopeBinding<'a>> { ) -> Option<LexicalScopeBinding<'a>> {
self.r.resolve_ident_in_lexical_scope( self.r.resolve_ident_in_lexical_scope(
ident, ident,
ns, ns,
&self.parent_scope, &self.parent_scope,
record_used_id, crate_lint,
path_span,
&self.ribs[ns], &self.ribs[ns],
) )
} }
@ -768,14 +769,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
&mut self, &mut self,
path: &[Segment], path: &[Segment],
opt_ns: Option<Namespace>, // `None` indicates a module path in import opt_ns: Option<Namespace>, // `None` indicates a module path in import
path_span: Span,
crate_lint: CrateLint, crate_lint: CrateLint,
) -> PathResult<'a> { ) -> PathResult<'a> {
self.r.resolve_path_with_ribs( self.r.resolve_path_with_ribs(
path, path,
opt_ns, opt_ns,
&self.parent_scope, &self.parent_scope,
path_span,
crate_lint, crate_lint,
Some(&self.ribs), Some(&self.ribs),
) )
@ -941,15 +940,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}; };
for &ns in nss { 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(..)) => { Some(LexicalScopeBinding::Res(..)) => {
report_error(self, ns); report_error(self, ns);
} }
Some(LexicalScopeBinding::Item(binding)) => { Some(LexicalScopeBinding::Item(binding)) => {
let orig_unusable_binding = let orig_unusable_binding =
replace(&mut self.r.unusable_binding, Some(binding)); replace(&mut self.r.unusable_binding, Some(binding));
if let Some(LexicalScopeBinding::Res(..)) = self if let Some(LexicalScopeBinding::Res(..)) =
.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) self.resolve_ident_in_lexical_scope(ident, ns, CrateLint::No)
{ {
report_error(self, ns); 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 { if let Some(trait_ref) = opt_trait_ref {
let path: Vec<_> = Segment::from_path(&trait_ref.path); let path: Vec<_> = Segment::from_path(&trait_ref.path);
let res = self.smart_resolve_path_fragment( let res = self.smart_resolve_path_fragment(
trait_ref.ref_id,
None, None,
&path, &path,
trait_ref.path.span,
PathSource::Trait(AliasPossibility::No), 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() { if let Some(def_id) = res.base_res().opt_def_id() {
new_id = Some(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. // then fall back to a fresh binding.
let has_sub = sub.is_some(); let has_sub = sub.is_some();
let res = self 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)); .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_partial_res(pat.id, PartialRes::new(res));
self.r.record_pat_span(pat.id, pat.span); 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( fn try_resolve_as_non_binding(
&mut self, &mut self,
pat_src: PatternSource, pat_src: PatternSource,
pat: &Pat,
bm: BindingMode, bm: BindingMode,
ident: Ident, ident: Ident,
has_sub: bool, 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. // 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 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 { let (res, binding) = match ls_binding {
LexicalScopeBinding::Item(binding) LexicalScopeBinding::Item(binding)
if is_syntactic_ambiguity && binding.is_ambiguity() => if is_syntactic_ambiguity && binding.is_ambiguity() =>
@ -1901,35 +1897,34 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
source: PathSource<'ast>, source: PathSource<'ast>,
) { ) {
self.smart_resolve_path_fragment( self.smart_resolve_path_fragment(
id,
qself, qself,
&Segment::from_path(path), &Segment::from_path(path),
path.span,
source, source,
CrateLint::SimplePath(id), CrateLint::SimplePath(id, path.span),
); );
} }
fn smart_resolve_path_fragment( fn smart_resolve_path_fragment(
&mut self, &mut self,
id: NodeId,
qself: Option<&QSelf>, qself: Option<&QSelf>,
path: &[Segment], path: &[Segment],
span: Span,
source: PathSource<'ast>, source: PathSource<'ast>,
crate_lint: CrateLint, crate_lint: CrateLint,
) -> PartialRes { ) -> PartialRes {
tracing::debug!( tracing::debug!(
"smart_resolve_path_fragment(id={:?}, qself={:?}, path={:?})", "smart_resolve_path_fragment(qself={:?}, path={:?}, crate_lint={:?})",
id,
qself, qself,
path path,
crate_lint,
); );
let ns = source.namespace(); 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>| { let report_errors = |this: &mut Self, res: Option<Res>| {
if this.should_report_errs() { 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 def_id = this.parent_scope.module.nearest_parent_mod();
let instead = res.is_some(); let instead = res.is_some();
@ -1967,7 +1962,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}; };
let (mut err, candidates) = 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() { if candidates.is_empty() {
err.cancel(); err.cancel();
@ -2015,13 +2010,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
None None
}; };
assert_ne!(crate_lint, CrateLint::No);
let partial_res = match self.resolve_qpath_anywhere( let partial_res = match self.resolve_qpath_anywhere(
id,
qself, qself,
path, path,
ns, ns,
span, path_span,
source.defer_to_typeck(), source.defer_to_typeck(),
crate_lint, 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.push(Segment::from_ident(Ident::with_dummy_span(sym::std)));
std_path.extend(path); std_path.extend(path);
if let PathResult::Module(_) | PathResult::NonModule(_) = 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` // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
let item_span = 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(item_span, path_span);
self.r.confused_type_with_std_module.insert(span, 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 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( let binding = self.resolve_ident_in_lexical_scope(
Ident::with_dummy_span(kw::SelfUpper), Ident::with_dummy_span(kw::SelfUpper),
TypeNS, TypeNS,
None, CrateLint::No,
span,
); );
if let Some(LexicalScopeBinding::Res(res)) = binding { res != Res::Err } else { false } 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 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 } 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. // Resolve in alternative namespaces if resolution in the primary namespace fails.
fn resolve_qpath_anywhere( fn resolve_qpath_anywhere(
&mut self, &mut self,
id: NodeId,
qself: Option<&QSelf>, qself: Option<&QSelf>,
path: &[Segment], path: &[Segment],
primary_ns: Namespace, 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() { for (i, &ns) in [primary_ns, TypeNS, ValueNS].iter().enumerate() {
if i == 0 || ns != primary_ns { 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) Some(partial_res)
if partial_res.unresolved_segments() == 0 || defer_to_typeck => 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. /// Handles paths that may refer to associated items.
fn resolve_qpath( fn resolve_qpath(
&mut self, &mut self,
id: NodeId,
qself: Option<&QSelf>, qself: Option<&QSelf>,
path: &[Segment], path: &[Segment],
ns: Namespace, ns: Namespace,
span: Span,
crate_lint: CrateLint, crate_lint: CrateLint,
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> { ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
debug!( debug!(
"resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})", "resolve_qpath(qself={:?}, path={:?}, ns={:?}, crate_lint={:?})",
id, qself, path, ns, span, qself, path, ns, crate_lint,
); );
if let Some(qself) = qself { 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`). // contains the full span (the `CrateLint::QPathTrait`).
let ns = if qself.position + 1 == path.len() { ns } else { TypeNS }; let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
let partial_res = self.smart_resolve_path_fragment( let partial_res = self.smart_resolve_path_fragment(
id,
None, None,
&path[..=qself.position], &path[..=qself.position],
span,
PathSource::TraitItem(ns), 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 // 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::NonModule(path_res) => path_res,
PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => { PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
PartialRes::new(module.res().unwrap()) PartialRes::new(module.res().unwrap())
@ -2256,9 +2250,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
&& result.base_res() != Res::Err && result.base_res() != Res::Err
&& path[0].ident.name != kw::PathRoot && path[0].ident.name != kw::PathRoot
&& path[0].ident.name != kw::DollarCrate && path[0].ident.name != kw::DollarCrate
&& let Some((id, path_span)) = crate_lint.node_id_and_path_span()
{ {
let unqualified_result = { 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::NonModule(path_res) => path_res.base_res(),
PathResult::Module(ModuleOrUniformRoot::Module(module)) => { PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
module.res().unwrap() module.res().unwrap()
@ -2268,7 +2263,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}; };
if result.base_res() == unqualified_result { if result.base_res() == unqualified_result {
let lint = lint::builtin::UNUSED_QUALIFICATIONS; 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")
} }
} }

View file

@ -187,12 +187,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
(String::new(), "the crate root".to_string()) (String::new(), "the crate root".to_string())
} else { } else {
let mod_path = &path[..path.len() - 1]; let mod_path = &path[..path.len() - 1];
let mod_prefix = let mod_prefix = match self.resolve_path(mod_path, Some(TypeNS), CrateLint::No) {
match self.resolve_path(mod_path, Some(TypeNS), span, CrateLint::No) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(), _ => None,
_ => None, }
} .map_or_else(String::new, |res| format!("{} ", res.descr()));
.map_or_else(String::new, |res| format!("{} ", res.descr()));
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path))) (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). // 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 { if ["this", "my"].contains(&item_str.as_str()) && is_assoc_fn {
err.span_suggestion_short( err.span_suggestion_short(
@ -241,7 +240,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
"self".to_string(), "self".to_string(),
Applicability::MaybeIncorrect, 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)) = if let Some((FnKind::Fn(_, _, sig, ..), fn_span)) =
&self.diagnostic_metadata.current_function &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) { 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 { match candidate {
AssocSuggestion::Field => { AssocSuggestion::Field => {
if self_is_available { if self_is_available {
@ -461,7 +460,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
} }
// Try Levenshtein algorithm. // 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. // Try context-dependent help if relaxed lookup didn't work.
if let Some(res) = res { if let Some(res) = res {
if self.smart_resolve_context_dependent_help( 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 // 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); self.r.add_typo_suggestion(&mut err, suggestion, ident_span);
} }
if fallback { if fallback {
@ -641,14 +640,13 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
fn get_single_associated_item( fn get_single_associated_item(
&mut self, &mut self,
path: &[Segment], path: &[Segment],
span: Span,
source: &PathSource<'_>, source: &PathSource<'_>,
filter_fn: &impl Fn(Res) -> bool, filter_fn: &impl Fn(Res) -> bool,
) -> Option<TypoSuggestion> { ) -> Option<TypoSuggestion> {
if let crate::PathSource::TraitItem(_) = source { if let crate::PathSource::TraitItem(_) = source {
let mod_path = &path[..path.len() - 1]; let mod_path = &path[..path.len() - 1];
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = 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 resolutions = self.r.resolutions(module).borrow();
let targets: Vec<_> = let targets: Vec<_> =
@ -699,7 +697,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
{ {
// use this to verify that ident is a type param. // use this to verify that ident is a type param.
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere( let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
bounded_ty.id,
None, None,
&Segment::from_path(path), &Segment::from_path(path),
Namespace::TypeNS, 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 { if let ast::TyKind::Path(None, type_param_path) = &ty.peel_refs().kind {
// Confirm that the `SelfTy` is a type parameter. // Confirm that the `SelfTy` is a type parameter.
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere( let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
bounded_ty.id,
None, None,
&Segment::from_path(type_param_path), &Segment::from_path(type_param_path),
Namespace::TypeNS, Namespace::TypeNS,
@ -1292,8 +1288,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
ident, ident,
ns, ns,
&self.parent_scope, &self.parent_scope,
false, None,
module.span,
) { ) {
let res = binding.res(); let res = binding.res();
if filter_fn(res) { if filter_fn(res) {
@ -1323,7 +1318,6 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
path: &[Segment], path: &[Segment],
ns: Namespace, ns: Namespace,
filter_fn: &impl Fn(Res) -> bool, filter_fn: &impl Fn(Res) -> bool,
span: Span,
) -> Option<TypoSuggestion> { ) -> Option<TypoSuggestion> {
let mut names = Vec::new(); let mut names = Vec::new();
if path.len() == 1 { if path.len() == 1 {
@ -1384,7 +1378,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
// Search in module. // Search in module.
let mod_path = &path[..path.len() - 1]; let mod_path = &path[..path.len() - 1];
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = 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); self.r.add_module_candidates(module, &mut names, &filter_fn);
} }

View file

@ -13,6 +13,7 @@
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(let_chains)]
#![feature(let_else)] #![feature(let_else)]
#![feature(never_type)] #![feature(never_type)]
#![feature(nll)] #![feature(nll)]
@ -54,9 +55,9 @@ use rustc_index::vec::IndexVec;
use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_metadata::creader::{CStore, CrateLoader};
use rustc_middle::metadata::ModChild; use rustc_middle::metadata::ModChild;
use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::privacy::AccessLevels;
use rustc_middle::span_bug;
use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs}; use rustc_middle::ty::{self, DefIdTree, MainDefinition, RegisteredTools, ResolverOutputs};
use rustc_middle::{bug, span_bug};
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_session::cstore::{CrateStore, MetadataLoaderDyn}; use rustc_session::cstore::{CrateStore, MetadataLoaderDyn};
use rustc_session::lint; use rustc_session::lint;
@ -1949,8 +1950,7 @@ impl<'a> Resolver<'a> {
mut ident: Ident, mut ident: Ident,
ns: Namespace, ns: Namespace,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
record_used_id: Option<NodeId>, crate_lint: CrateLint,
path_span: Span,
ribs: &[Rib<'a>], ribs: &[Rib<'a>],
) -> Option<LexicalScopeBinding<'a>> { ) -> Option<LexicalScopeBinding<'a>> {
assert!(ns == TypeNS || ns == ValueNS); assert!(ns == TypeNS || ns == ValueNS);
@ -1972,7 +1972,7 @@ impl<'a> Resolver<'a> {
let normalized_ident = Ident { span: normalized_span, ..ident }; let normalized_ident = Ident { span: normalized_span, ..ident };
// Walk backwards up the ribs in scope. // 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; let mut module = self.graph_root;
for i in (0..ribs.len()).rev() { for i in (0..ribs.len()).rev() {
debug!("walk rib\n{:?}", ribs[i].bindings); debug!("walk rib\n{:?}", ribs[i].bindings);
@ -1987,7 +1987,6 @@ impl<'a> Resolver<'a> {
rib_ident, rib_ident,
*res, *res,
record_used, record_used,
path_span,
*original_rib_ident_def, *original_rib_ident_def,
ribs, ribs,
))); )));
@ -2015,7 +2014,6 @@ impl<'a> Resolver<'a> {
ns, ns,
parent_scope, parent_scope,
record_used, record_used,
path_span,
); );
if let Ok(binding) = item { if let Ok(binding) = item {
// The ident resolves to an item. // The ident resolves to an item.
@ -2024,11 +2022,10 @@ impl<'a> Resolver<'a> {
} }
self.early_resolve_ident_in_lexical_scope( self.early_resolve_ident_in_lexical_scope(
orig_ident, orig_ident,
ScopeSet::Late(ns, module, record_used_id), ScopeSet::Late(ns, module, crate_lint.node_id()),
parent_scope, parent_scope,
record_used, record_used,
record_used, record_used.is_some(),
path_span,
) )
.ok() .ok()
.map(LexicalScopeBinding::Item) .map(LexicalScopeBinding::Item)
@ -2088,10 +2085,9 @@ impl<'a> Resolver<'a> {
ident: Ident, ident: Ident,
ns: Namespace, ns: Namespace,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
record_used: bool, record_used: Option<Span>,
path_span: Span,
) -> Result<&'a NameBinding<'a>, Determinacy> { ) -> 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) .map_err(|(determinacy, _)| determinacy)
} }
@ -2101,8 +2097,7 @@ impl<'a> Resolver<'a> {
mut ident: Ident, mut ident: Ident,
ns: Namespace, ns: Namespace,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
record_used: bool, record_used: Option<Span>,
path_span: Span,
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
let tmp_parent_scope; let tmp_parent_scope;
let mut adjusted_parent_scope = parent_scope; let mut adjusted_parent_scope = parent_scope;
@ -2128,7 +2123,6 @@ impl<'a> Resolver<'a> {
adjusted_parent_scope, adjusted_parent_scope,
false, false,
record_used, record_used,
path_span,
) )
} }
@ -2219,10 +2213,9 @@ impl<'a> Resolver<'a> {
path: &[Segment], path: &[Segment],
opt_ns: Option<Namespace>, // `None` indicates a module path in import opt_ns: Option<Namespace>, // `None` indicates a module path in import
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
path_span: Span,
crate_lint: CrateLint, crate_lint: CrateLint,
) -> PathResult<'a> { ) -> 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( fn resolve_path_with_ribs(
@ -2230,24 +2223,20 @@ impl<'a> Resolver<'a> {
path: &[Segment], path: &[Segment],
opt_ns: Option<Namespace>, // `None` indicates a module path in import opt_ns: Option<Namespace>, // `None` indicates a module path in import
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
path_span: Span,
crate_lint: CrateLint, crate_lint: CrateLint,
ribs: Option<&PerNS<Vec<Rib<'a>>>>, ribs: Option<&PerNS<Vec<Rib<'a>>>>,
) -> PathResult<'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 module = None;
let mut allow_super = true; let mut allow_super = true;
let mut second_binding = None; 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() { for (i, &Segment { ident, id, has_generic_args: _ }) in path.iter().enumerate() {
debug!("resolve_path ident {} {:?} {:?}", i, ident, id); debug!("resolve_path ident {} {:?} {:?}", i, ident, id);
let record_segment_res = |this: &mut Self, res| { let record_segment_res = |this: &mut Self, res| {
if record_used { if record_used.is_some() {
if let Some(id) = id { if let Some(id) = id {
if !this.partial_res_map.contains_key(&id) { if !this.partial_res_map.contains_key(&id) {
assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id"); assert!(id != ast::DUMMY_NODE_ID, "Trying to resolve dummy id");
@ -2281,7 +2270,7 @@ impl<'a> Resolver<'a> {
continue; 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) ("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. // Report special messages for path segment keywords in wrong positions.
if ident.is_path_segment_keyword() && i != 0 { 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 { let name_str = if name == kw::PathRoot {
"crate root".to_string() "crate root".to_string()
} else { } else {
@ -2333,14 +2322,7 @@ impl<'a> Resolver<'a> {
} }
let find_binding_in_ns = |this: &mut Self, ns| { let find_binding_in_ns = |this: &mut Self, ns| {
let binding = if let Some(module) = module { let binding = if let Some(module) = module {
this.resolve_ident_in_module( this.resolve_ident_in_module(module, ident, ns, parent_scope, record_used)
module,
ident,
ns,
parent_scope,
record_used,
path_span,
)
} else if ribs.is_none() || opt_ns.is_none() || opt_ns == Some(MacroNS) { } else if ribs.is_none() || opt_ns.is_none() || opt_ns == Some(MacroNS) {
let scopes = ScopeSet::All(ns, opt_ns.is_none()); let scopes = ScopeSet::All(ns, opt_ns.is_none());
this.early_resolve_ident_in_lexical_scope( this.early_resolve_ident_in_lexical_scope(
@ -2348,16 +2330,14 @@ impl<'a> Resolver<'a> {
scopes, scopes,
parent_scope, parent_scope,
record_used, record_used,
record_used, record_used.is_some(),
path_span,
) )
} else { } else {
match this.resolve_ident_in_lexical_scope( match this.resolve_ident_in_lexical_scope(
ident, ident,
ns, ns,
parent_scope, parent_scope,
crate_lint.node_id(), crate_lint,
path_span,
&ribs.unwrap()[ns], &ribs.unwrap()[ns],
) { ) {
// we found a locally-imported or available item/module // 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), PartialRes::with_unresolved_segments(res, path.len() - 1),
)); ));
} }
_ => Err(Determinacy::determined(record_used)), _ => Err(Determinacy::determined(record_used.is_some())),
} }
}; };
FindBindingResult::Binding(binding) FindBindingResult::Binding(binding)
@ -2405,25 +2385,25 @@ impl<'a> Resolver<'a> {
} else if res == Res::Err { } else if res == Res::Err {
return PathResult::NonModule(PartialRes::new(Res::Err)); return PathResult::NonModule(PartialRes::new(Res::Err));
} else if opt_ns.is_some() && (is_last || maybe_assoc) { } else if opt_ns.is_some() && (is_last || maybe_assoc) {
self.lint_if_path_starts_with_module( self.lint_if_path_starts_with_module(crate_lint, path, second_binding);
crate_lint,
path,
path_span,
second_binding,
);
return PathResult::NonModule(PartialRes::with_unresolved_segments( return PathResult::NonModule(PartialRes::with_unresolved_segments(
res, res,
path.len() - i - 1, path.len() - i - 1,
)); ));
} else { } else {
return PathResult::failed(ident.span, is_last, record_used, || { return PathResult::failed(
let label = format!( ident.span,
"`{ident}` is {} {}, not a module", is_last,
res.article(), record_used.is_some(),
res.descr() || {
); let label = format!(
(label, None) "`{ident}` is {} {}, not a module",
}); res.article(),
res.descr()
);
(label, None)
},
);
} }
} }
Err(Undetermined) => return PathResult::Indeterminate, 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 { let module_res = match module {
Some(ModuleOrUniformRoot::Module(module)) => module.res(), Some(ModuleOrUniformRoot::Module(module)) => module.res(),
_ => None, _ => None,
@ -2477,8 +2457,7 @@ impl<'a> Resolver<'a> {
ident, ident,
ValueNS, ValueNS,
parent_scope, parent_scope,
None, CrateLint::No,
path_span,
&ribs.unwrap()[ValueNS], &ribs.unwrap()[ValueNS],
) { ) {
// Name matches a local variable. For example: // 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 { PathResult::Module(match module {
Some(module) => module, Some(module) => module,
None if path.is_empty() => ModuleOrUniformRoot::CurrentScope, 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, &mut self,
crate_lint: CrateLint, crate_lint: CrateLint,
path: &[Segment], path: &[Segment],
path_span: Span,
second_binding: Option<&NameBinding<'_>>, second_binding: Option<&NameBinding<'_>>,
) { ) {
let (diag_id, diag_span) = match crate_lint { let (diag_id, diag_span) = match crate_lint {
CrateLint::No => return, CrateLint::No => return,
CrateLint::SimplePath(id) => (id, path_span), CrateLint::SimplePath(id, path_span) => (id, path_span),
CrateLint::UsePath { root_id, root_span } => (root_id, root_span), CrateLint::UsePath { root_id, root_span, .. } => (root_id, root_span),
CrateLint::QPathTrait { qpath_id, qpath_span } => (qpath_id, qpath_span), CrateLint::QPathTrait { qpath_id, qpath_span, .. } => (qpath_id, qpath_span),
}; };
let first_name = match path.get(0) { let first_name = match path.get(0) {
@ -2678,8 +2656,7 @@ impl<'a> Resolver<'a> {
rib_index: usize, rib_index: usize,
rib_ident: Ident, rib_ident: Ident,
mut res: Res, mut res: Res,
record_used: bool, record_used: Option<Span>,
span: Span,
original_rib_ident_def: Ident, original_rib_ident_def: Ident,
all_ribs: &[Rib<'a>], all_ribs: &[Rib<'a>],
) -> Res { ) -> Res {
@ -2689,7 +2666,7 @@ impl<'a> Resolver<'a> {
// An invalid forward use of a generic parameter from a previous default. // An invalid forward use of a generic parameter from a previous default.
if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind { 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 { let res_error = if rib_ident.name == kw::SelfUpper {
ResolutionError::SelfInGenericParamDefault ResolutionError::SelfInGenericParamDefault
} else { } else {
@ -2719,17 +2696,17 @@ impl<'a> Resolver<'a> {
// This was an attempt to access an upvar inside a // This was an attempt to access an upvar inside a
// named function item. This is not allowed, so we // named function item. This is not allowed, so we
// report an error. // report an error.
if record_used { if let Some(span) = record_used {
// We don't immediately trigger a resolve error, because // We don't immediately trigger a resolve error, because
// we want certain other resolution errors (namely those // we want certain other resolution errors (namely those
// emitted for `ConstantItemRibKind` below) to take // emitted for `ConstantItemRibKind` below) to take
// precedence. // precedence.
res_err = Some(CannotCaptureDynamicEnvironmentInFnItem); res_err = Some((span, CannotCaptureDynamicEnvironmentInFnItem));
} }
} }
ConstantItemRibKind(_, item) => { ConstantItemRibKind(_, item) => {
// Still doesn't deal with upvars // Still doesn't deal with upvars
if record_used { if let Some(span) = record_used {
let (span, resolution_error) = let (span, resolution_error) =
if let Some((ident, constant_item_kind)) = item { if let Some((ident, constant_item_kind)) = item {
let kind_str = match constant_item_kind { let kind_str = match constant_item_kind {
@ -2757,14 +2734,14 @@ impl<'a> Resolver<'a> {
return Res::Err; return Res::Err;
} }
ConstParamTyRibKind => { ConstParamTyRibKind => {
if record_used { if let Some(span) = record_used {
self.report_error(span, ParamInTyOfConstParam(rib_ident.name)); self.report_error(span, ParamInTyOfConstParam(rib_ident.name));
} }
return Res::Err; return Res::Err;
} }
} }
} }
if let Some(res_err) = res_err { if let Some((span, res_err)) = res_err {
self.report_error(span, res_err); self.report_error(span, res_err);
return Res::Err; return Res::Err;
} }
@ -2792,7 +2769,7 @@ impl<'a> Resolver<'a> {
if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res { if let Res::SelfTy { trait_, alias_to: Some((def, _)) } = res {
res = Res::SelfTy { trait_, alias_to: Some((def, true)) } res = Res::SelfTy { trait_, alias_to: Some((def, true)) }
} else { } else {
if record_used { if let Some(span) = record_used {
self.report_error( self.report_error(
span, span,
ResolutionError::ParamInNonTrivialAnonConst { ResolutionError::ParamInNonTrivialAnonConst {
@ -2800,9 +2777,9 @@ impl<'a> Resolver<'a> {
is_type: true, is_type: true,
}, },
); );
self.session.delay_span_bug(span, CG_BUG_STR);
} }
self.session.delay_span_bug(span, CG_BUG_STR);
return Res::Err; return Res::Err;
} }
} }
@ -2814,7 +2791,7 @@ impl<'a> Resolver<'a> {
ItemRibKind(has_generic_params) => has_generic_params, ItemRibKind(has_generic_params) => has_generic_params,
FnItemRibKind => HasGenericParams::Yes, FnItemRibKind => HasGenericParams::Yes,
ConstParamTyRibKind => { ConstParamTyRibKind => {
if record_used { if let Some(span) = record_used {
self.report_error( self.report_error(
span, span,
ResolutionError::ParamInTyOfConstParam(rib_ident.name), 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( self.report_error(
span, span,
ResolutionError::GenericParamsFromOuterFunction( ResolutionError::GenericParamsFromOuterFunction(
@ -2858,7 +2835,7 @@ impl<'a> Resolver<'a> {
let features = self.session.features_untracked(); let features = self.session.features_untracked();
// HACK(min_const_generics): We currently only allow `N` or `{ N }`. // HACK(min_const_generics): We currently only allow `N` or `{ N }`.
if !(trivial || features.generic_const_exprs) { if !(trivial || features.generic_const_exprs) {
if record_used { if let Some(span) = record_used {
self.report_error( self.report_error(
span, span,
ResolutionError::ParamInNonTrivialAnonConst { ResolutionError::ParamInNonTrivialAnonConst {
@ -2866,9 +2843,9 @@ impl<'a> Resolver<'a> {
is_type: false, is_type: false,
}, },
); );
self.session.delay_span_bug(span, CG_BUG_STR);
} }
self.session.delay_span_bug(span, CG_BUG_STR);
return Res::Err; return Res::Err;
} }
@ -2878,7 +2855,7 @@ impl<'a> Resolver<'a> {
ItemRibKind(has_generic_params) => has_generic_params, ItemRibKind(has_generic_params) => has_generic_params,
FnItemRibKind => HasGenericParams::Yes, FnItemRibKind => HasGenericParams::Yes,
ConstParamTyRibKind => { ConstParamTyRibKind => {
if record_used { if let Some(span) = record_used {
self.report_error( self.report_error(
span, span,
ResolutionError::ParamInTyOfConstParam(rib_ident.name), 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. // This was an attempt to use a const parameter outside its scope.
if record_used { if let Some(span) = record_used {
self.report_error( self.report_error(
span, span,
ResolutionError::GenericParamsFromOuterFunction( ResolutionError::GenericParamsFromOuterFunction(
@ -3330,7 +3307,6 @@ impl<'a> Resolver<'a> {
&segments, &segments,
Some(ns), Some(ns),
&ParentScope::module(module, self), &ParentScope::module(module, self),
DUMMY_SP,
CrateLint::No, CrateLint::No,
) { ) {
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()), PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
@ -3425,8 +3401,7 @@ impl<'a> Resolver<'a> {
ident, ident,
ValueNS, ValueNS,
parent_scope, parent_scope,
false, None
DUMMY_SP,
) else { ) else {
return; return;
}; };
@ -3490,29 +3465,37 @@ enum CrateLint {
/// This lint applies to some arbitrary path; e.g., `impl ::foo::Bar`. /// This lint applies to some arbitrary path; e.g., `impl ::foo::Bar`.
/// In this case, we can take the span of that path. /// 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 /// This lint comes from a `use` statement. In this case, what we
/// care about really is the *root* `use` statement; e.g., if 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 /// have nested things like `use a::{b, c}`, we care about the
/// `use a` part. /// `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, /// 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`. /// 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`). /// 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 { impl CrateLint {
fn node_id(&self) -> Option<NodeId> { fn node_id_and_path_span(&self) -> Option<(NodeId, Span)> {
match *self { match *self {
CrateLint::No => None, CrateLint::No => None,
CrateLint::SimplePath(id) CrateLint::SimplePath(id, path_span)
| CrateLint::UsePath { root_id: id, .. } | CrateLint::UsePath { root_id: id, path_span, .. }
| CrateLint::QPathTrait { qpath_id: id, .. } => Some(id), | 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) { pub fn provide(providers: &mut Providers) {

View file

@ -415,7 +415,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
let mut indeterminate = false; let mut indeterminate = false;
for ns in [TypeNS, ValueNS, MacroNS].iter().copied() { 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::Module(ModuleOrUniformRoot::Module(_)) => return Ok(true),
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => { PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
return Ok(true); return Ok(true);
@ -575,13 +575,7 @@ impl<'a> Resolver<'a> {
} }
let res = if path.len() > 1 { let res = if path.len() > 1 {
let res = match self.resolve_path( let res = match self.resolve_path(&path, Some(MacroNS), parent_scope, CrateLint::No) {
&path,
Some(MacroNS),
parent_scope,
path_span,
CrateLint::No,
) {
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => { PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
Ok(path_res.base_res()) Ok(path_res.base_res())
} }
@ -611,9 +605,8 @@ impl<'a> Resolver<'a> {
path[0].ident, path[0].ident,
scope_set, scope_set,
parent_scope, parent_scope,
false, None,
force, force,
path_span,
); );
if let Err(Determinacy::Undetermined) = binding { if let Err(Determinacy::Undetermined) = binding {
return Err(Determinacy::Undetermined); return Err(Determinacy::Undetermined);
@ -647,9 +640,8 @@ impl<'a> Resolver<'a> {
orig_ident: Ident, orig_ident: Ident,
scope_set: ScopeSet<'a>, scope_set: ScopeSet<'a>,
parent_scope: &ParentScope<'a>, parent_scope: &ParentScope<'a>,
record_used: bool, record_used: Option<Span>,
force: bool, force: bool,
path_span: Span,
) -> Result<&'a NameBinding<'a>, Determinacy> { ) -> Result<&'a NameBinding<'a>, Determinacy> {
bitflags::bitflags! { bitflags::bitflags! {
struct Flags: u8 { 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. // Make sure `self`, `super` etc produce an error when passed to here.
if orig_ident.is_path_segment_keyword() { if orig_ident.is_path_segment_keyword() {
@ -769,7 +761,6 @@ impl<'a> Resolver<'a> {
ns, ns,
parent_scope, parent_scope,
record_used, record_used,
path_span,
); );
match binding { match binding {
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)), Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
@ -791,7 +782,6 @@ impl<'a> Resolver<'a> {
adjusted_parent_scope, adjusted_parent_scope,
!matches!(scope_set, ScopeSet::Late(..)), !matches!(scope_set, ScopeSet::Late(..)),
record_used, record_used,
path_span,
); );
match binding { match binding {
Ok(binding) => { Ok(binding) => {
@ -855,12 +845,14 @@ impl<'a> Resolver<'a> {
Err(Determinacy::Determined) Err(Determinacy::Determined)
} }
} }
Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) { Scope::ExternPrelude => {
Some(binding) => Ok((binding, Flags::empty())), match this.extern_prelude_get(ident, record_used.is_none()) {
None => Err(Determinacy::determined( Some(binding) => Ok((binding, Flags::empty())),
this.graph_root.unexpanded_invocations.borrow().is_empty(), None => Err(Determinacy::determined(
)), this.graph_root.unexpanded_invocations.borrow().is_empty(),
}, )),
}
}
Scope::ToolPrelude => match this.registered_tools.get(&ident).cloned() { Scope::ToolPrelude => match this.registered_tools.get(&ident).cloned() {
Some(ident) => ok(Res::ToolMod, ident.span, this.arenas), Some(ident) => ok(Res::ToolMod, ident.span, this.arenas),
None => Err(Determinacy::Determined), None => Err(Determinacy::Determined),
@ -873,8 +865,7 @@ impl<'a> Resolver<'a> {
ident, ident,
ns, ns,
parent_scope, parent_scope,
false, None,
path_span,
) { ) {
if use_prelude || this.is_builtin_macro(binding.res()) { if use_prelude || this.is_builtin_macro(binding.res()) {
result = Ok((binding, Flags::MISC_FROM_PRELUDE)); result = Ok((binding, Flags::MISC_FROM_PRELUDE));
@ -893,7 +884,7 @@ impl<'a> Resolver<'a> {
Ok((binding, flags)) Ok((binding, flags))
if sub_namespace_match(binding.macro_kind(), macro_kind) => 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)); return Some(Ok(binding));
} }
@ -1032,8 +1023,7 @@ impl<'a> Resolver<'a> {
&path, &path,
Some(MacroNS), Some(MacroNS),
&parent_scope, &parent_scope,
path_span, CrateLint::SimplePath(ast::CRATE_NODE_ID, path_span),
CrateLint::SimplePath(ast::CRATE_NODE_ID),
) { ) {
PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => { PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => {
let res = path_res.base_res(); let res = path_res.base_res();
@ -1067,9 +1057,8 @@ impl<'a> Resolver<'a> {
ident, ident,
ScopeSet::Macro(kind), ScopeSet::Macro(kind),
&parent_scope, &parent_scope,
Some(ident.span),
true, true,
true,
ident.span,
) { ) {
Ok(binding) => { Ok(binding) => {
let initial_res = initial_binding.map(|initial_binding| { let initial_res = initial_binding.map(|initial_binding| {
@ -1109,9 +1098,8 @@ impl<'a> Resolver<'a> {
ident, ident,
ScopeSet::Macro(MacroKind::Attr), ScopeSet::Macro(MacroKind::Attr),
&parent_scope, &parent_scope,
Some(ident.span),
true, true,
true,
ident.span,
); );
} }
} }

View file

@ -568,7 +568,7 @@ fn configure_cmake(
// We also do this if the user explicitly requested static libstdc++. // We also do this if the user explicitly requested static libstdc++.
if builder.config.llvm_static_stdcpp { if builder.config.llvm_static_stdcpp {
if !target.contains("msvc") && !target.contains("netbsd") { if !target.contains("msvc") && !target.contains("netbsd") {
if target.contains("apple") { if target.contains("apple") || target.contains("windows") {
ldflags.push_all("-static-libstdc++"); ldflags.push_all("-static-libstdc++");
} else { } else {
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++"); ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");