]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #88689 - Aaron1011:confused-std-resolver, r=cjgillot
authorbors <bors@rust-lang.org>
Tue, 7 Sep 2021 05:28:53 +0000 (05:28 +0000)
committerbors <bors@rust-lang.org>
Tue, 7 Sep 2021 05:28:53 +0000 (05:28 +0000)
Move `confused_type_with_std_module` to `ResolverOutputs`

This eliminates untracked global state from `Session`.

compiler/rustc_middle/src/ty/mod.rs
compiler/rustc_resolve/src/late.rs
compiler/rustc_resolve/src/lib.rs
compiler/rustc_session/src/session.rs
compiler/rustc_typeck/src/astconv/mod.rs
compiler/rustc_typeck/src/check/method/suggest.rs

index d01ca27b8511895b78102b6c087c1cd496e33fb1..fddfd6e435c0550e586f0ffa732a35784ab33f99 100644 (file)
@@ -137,6 +137,9 @@ pub struct ResolverOutputs {
     /// A list of proc macro LocalDefIds, written out in the order in which
     /// they are declared in the static array generated by proc_macro_harness.
     pub proc_macros: Vec<LocalDefId>,
+    /// Mapping from ident span to path span for paths that don't exist as written, but that
+    /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
+    pub confused_type_with_std_module: FxHashMap<Span, Span>,
 }
 
 #[derive(Clone, Copy, Debug)]
index 60573968361203330f30e8f77c33ec89f8d15c81..c0b52d21fa639c293987ce4779a9158e9f261d53 100644 (file)
@@ -1999,9 +1999,8 @@ fn smart_resolve_path_fragment(
                         let item_span =
                             path.iter().last().map_or(span, |segment| segment.ident.span);
 
-                        let mut hm = self.r.session.confused_type_with_std_module.borrow_mut();
-                        hm.insert(item_span, span);
-                        hm.insert(span, span);
+                        self.r.confused_type_with_std_module.insert(item_span, span);
+                        self.r.confused_type_with_std_module.insert(span, span);
                     }
                 }
 
index 152d34fd63558df8e2c8caac358cae5b6f7f8608..6d2961db9e3dace832a4e86ef6e3663148d7fbb3 100644 (file)
@@ -1038,6 +1038,7 @@ pub struct Resolver<'a> {
     /// A list of proc macro LocalDefIds, written out in the order in which
     /// they are declared in the static array generated by proc_macro_harness.
     proc_macros: Vec<NodeId>,
+    confused_type_with_std_module: FxHashMap<Span, Span>,
 }
 
 /// Nothing really interesting here; it just provides memory for the rest of the crate.
@@ -1404,6 +1405,7 @@ pub fn new(
             main_def: Default::default(),
             trait_impls: Default::default(),
             proc_macros: Default::default(),
+            confused_type_with_std_module: Default::default(),
         };
 
         let root_parent_scope = ParentScope::module(graph_root, &resolver);
@@ -1447,6 +1449,7 @@ pub fn into_outputs(self) -> ResolverOutputs {
         let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
         let glob_map = self.glob_map;
         let main_def = self.main_def;
+        let confused_type_with_std_module = self.confused_type_with_std_module;
         ResolverOutputs {
             definitions,
             cstore: Box::new(self.crate_loader.into_cstore()),
@@ -1464,6 +1467,7 @@ pub fn into_outputs(self) -> ResolverOutputs {
             main_def,
             trait_impls: self.trait_impls,
             proc_macros,
+            confused_type_with_std_module,
         }
     }
 
@@ -1486,6 +1490,7 @@ pub fn clone_outputs(&self) -> ResolverOutputs {
             main_def: self.main_def.clone(),
             trait_impls: self.trait_impls.clone(),
             proc_macros,
+            confused_type_with_std_module: self.confused_type_with_std_module.clone(),
         }
     }
 
index 0f7db69fefefc779cb66adc8035bb8a330dfb45f..c71595ab57e7224ab60699e8bf4caf698827bc8b 100644 (file)
@@ -183,10 +183,6 @@ pub struct Session {
     /// Cap lint level specified by a driver specifically.
     pub driver_lint_caps: FxHashMap<lint::LintId, lint::Level>,
 
-    /// Mapping from ident span to path span for paths that don't exist as written, but that
-    /// exist under `std`. For example, wrote `str::from_utf8` instead of `std::str::from_utf8`.
-    pub confused_type_with_std_module: Lock<FxHashMap<Span, Span>>,
-
     /// Tracks the current behavior of the CTFE engine when an error occurs.
     /// Options range from returning the error without a backtrace to returning an error
     /// and immediately printing the backtrace to stderr.
@@ -1313,7 +1309,6 @@ pub fn build_session(
         print_fuel,
         jobserver: jobserver::client(),
         driver_lint_caps,
-        confused_type_with_std_module: Lock::new(Default::default()),
         ctfe_backtrace,
         miri_unleashed_features: Lock::new(Default::default()),
         asm_arch,
index 059e0cadd190cf649cf092fe4a291e48e6ebca11..a795a52a25c46243b9acf01e6d5d5ad420bfa709 100644 (file)
@@ -1495,9 +1495,8 @@ fn report_ambiguous_associated_type(
         let mut err = struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type");
         if let (true, Ok(snippet)) = (
             self.tcx()
-                .sess
+                .resolutions(())
                 .confused_type_with_std_module
-                .borrow()
                 .keys()
                 .any(|full_span| full_span.contains(span)),
             self.tcx().sess.source_map().span_to_snippet(span),
index c60d82d0cabc579e819b76f6cbac2049b53f818e..aec080ae205178e45361a9c0d487c219cd4cf333 100644 (file)
@@ -434,7 +434,7 @@ pub fn report_method_error(
                             }
                         }
                         if let Some(span) =
-                            tcx.sess.confused_type_with_std_module.borrow().get(&span)
+                            tcx.resolutions(()).confused_type_with_std_module.get(&span)
                         {
                             if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*span) {
                                 err.span_suggestion(