提交 74d079d5 编写于 作者: V Vadim Petrochenkov

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

上级 15a8b981
......@@ -296,8 +296,7 @@ fn resolve_visibility_speculative<'ast>(
&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 @@ fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool
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 @@ fn lookup_import_candidates_from_module<FilterFn>(
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 @@ pub(crate) fn make_path_suggestion(
_ => 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 @@ pub(crate) fn make_path_suggestion(
/// ```
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 @@ fn make_missing_self_suggestion(
/// ```
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 @@ fn make_missing_crate_suggestion(
/// ```
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 @@ fn make_missing_super_suggestion(
/// 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 @@ fn make_external_crate_suggestion(
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 @@ fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
// 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 @@ fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
source,
ns,
&import.parent_scope,
false,
import.span,
None,
);
import.vis.set(orig_vis);
source_bindings[ns].set(binding);
......@@ -882,15 +865,13 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
_ => 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 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
// 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 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
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 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
ident,
ns,
&import.parent_scope,
true,
import.span,
Some(import.span),
);
if binding.is_ok() {
all_ns_failed = false;
......@@ -1249,12 +1223,7 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
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 @@ fn check_for_redundant_imports(
target,
ScopeSet::All(ns, false),
&import.parent_scope,
None,
false,
false,
import.span,
) {
Ok(other_binding) => {
is_redundant[ns] = Some(
......
......@@ -483,7 +483,11 @@ fn visit_ty(&mut self, ty: &'ast Ty) {
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 @@ fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
self.resolve_ident_in_lexical_scope(
path.segments[0].ident,
ns,
None,
path.span,
CrateLint::No,
)
.is_some()
};
......@@ -751,15 +754,13 @@ fn resolve_ident_in_lexical_scope(
&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 @@ fn resolve_path(
&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 @@ fn future_proof_import(&mut self, use_tree: &UseTree) {
};
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 @@ fn with_optional_trait_ref<T>(
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 @@ fn resolve_pattern_inner(
// 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 @@ fn innermost_rib_bindings(&mut self, ns: Namespace) -> &mut IdentMap<Res> {
fn try_resolve_as_non_binding(
&mut self,
pat_src: PatternSource,
pat: &Pat,
bm: BindingMode,
ident: Ident,
has_sub: bool,
......@@ -1812,7 +1808,7 @@ fn try_resolve_as_non_binding(
// 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 @@ fn smart_resolve_path(
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 @@ fn smart_resolve_path_fragment(
};
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 @@ fn smart_resolve_path_fragment(
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 @@ fn smart_resolve_path_fragment(
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 @@ fn smart_resolve_path_fragment(
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 @@ fn should_report_errs(&self) -> bool {
// 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 @@ fn resolve_qpath_anywhere(
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 @@ fn resolve_qpath_anywhere(
/// 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 @@ fn resolve_qpath(
// 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 @@ fn resolve_qpath(
)));
}
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 @@ fn resolve_qpath(
&& 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 @@ fn resolve_qpath(
};
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 @@ pub(crate) fn smart_resolve_report_errors(
(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 @@ pub(crate) fn smart_resolve_report_errors(
_ => {}
}
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 @@ pub(crate) fn smart_resolve_report_errors(
"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 @@ pub(crate) fn smart_resolve_report_errors(
);
}
}
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 @@ pub(crate) fn smart_resolve_report_errors(
}
// 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 @@ pub(crate) fn smart_resolve_report_errors(
}
// 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 @@ fn detect_assoct_type_constraint_meant_as_path(&self, base_span: Span, err: &mut
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 @@ fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diagnost
{
// 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 @@ fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diagnost
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 @@ fn extract_node_id(t: &Ty) -> Option<NodeId> {
ident,
ns,
&self.parent_scope,
false,
module.span,
None,
) {
let res = binding.res();
if filter_fn(res) {
......@@ -1323,7 +1318,6 @@ fn lookup_typo_candidate(
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 @@ fn lookup_typo_candidate(
// 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);
}
......
此差异已折叠。
......@@ -415,7 +415,7 @@ fn cfg_accessible(
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 @@ pub fn resolve_macro_path(
}
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 @@ pub fn resolve_macro_path(
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 @@ pub fn resolve_macro_path(
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 @@ struct Flags: u8 {
}
}
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 @@ struct Flags: u8 {
ns,
parent_scope,
record_used,
path_span,
);
match binding {
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
......@@ -791,7 +782,6 @@ struct Flags: u8 {
adjusted_parent_scope,
!matches!(scope_set, ScopeSet::Late(..)),
record_used,
path_span,
);
match binding {
Ok(binding) => {
......@@ -855,12 +845,14 @@ struct Flags: u8 {
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 @@ struct Flags: u8 {
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 @@ struct Flags: u8 {
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 @@ struct Flags: u8 {
&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 @@ struct Flags: u8 {
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 @@ struct Flags: u8 {
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++");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册