Skip to content

Commit 74d079d

Browse files
committed
resolve: Stop passing unused spans and node ids to path resolution functions
1 parent 15a8b98 commit 74d079d

File tree

8 files changed

+189
-268
lines changed

8 files changed

+189
-268
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
296296
&segments,
297297
Some(TypeNS),
298298
parent_scope,
299-
path.span,
300-
if speculative { CrateLint::No } else { CrateLint::SimplePath(id) },
299+
if speculative { CrateLint::No } else { CrateLint::SimplePath(id, path.span) },
301300
) {
302301
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
303302
let res = module.res().expect("visibility resolved to unnamed block");
@@ -1130,8 +1129,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11301129
ident,
11311130
MacroNS,
11321131
&self.parent_scope,
1133-
false,
1134-
ident.span,
1132+
None,
11351133
);
11361134
if let Ok(binding) = result {
11371135
let import = macro_use_import(self, ident.span);

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,9 +1076,8 @@ impl<'a> Resolver<'a> {
10761076
ident,
10771077
ScopeSet::All(ns, false),
10781078
&parent_scope,
1079+
None,
10791080
false,
1080-
false,
1081-
ident.span,
10821081
) {
10831082
let desc = match binding.res() {
10841083
Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
@@ -1405,10 +1404,10 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14051404
_ => return None,
14061405
}
14071406

1408-
self.make_missing_self_suggestion(span, path.clone(), parent_scope)
1409-
.or_else(|| self.make_missing_crate_suggestion(span, path.clone(), parent_scope))
1410-
.or_else(|| self.make_missing_super_suggestion(span, path.clone(), parent_scope))
1411-
.or_else(|| self.make_external_crate_suggestion(span, path, parent_scope))
1407+
self.make_missing_self_suggestion(path.clone(), parent_scope)
1408+
.or_else(|| self.make_missing_crate_suggestion(path.clone(), parent_scope))
1409+
.or_else(|| self.make_missing_super_suggestion(path.clone(), parent_scope))
1410+
.or_else(|| self.make_external_crate_suggestion(path, parent_scope))
14121411
}
14131412

14141413
/// Suggest a missing `self::` if that resolves to an correct module.
@@ -1420,13 +1419,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14201419
/// ```
14211420
fn make_missing_self_suggestion(
14221421
&mut self,
1423-
span: Span,
14241422
mut path: Vec<Segment>,
14251423
parent_scope: &ParentScope<'b>,
14261424
) -> Option<(Vec<Segment>, Vec<String>)> {
14271425
// Replace first ident with `self` and check if that is valid.
14281426
path[0].ident.name = kw::SelfLower;
1429-
let result = self.r.resolve_path(&path, None, parent_scope, span, CrateLint::No);
1427+
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
14301428
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
14311429
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
14321430
}
@@ -1440,13 +1438,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14401438
/// ```
14411439
fn make_missing_crate_suggestion(
14421440
&mut self,
1443-
span: Span,
14441441
mut path: Vec<Segment>,
14451442
parent_scope: &ParentScope<'b>,
14461443
) -> Option<(Vec<Segment>, Vec<String>)> {
14471444
// Replace first ident with `crate` and check if that is valid.
14481445
path[0].ident.name = kw::Crate;
1449-
let result = self.r.resolve_path(&path, None, parent_scope, span, CrateLint::No);
1446+
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
14501447
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
14511448
if let PathResult::Module(..) = result {
14521449
Some((
@@ -1472,13 +1469,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14721469
/// ```
14731470
fn make_missing_super_suggestion(
14741471
&mut self,
1475-
span: Span,
14761472
mut path: Vec<Segment>,
14771473
parent_scope: &ParentScope<'b>,
14781474
) -> Option<(Vec<Segment>, Vec<String>)> {
14791475
// Replace first ident with `crate` and check if that is valid.
14801476
path[0].ident.name = kw::Super;
1481-
let result = self.r.resolve_path(&path, None, parent_scope, span, CrateLint::No);
1477+
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
14821478
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
14831479
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
14841480
}
@@ -1495,7 +1491,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14951491
/// name as the first part of path.
14961492
fn make_external_crate_suggestion(
14971493
&mut self,
1498-
span: Span,
14991494
mut path: Vec<Segment>,
15001495
parent_scope: &ParentScope<'b>,
15011496
) -> Option<(Vec<Segment>, Vec<String>)> {
@@ -1513,7 +1508,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
15131508
for name in extern_crate_names.into_iter() {
15141509
// Replace first ident with a crate name and check if that is valid.
15151510
path[0].ident.name = name;
1516-
let result = self.r.resolve_path(&path, None, parent_scope, span, CrateLint::No);
1511+
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
15171512
debug!(
15181513
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
15191514
name, path, result

compiler/rustc_resolve/src/imports.rs

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ impl<'a> Resolver<'a> {
175175
ident: Ident,
176176
ns: Namespace,
177177
parent_scope: &ParentScope<'a>,
178-
record_used: bool,
179-
path_span: Span,
178+
record_used: Option<Span>,
180179
) -> Result<&'a NameBinding<'a>, Determinacy> {
181180
self.resolve_ident_in_module_unadjusted_ext(
182181
module,
@@ -185,7 +184,6 @@ impl<'a> Resolver<'a> {
185184
parent_scope,
186185
false,
187186
record_used,
188-
path_span,
189187
)
190188
.map_err(|(determinacy, _)| determinacy)
191189
}
@@ -199,8 +197,7 @@ impl<'a> Resolver<'a> {
199197
ns: Namespace,
200198
parent_scope: &ParentScope<'a>,
201199
restricted_shadowing: bool,
202-
record_used: bool,
203-
path_span: Span,
200+
record_used: Option<Span>,
204201
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
205202
let module = match module {
206203
ModuleOrUniformRoot::Module(module) => module,
@@ -211,16 +208,16 @@ impl<'a> Resolver<'a> {
211208
ScopeSet::AbsolutePath(ns),
212209
parent_scope,
213210
record_used,
214-
record_used,
215-
path_span,
211+
record_used.is_some(),
216212
);
217213
return binding.map_err(|determinacy| (determinacy, Weak::No));
218214
}
219215
ModuleOrUniformRoot::ExternPrelude => {
220216
assert!(!restricted_shadowing);
221217
return if ns != TypeNS {
222218
Err((Determined, Weak::No))
223-
} else if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
219+
} else if let Some(binding) = self.extern_prelude_get(ident, record_used.is_none())
220+
{
224221
Ok(binding)
225222
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
226223
// Macro-expanded `extern crate` items can add names to extern prelude.
@@ -251,8 +248,7 @@ impl<'a> Resolver<'a> {
251248
scopes,
252249
parent_scope,
253250
record_used,
254-
record_used,
255-
path_span,
251+
record_used.is_some(),
256252
);
257253
return binding.map_err(|determinacy| (determinacy, Weak::No));
258254
}
@@ -262,7 +258,7 @@ impl<'a> Resolver<'a> {
262258
let resolution =
263259
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
264260

265-
if let Some(binding) = resolution.binding {
261+
if let Some(binding) = resolution.binding && let Some(path_span) = record_used {
266262
if !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
267263
if let NameBindingKind::Res(_, true) = binding.kind {
268264
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
@@ -280,7 +276,7 @@ impl<'a> Resolver<'a> {
280276
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
281277
};
282278

283-
if record_used {
279+
if let Some(path_span) = record_used {
284280
return resolution
285281
.binding
286282
.and_then(|binding| {
@@ -353,14 +349,8 @@ impl<'a> Resolver<'a> {
353349
let ImportKind::Single { source: ident, .. } = single_import.kind else {
354350
unreachable!();
355351
};
356-
match self.resolve_ident_in_module(
357-
module,
358-
ident,
359-
ns,
360-
&single_import.parent_scope,
361-
false,
362-
path_span,
363-
) {
352+
match self.resolve_ident_in_module(module, ident, ns, &single_import.parent_scope, None)
353+
{
364354
Err(Determined) => continue,
365355
Ok(binding)
366356
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
@@ -434,8 +424,7 @@ impl<'a> Resolver<'a> {
434424
ident,
435425
ns,
436426
adjusted_parent_scope,
437-
false,
438-
path_span,
427+
None,
439428
);
440429

441430
match result {
@@ -783,13 +772,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
783772
// For better failure detection, pretend that the import will
784773
// not define any names while resolving its module path.
785774
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
786-
let path_res = self.r.resolve_path(
787-
&import.module_path,
788-
None,
789-
&import.parent_scope,
790-
import.span,
791-
CrateLint::No,
792-
);
775+
let path_res =
776+
self.r.resolve_path(&import.module_path, None, &import.parent_scope, CrateLint::No);
793777
import.vis.set(orig_vis);
794778

795779
match path_res {
@@ -828,8 +812,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
828812
source,
829813
ns,
830814
&import.parent_scope,
831-
false,
832-
import.span,
815+
None,
833816
);
834817
import.vis.set(orig_vis);
835818
source_bindings[ns].set(binding);
@@ -882,15 +865,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
882865
_ => None,
883866
};
884867
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
885-
let crate_lint =
886-
CrateLint::UsePath { root_id: import.root_id, root_span: import.root_span };
887-
let path_res = self.r.resolve_path(
888-
&import.module_path,
889-
None,
890-
&import.parent_scope,
891-
import.span,
892-
crate_lint,
893-
);
868+
let crate_lint = CrateLint::UsePath {
869+
root_id: import.root_id,
870+
root_span: import.root_span,
871+
path_span: import.span,
872+
};
873+
let path_res =
874+
self.r.resolve_path(&import.module_path, None, &import.parent_scope, crate_lint);
894875
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
895876
if let Some(orig_unusable_binding) = orig_unusable_binding {
896877
self.r.unusable_binding = orig_unusable_binding;
@@ -977,12 +958,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
977958
// 2 segments, so the `resolve_path` above won't trigger it.
978959
let mut full_path = import.module_path.clone();
979960
full_path.push(Segment::from_ident(Ident::empty()));
980-
self.r.lint_if_path_starts_with_module(
981-
crate_lint,
982-
&full_path,
983-
import.span,
984-
None,
985-
);
961+
self.r.lint_if_path_starts_with_module(crate_lint, &full_path, None);
986962
}
987963

988964
if let ModuleOrUniformRoot::Module(module) = module {
@@ -1020,8 +996,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
1020996
ident,
1021997
ns,
1022998
&import.parent_scope,
1023-
true,
1024-
import.span,
999+
Some(import.span),
10251000
);
10261001
this.last_import_segment = orig_last_import_segment;
10271002
this.unusable_binding = orig_unusable_binding;
@@ -1082,8 +1057,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
10821057
ident,
10831058
ns,
10841059
&import.parent_scope,
1085-
true,
1086-
import.span,
1060+
Some(import.span),
10871061
);
10881062
if binding.is_ok() {
10891063
all_ns_failed = false;
@@ -1249,12 +1223,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
12491223
full_path.push(Segment::from_ident(ident));
12501224
self.r.per_ns(|this, ns| {
12511225
if let Ok(binding) = source_bindings[ns].get() {
1252-
this.lint_if_path_starts_with_module(
1253-
crate_lint,
1254-
&full_path,
1255-
import.span,
1256-
Some(binding),
1257-
);
1226+
this.lint_if_path_starts_with_module(crate_lint, &full_path, Some(binding));
12581227
}
12591228
});
12601229
}
@@ -1310,9 +1279,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13101279
target,
13111280
ScopeSet::All(ns, false),
13121281
&import.parent_scope,
1282+
None,
13131283
false,
1314-
false,
1315-
import.span,
13161284
) {
13171285
Ok(other_binding) => {
13181286
is_redundant[ns] = Some(

0 commit comments

Comments
 (0)