Skip to content

Commit 385f8e2

Browse files
committed
Auto merge of #88689 - Aaron1011:confused-std-resolver, r=cjgillot
Move `confused_type_with_std_module` to `ResolverOutputs` This eliminates untracked global state from `Session`.
2 parents ffaf857 + 4044024 commit 385f8e2

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

Diff for: compiler/rustc_middle/src/ty/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ pub struct ResolverOutputs {
137137
/// A list of proc macro LocalDefIds, written out in the order in which
138138
/// they are declared in the static array generated by proc_macro_harness.
139139
pub proc_macros: Vec<LocalDefId>,
140+
/// Mapping from ident span to path span for paths that don't exist as written, but that
141+
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
142+
pub confused_type_with_std_module: FxHashMap<Span, Span>,
140143
}
141144

142145
#[derive(Clone, Copy, Debug)]

Diff for: compiler/rustc_resolve/src/late.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1999,9 +1999,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19991999
let item_span =
20002000
path.iter().last().map_or(span, |segment| segment.ident.span);
20012001

2002-
let mut hm = self.r.session.confused_type_with_std_module.borrow_mut();
2003-
hm.insert(item_span, span);
2004-
hm.insert(span, span);
2002+
self.r.confused_type_with_std_module.insert(item_span, span);
2003+
self.r.confused_type_with_std_module.insert(span, span);
20052004
}
20062005
}
20072006

Diff for: compiler/rustc_resolve/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ pub struct Resolver<'a> {
10381038
/// A list of proc macro LocalDefIds, written out in the order in which
10391039
/// they are declared in the static array generated by proc_macro_harness.
10401040
proc_macros: Vec<NodeId>,
1041+
confused_type_with_std_module: FxHashMap<Span, Span>,
10411042
}
10421043

10431044
/// Nothing really interesting here; it just provides memory for the rest of the crate.
@@ -1404,6 +1405,7 @@ impl<'a> Resolver<'a> {
14041405
main_def: Default::default(),
14051406
trait_impls: Default::default(),
14061407
proc_macros: Default::default(),
1408+
confused_type_with_std_module: Default::default(),
14071409
};
14081410

14091411
let root_parent_scope = ParentScope::module(graph_root, &resolver);
@@ -1447,6 +1449,7 @@ impl<'a> Resolver<'a> {
14471449
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
14481450
let glob_map = self.glob_map;
14491451
let main_def = self.main_def;
1452+
let confused_type_with_std_module = self.confused_type_with_std_module;
14501453
ResolverOutputs {
14511454
definitions,
14521455
cstore: Box::new(self.crate_loader.into_cstore()),
@@ -1464,6 +1467,7 @@ impl<'a> Resolver<'a> {
14641467
main_def,
14651468
trait_impls: self.trait_impls,
14661469
proc_macros,
1470+
confused_type_with_std_module,
14671471
}
14681472
}
14691473

@@ -1486,6 +1490,7 @@ impl<'a> Resolver<'a> {
14861490
main_def: self.main_def.clone(),
14871491
trait_impls: self.trait_impls.clone(),
14881492
proc_macros,
1493+
confused_type_with_std_module: self.confused_type_with_std_module.clone(),
14891494
}
14901495
}
14911496

Diff for: compiler/rustc_session/src/session.rs

-5
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ pub struct Session {
183183
/// Cap lint level specified by a driver specifically.
184184
pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
185185

186-
/// Mapping from ident span to path span for paths that don't exist as written, but that
187-
/// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
188-
pub confused_type_with_std_module: Lock<FxHashMap<Span, Span>>,
189-
190186
/// Tracks the current behavior of the CTFE engine when an error occurs.
191187
/// Options range from returning the error without a backtrace to returning an error
192188
/// and immediately printing the backtrace to stderr.
@@ -1313,7 +1309,6 @@ pub fn build_session(
13131309
print_fuel,
13141310
jobserver: jobserver::client(),
13151311
driver_lint_caps,
1316-
confused_type_with_std_module: Lock::new(Default::default()),
13171312
ctfe_backtrace,
13181313
miri_unleashed_features: Lock::new(Default::default()),
13191314
asm_arch,

Diff for: compiler/rustc_typeck/src/astconv/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14951495
let mut err = struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type");
14961496
if let (true, Ok(snippet)) = (
14971497
self.tcx()
1498-
.sess
1498+
.resolutions(())
14991499
.confused_type_with_std_module
1500-
.borrow()
15011500
.keys()
15021501
.any(|full_span| full_span.contains(span)),
15031502
self.tcx().sess.source_map().span_to_snippet(span),

Diff for: compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
434434
}
435435
}
436436
if let Some(span) =
437-
tcx.sess.confused_type_with_std_module.borrow().get(&span)
437+
tcx.resolutions(()).confused_type_with_std_module.get(&span)
438438
{
439439
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*span) {
440440
err.span_suggestion(

0 commit comments

Comments
 (0)