diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index ab1df2d4c3bb9..5e15ca16b97cd 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -936,8 +936,8 @@ pub struct GlobalCtxt<'tcx> { freevars: FxHashMap>>, maybe_unused_trait_imports: FxHashSet, - maybe_unused_extern_crates: Vec<(DefId, Span)>, + pub extern_prelude: FxHashSet, // Internal cache for metadata decoding. No need to track deps on this. pub rcache: Lock>>, @@ -1223,6 +1223,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { .into_iter() .map(|(id, sp)| (hir.local_def_id(id), sp)) .collect(), + extern_prelude: resolutions.extern_prelude, hir, def_path_hash_to_def_id, queries: query::Queries::new( diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index ab0813240364c..ca4cafd0a7391 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // printing the `CrateRoot` so we don't prepend a `crate::` to paths. let mut is_prelude_crate = false; if let DefPathData::CrateRoot = self.def_key(parent_did).disambiguated_data.data { - if self.sess.extern_prelude.contains(&data.as_interned_str().as_symbol()) { + if self.extern_prelude.contains(&data.as_interned_str().as_symbol()) { is_prelude_crate = true; } } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 2e8734a6aa8eb..ee6d2dfb065f0 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -36,7 +36,7 @@ use ty::subst::{Subst, Substs}; use ty::util::{IntTypeExt, Discr}; use ty::walk::TypeWalker; use util::captures::Captures; -use util::nodemap::{NodeSet, DefIdMap, FxHashMap}; +use util::nodemap::{NodeSet, DefIdMap, FxHashMap, FxHashSet}; use arena::SyncDroplessArena; use session::DataTypeKind; @@ -140,6 +140,7 @@ pub struct Resolutions { pub maybe_unused_trait_imports: NodeSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, pub export_map: ExportMap, + pub extern_prelude: FxHashSet, } #[derive(Clone, Copy, PartialEq, Eq, Debug)] diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 7fb66ea97f26b..3b0acfd6f8c12 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -790,6 +790,7 @@ where trait_map: resolver.trait_map, maybe_unused_trait_imports: resolver.maybe_unused_trait_imports, maybe_unused_extern_crates: resolver.maybe_unused_extern_crates, + extern_prelude: resolver.extern_prelude, }, analysis: ty::CrateAnalysis { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1ad41fa058244..8cf3c0f8843a8 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1360,7 +1360,7 @@ pub struct Resolver<'a, 'b: 'a> { graph_root: Module<'a>, prelude: Option>, - extern_prelude: FxHashSet, + pub extern_prelude: FxHashSet, /// n.b. This is used only for better diagnostics, not name resolution itself. has_self: FxHashSet, diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 62ffffab07661..f9aa0397257b8 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -164,7 +164,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) { // If the extern crate isn't in the extern prelude, // there is no way it can be written as an `use`. let orig_name = extern_crate.orig_name.unwrap_or(item.name); - if !tcx.sess.extern_prelude.contains(&orig_name) { + if !tcx.extern_prelude.contains(&orig_name) { continue; } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b85604d860be4..4a698e499a7fb 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -474,6 +474,7 @@ pub fn run_core(search_paths: SearchPaths, trait_map: resolver.trait_map.clone(), maybe_unused_trait_imports: resolver.maybe_unused_trait_imports.clone(), maybe_unused_extern_crates: resolver.maybe_unused_extern_crates.clone(), + extern_prelude: resolver.extern_prelude.clone(), }; let analysis = ty::CrateAnalysis { access_levels: Lrc::new(AccessLevels::default()),