Skip to content

Commit 487e5ce

Browse files
Introduce, implement and use CmResolver.
1 parent 8fb40f7 commit 487e5ce

File tree

8 files changed

+337
-189
lines changed

8 files changed

+337
-189
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
223223

224224
pub(crate) fn build_reduced_graph_external(&self, module: Module<'ra>) {
225225
for child in self.tcx.module_children(module.def_id()) {
226-
let parent_scope = ParentScope::module(module, self);
226+
let parent_scope = ParentScope::module(module, self.arenas);
227227
self.build_reduced_graph_for_external_crate_res(child, parent_scope)
228228
}
229229
}
@@ -373,7 +373,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
373373
res,
374374
))
375375
};
376-
match self.r.resolve_path(
376+
match self.r.cm().resolve_path(
377377
&segments,
378378
None,
379379
parent_scope,
@@ -1128,7 +1128,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11281128
});
11291129
} else {
11301130
for ident in single_imports.iter().cloned() {
1131-
let result = self.r.maybe_resolve_ident_in_module(
1131+
let result = self.r.cm().maybe_resolve_ident_in_module(
11321132
ModuleOrUniformRoot::Module(module),
11331133
ident,
11341134
MacroNS,

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
467467

468468
pub(crate) fn lint_if_path_starts_with_module(
469469
&mut self,
470-
finalize: Option<Finalize>,
470+
finalize: Finalize,
471471
path: &[Segment],
472472
second_binding: Option<NameBinding<'_>>,
473473
) {
474-
let Some(Finalize { node_id, root_span, .. }) = finalize else {
475-
return;
476-
};
474+
let Finalize { node_id, root_span, .. } = finalize;
477475

478476
let first_name = match path.get(0) {
479477
// In the 2018 edition this lint is a hard error, so nothing to do
@@ -1027,7 +1025,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10271025
) -> Option<TypoSuggestion> {
10281026
let mut suggestions = Vec::new();
10291027
let ctxt = ident.span.ctxt();
1030-
self.visit_scopes(scope_set, parent_scope, ctxt, |this, scope, use_prelude, _| {
1028+
self.cm().visit_scopes(scope_set, parent_scope, ctxt, |this, scope, use_prelude, _| {
10311029
match scope {
10321030
Scope::DeriveHelpers(expn_id) => {
10331031
let res = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper);
@@ -1046,7 +1044,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10461044
if filter_fn(res) {
10471045
for derive in parent_scope.derives {
10481046
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
1049-
let Ok((Some(ext), _)) = this.resolve_macro_path(
1047+
let Ok((Some(ext), _)) = this.reborrow().resolve_macro_path(
10501048
derive,
10511049
Some(MacroKind::Derive),
10521050
parent_scope,
@@ -1480,7 +1478,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14801478
) {
14811479
// Bring imported but unused `derive` macros into `macro_map` so we ensure they can be used
14821480
// for suggestions.
1483-
self.visit_scopes(
1481+
self.cm().visit_scopes(
14841482
ScopeSet::Macro(MacroKind::Derive),
14851483
&parent_scope,
14861484
ident.span.ctxt(),
@@ -1589,7 +1587,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15891587
});
15901588
}
15911589
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
1592-
let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
1590+
let Ok(binding) = self.cm().early_resolve_ident_in_lexical_scope(
15931591
ident,
15941592
ScopeSet::All(ns),
15951593
parent_scope,
@@ -2269,16 +2267,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22692267
if ns == TypeNS || ns == ValueNS {
22702268
let ns_to_try = if ns == TypeNS { ValueNS } else { TypeNS };
22712269
let binding = if let Some(module) = module {
2272-
self.resolve_ident_in_module(
2273-
module,
2274-
ident,
2275-
ns_to_try,
2276-
parent_scope,
2277-
None,
2278-
ignore_binding,
2279-
ignore_import,
2280-
)
2281-
.ok()
2270+
self.cm()
2271+
.resolve_ident_in_module(
2272+
module,
2273+
ident,
2274+
ns_to_try,
2275+
parent_scope,
2276+
None,
2277+
ignore_binding,
2278+
ignore_import,
2279+
)
2280+
.ok()
22822281
} else if let Some(ribs) = ribs
22832282
&& let Some(TypeNS | ValueNS) = opt_ns
22842283
{
@@ -2296,16 +2295,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22962295
_ => None,
22972296
}
22982297
} else {
2299-
self.early_resolve_ident_in_lexical_scope(
2300-
ident,
2301-
ScopeSet::All(ns_to_try),
2302-
parent_scope,
2303-
None,
2304-
false,
2305-
ignore_binding,
2306-
ignore_import,
2307-
)
2308-
.ok()
2298+
self.cm()
2299+
.early_resolve_ident_in_lexical_scope(
2300+
ident,
2301+
ScopeSet::All(ns_to_try),
2302+
parent_scope,
2303+
None,
2304+
false,
2305+
ignore_binding,
2306+
ignore_import,
2307+
)
2308+
.ok()
23092309
};
23102310
if let Some(binding) = binding {
23112311
msg = format!(
@@ -2399,7 +2399,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
23992399
},
24002400
)
24012401
});
2402-
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
2402+
if let Ok(binding) = self.cm().early_resolve_ident_in_lexical_scope(
24032403
ident,
24042404
ScopeSet::All(ValueNS),
24052405
parent_scope,
@@ -2529,7 +2529,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
25292529
) -> Option<(Vec<Segment>, Option<String>)> {
25302530
// Replace first ident with `self` and check if that is valid.
25312531
path[0].ident.name = kw::SelfLower;
2532-
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2532+
let result = self.cm().maybe_resolve_path(&path, None, parent_scope, None);
25332533
debug!(?path, ?result);
25342534
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
25352535
}
@@ -2549,7 +2549,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
25492549
) -> Option<(Vec<Segment>, Option<String>)> {
25502550
// Replace first ident with `crate` and check if that is valid.
25512551
path[0].ident.name = kw::Crate;
2552-
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2552+
let result = self.cm().maybe_resolve_path(&path, None, parent_scope, None);
25532553
debug!(?path, ?result);
25542554
if let PathResult::Module(..) = result {
25552555
Some((
@@ -2581,7 +2581,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
25812581
) -> Option<(Vec<Segment>, Option<String>)> {
25822582
// Replace first ident with `crate` and check if that is valid.
25832583
path[0].ident.name = kw::Super;
2584-
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2584+
let result = self.cm().maybe_resolve_path(&path, None, parent_scope, None);
25852585
debug!(?path, ?result);
25862586
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
25872587
}
@@ -2616,7 +2616,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
26162616
for name in extern_crate_names.into_iter() {
26172617
// Replace first ident with a crate name and check if that is valid.
26182618
path[0].ident.name = name;
2619-
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
2619+
let result = self.cm().maybe_resolve_path(&path, None, parent_scope, None);
26202620
debug!(?path, ?name, ?result);
26212621
if let PathResult::Module(..) = result {
26222622
return Some((path, None));

0 commit comments

Comments
 (0)