From 5728c5371dc27aa0572c99c692cede23a019b7ff Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 18:35:58 +0100 Subject: [PATCH 01/13] Use `HirId` as key for `ResolverOutputs::trait_map` instead of `NodeId` --- src/librustc_hir/definitions.rs | 4 +++- src/librustc_middle/ty/context.rs | 3 +-- src/librustc_middle/ty/mod.rs | 4 ++-- src/librustc_resolve/lib.rs | 19 +++++++++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/librustc_hir/definitions.rs b/src/librustc_hir/definitions.rs index 30cddac6aac91..c7a0822d27dd6 100644 --- a/src/librustc_hir/definitions.rs +++ b/src/librustc_hir/definitions.rs @@ -327,7 +327,9 @@ impl Definitions { #[inline] pub fn local_def_id(&self, node: ast::NodeId) -> LocalDefId { - self.opt_local_def_id(node).unwrap() + self.opt_local_def_id(node).unwrap_or_else(|| { + panic!("no entry for node id: `{:?}` / `{:?}`", node, self.opt_node_id_to_hir_id(node)) + }) } #[inline] diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d2e53facf5e0a..a09d1c16986bd 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1113,8 +1113,7 @@ impl<'tcx> TyCtxt<'tcx> { }; let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default(); - for (k, v) in resolutions.trait_map { - let hir_id = definitions.node_id_to_hir_id(k); + for (hir_id, v) in resolutions.trait_map.into_iter() { let map = trait_map.entry(hir_id.owner).or_default(); let v = v .into_iter() diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 36bc44f5e5032..4b9f77b4b4b57 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -31,7 +31,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem}; -use rustc_hir::{Constness, GlobMap, Node, TraitMap}; +use rustc_hir::{Constness, GlobMap, Node}; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; use rustc_serialize::{self, Encodable, Encoder}; @@ -121,7 +121,7 @@ pub struct ResolverOutputs { pub definitions: rustc_hir::definitions::Definitions, pub cstore: Box, pub extern_crate_map: NodeMap, - pub trait_map: TraitMap, + pub trait_map: FxHashMap>>, pub maybe_unused_trait_imports: NodeSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, pub export_map: ExportMap, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index bfb7f081fc333..625ca5dec5083 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1,3 +1,5 @@ +// ignore-tidy-filelength + //! This crate is responsible for the part of name resolution that doesn't require type checker. //! //! Module structure of the crate is built here. @@ -1271,12 +1273,19 @@ impl<'a> Resolver<'a> { } pub fn into_outputs(self) -> ResolverOutputs { + let trait_map = { + let mut map = FxHashMap::default(); + for (k, v) in self.trait_map.into_iter() { + map.insert(self.definitions.node_id_to_hir_id(k), v); + } + map + }; ResolverOutputs { definitions: self.definitions, cstore: Box::new(self.crate_loader.into_cstore()), extern_crate_map: self.extern_crate_map, export_map: self.export_map, - trait_map: self.trait_map, + trait_map, glob_map: self.glob_map, maybe_unused_trait_imports: self.maybe_unused_trait_imports, maybe_unused_extern_crates: self.maybe_unused_extern_crates, @@ -1294,7 +1303,13 @@ impl<'a> Resolver<'a> { cstore: Box::new(self.cstore().clone()), extern_crate_map: self.extern_crate_map.clone(), export_map: self.export_map.clone(), - trait_map: self.trait_map.clone(), + trait_map: { + let mut map = FxHashMap::default(); + for (k, v) in self.trait_map.iter() { + map.insert(self.definitions.node_id_to_hir_id(k.clone()), v.clone()); + } + map + }, glob_map: self.glob_map.clone(), maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(), maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(), From 3c5dba7c6214b2a27d4d976419ab3036ec7ae473 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 21:52:30 +0100 Subject: [PATCH 02/13] Use `HirId` in value of `ResolverOutputs::trait_map` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 4 ---- src/librustc_middle/ty/mod.rs | 2 +- src/librustc_resolve/lib.rs | 20 +++++++++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index a09d1c16986bd..8b96b0eaab3c5 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1115,10 +1115,6 @@ impl<'tcx> TyCtxt<'tcx> { let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default(); for (hir_id, v) in resolutions.trait_map.into_iter() { let map = trait_map.entry(hir_id.owner).or_default(); - let v = v - .into_iter() - .map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id))) - .collect(); map.insert(hir_id.local_id, StableVec::new(v)); } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 4b9f77b4b4b57..46715b8e737a9 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -121,7 +121,7 @@ pub struct ResolverOutputs { pub definitions: rustc_hir::definitions::Definitions, pub cstore: Box, pub extern_crate_map: NodeMap, - pub trait_map: FxHashMap>>, + pub trait_map: FxHashMap>>, pub maybe_unused_trait_imports: NodeSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, pub export_map: ExportMap, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 625ca5dec5083..0b6b1fbdc34a0 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1273,15 +1273,21 @@ impl<'a> Resolver<'a> { } pub fn into_outputs(self) -> ResolverOutputs { + let definitions = self.definitions; let trait_map = { let mut map = FxHashMap::default(); for (k, v) in self.trait_map.into_iter() { - map.insert(self.definitions.node_id_to_hir_id(k), v); + map.insert( + definitions.node_id_to_hir_id(k), + v.into_iter() + .map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id))) + .collect(), + ); } map }; ResolverOutputs { - definitions: self.definitions, + definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), extern_crate_map: self.extern_crate_map, export_map: self.export_map, @@ -1306,7 +1312,15 @@ impl<'a> Resolver<'a> { trait_map: { let mut map = FxHashMap::default(); for (k, v) in self.trait_map.iter() { - map.insert(self.definitions.node_id_to_hir_id(k.clone()), v.clone()); + map.insert( + self.definitions.node_id_to_hir_id(k.clone()), + v.iter() + .map(|tc| { + tc.clone() + .map_import_ids(|id| self.definitions.node_id_to_hir_id(id)) + }) + .collect(), + ); } map }, From 52359f7c609ef3908c9fc6faf3d0e36f02c6d207 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 22:54:12 +0100 Subject: [PATCH 03/13] Use `HirId` in `ResolverOutputs::export_map` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 12 +----------- src/librustc_middle/ty/mod.rs | 2 +- src/librustc_resolve/lib.rs | 27 +++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 8b96b0eaab3c5..fffc286c8f6f7 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1131,17 +1131,7 @@ impl<'tcx> TyCtxt<'tcx> { consts: common_consts, extern_crate_map: resolutions.extern_crate_map, trait_map, - export_map: resolutions - .export_map - .into_iter() - .map(|(k, v)| { - let exports: Vec<_> = v - .into_iter() - .map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id))) - .collect(); - (k, exports) - }) - .collect(), + export_map: resolutions.export_map, maybe_unused_trait_imports: resolutions .maybe_unused_trait_imports .into_iter() diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 46715b8e737a9..820aa457d7c0f 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -124,7 +124,7 @@ pub struct ResolverOutputs { pub trait_map: FxHashMap>>, pub maybe_unused_trait_imports: NodeSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, - pub export_map: ExportMap, + pub export_map: ExportMap, pub glob_map: GlobMap, /// Extern prelude entries. The value is `true` if the entry was introduced /// via `extern crate` item and not `--extern` option or compiler built-in. diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0b6b1fbdc34a0..db9af9a0c4be1 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1274,6 +1274,18 @@ impl<'a> Resolver<'a> { pub fn into_outputs(self) -> ResolverOutputs { let definitions = self.definitions; + let export_map = { + let mut map = FxHashMap::default(); + for (k, v) in self.export_map.into_iter() { + map.insert( + k, + v.into_iter() + .map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id))) + .collect(), + ); + } + map + }; let trait_map = { let mut map = FxHashMap::default(); for (k, v) in self.trait_map.into_iter() { @@ -1290,7 +1302,7 @@ impl<'a> Resolver<'a> { definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), extern_crate_map: self.extern_crate_map, - export_map: self.export_map, + export_map, trait_map, glob_map: self.glob_map, maybe_unused_trait_imports: self.maybe_unused_trait_imports, @@ -1308,7 +1320,18 @@ impl<'a> Resolver<'a> { definitions: self.definitions.clone(), cstore: Box::new(self.cstore().clone()), extern_crate_map: self.extern_crate_map.clone(), - export_map: self.export_map.clone(), + export_map: { + let mut map = FxHashMap::default(); + for (k, v) in self.export_map.iter() { + map.insert( + k.clone(), + v.iter() + .map(|e| e.clone().map_id(|id| self.definitions.node_id_to_hir_id(id))) + .collect(), + ); + } + map + }, trait_map: { let mut map = FxHashMap::default(); for (k, v) in self.trait_map.iter() { From 13c86f289ba0d2944da320fd6c0359a591ce4374 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 23:01:48 +0100 Subject: [PATCH 04/13] Use `LocalDefId` in `ResolverOutputs::maybe_unused_trait_imports` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 6 +----- src/librustc_middle/ty/mod.rs | 5 +++-- src/librustc_resolve/lib.rs | 13 +++++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index fffc286c8f6f7..d090f9235ce33 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1132,11 +1132,7 @@ impl<'tcx> TyCtxt<'tcx> { extern_crate_map: resolutions.extern_crate_map, trait_map, export_map: resolutions.export_map, - maybe_unused_trait_imports: resolutions - .maybe_unused_trait_imports - .into_iter() - .map(|id| definitions.local_def_id(id)) - .collect(), + maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports, maybe_unused_extern_crates: resolutions .maybe_unused_extern_crates .into_iter() diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 820aa457d7c0f..4dc815fa7bcd0 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -17,11 +17,12 @@ use crate::ty; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use rustc_ast::ast; -use rustc_ast::node_id::{NodeId, NodeMap, NodeSet}; +use rustc_ast::node_id::{NodeId, NodeMap}; use rustc_attr as attr; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sorted_map::SortedIndexMultiMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -122,7 +123,7 @@ pub struct ResolverOutputs { pub cstore: Box, pub extern_crate_map: NodeMap, pub trait_map: FxHashMap>>, - pub maybe_unused_trait_imports: NodeSet, + pub maybe_unused_trait_imports: FxHashSet, pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, pub export_map: ExportMap, pub glob_map: GlobMap, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index db9af9a0c4be1..21a535b85aac7 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1298,6 +1298,11 @@ impl<'a> Resolver<'a> { } map }; + let maybe_unused_trait_imports = self + .maybe_unused_trait_imports + .into_iter() + .map(|id| definitions.local_def_id(id)) + .collect(); ResolverOutputs { definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), @@ -1305,7 +1310,7 @@ impl<'a> Resolver<'a> { export_map, trait_map, glob_map: self.glob_map, - maybe_unused_trait_imports: self.maybe_unused_trait_imports, + maybe_unused_trait_imports, maybe_unused_extern_crates: self.maybe_unused_extern_crates, extern_prelude: self .extern_prelude @@ -1348,7 +1353,11 @@ impl<'a> Resolver<'a> { map }, glob_map: self.glob_map.clone(), - maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(), + maybe_unused_trait_imports: self + .maybe_unused_trait_imports + .iter() + .map(|id| self.definitions.local_def_id(id.clone())) + .collect(), maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(), extern_prelude: self .extern_prelude From 25f575b29f467d2bb7aff9be359743414d218dfa Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 23:11:56 +0100 Subject: [PATCH 05/13] Use `DefId` in `ResolverOutputs::maybe_unused_extern_crates` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 6 +----- src/librustc_middle/ty/mod.rs | 4 ++-- src/librustc_resolve/lib.rs | 13 +++++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d090f9235ce33..fc77df51aa855 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1133,11 +1133,7 @@ impl<'tcx> TyCtxt<'tcx> { trait_map, export_map: resolutions.export_map, maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports, - maybe_unused_extern_crates: resolutions - .maybe_unused_extern_crates - .into_iter() - .map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp)) - .collect(), + maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates, glob_map: resolutions .glob_map .into_iter() diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 4dc815fa7bcd0..550016ce81b48 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -17,7 +17,7 @@ use crate::ty; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use rustc_ast::ast; -use rustc_ast::node_id::{NodeId, NodeMap}; +use rustc_ast::node_id::NodeMap; use rustc_attr as attr; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; @@ -124,7 +124,7 @@ pub struct ResolverOutputs { pub extern_crate_map: NodeMap, pub trait_map: FxHashMap>>, pub maybe_unused_trait_imports: FxHashSet, - pub maybe_unused_extern_crates: Vec<(NodeId, Span)>, + pub maybe_unused_extern_crates: Vec<(DefId, Span)>, pub export_map: ExportMap, pub glob_map: GlobMap, /// Extern prelude entries. The value is `true` if the entry was introduced diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 21a535b85aac7..b3a668f00ff0e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1303,6 +1303,11 @@ impl<'a> Resolver<'a> { .into_iter() .map(|id| definitions.local_def_id(id)) .collect(); + let maybe_unused_extern_crates = self + .maybe_unused_extern_crates + .into_iter() + .map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp)) + .collect(); ResolverOutputs { definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), @@ -1311,7 +1316,7 @@ impl<'a> Resolver<'a> { trait_map, glob_map: self.glob_map, maybe_unused_trait_imports, - maybe_unused_extern_crates: self.maybe_unused_extern_crates, + maybe_unused_extern_crates, extern_prelude: self .extern_prelude .iter() @@ -1358,7 +1363,11 @@ impl<'a> Resolver<'a> { .iter() .map(|id| self.definitions.local_def_id(id.clone())) .collect(), - maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(), + maybe_unused_extern_crates: self + .maybe_unused_extern_crates + .iter() + .map(|(id, sp)| (self.definitions.local_def_id(id.clone()).to_def_id(), sp.clone())) + .collect(), extern_prelude: self .extern_prelude .iter() From 21f65ae9db20c2019e9e4989754894d9ee7680ce Mon Sep 17 00:00:00 2001 From: marmeladema Date: Wed, 20 May 2020 23:18:45 +0100 Subject: [PATCH 06/13] Use `DefId` in `ResolverOutputs::glob_map` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 6 +----- src/librustc_middle/ty/mod.rs | 4 ++-- src/librustc_resolve/lib.rs | 13 +++++++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index fc77df51aa855..ad43f8c25b2cc 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1134,11 +1134,7 @@ impl<'tcx> TyCtxt<'tcx> { export_map: resolutions.export_map, maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports, maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates, - glob_map: resolutions - .glob_map - .into_iter() - .map(|(id, names)| (definitions.local_def_id(id), names)) - .collect(), + glob_map: resolutions.glob_map, extern_prelude: resolutions.extern_prelude, untracked_crate: krate, definitions, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 550016ce81b48..f246d8cf4c09d 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -32,7 +32,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; use rustc_hir::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem}; -use rustc_hir::{Constness, GlobMap, Node}; +use rustc_hir::{Constness, Node}; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; use rustc_serialize::{self, Encodable, Encoder}; @@ -126,7 +126,7 @@ pub struct ResolverOutputs { pub maybe_unused_trait_imports: FxHashSet, pub maybe_unused_extern_crates: Vec<(DefId, Span)>, pub export_map: ExportMap, - pub glob_map: GlobMap, + pub glob_map: FxHashMap>, /// Extern prelude entries. The value is `true` if the entry was introduced /// via `extern crate` item and not `--extern` option or compiler built-in. pub extern_prelude: FxHashMap, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index b3a668f00ff0e..03fc6a6ab4b16 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1308,13 +1308,18 @@ impl<'a> Resolver<'a> { .into_iter() .map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp)) .collect(); + let glob_map = self + .glob_map + .into_iter() + .map(|(id, names)| (definitions.local_def_id(id), names)) + .collect(); ResolverOutputs { definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), extern_crate_map: self.extern_crate_map, export_map, trait_map, - glob_map: self.glob_map, + glob_map, maybe_unused_trait_imports, maybe_unused_extern_crates, extern_prelude: self @@ -1357,7 +1362,11 @@ impl<'a> Resolver<'a> { } map }, - glob_map: self.glob_map.clone(), + glob_map: self + .glob_map + .iter() + .map(|(id, names)| (self.definitions.local_def_id(id.clone()), names.clone())) + .collect(), maybe_unused_trait_imports: self .maybe_unused_trait_imports .iter() From 8ff6ffd88897c29a494b1dcabd5bd98b9cde0a39 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Thu, 21 May 2020 00:08:49 +0100 Subject: [PATCH 07/13] Use `DefId` in `ResolverOutputs::extern_crate_map` instead of `NodeId` --- src/librustc_middle/ty/context.rs | 8 ++------ src/librustc_middle/ty/mod.rs | 3 +-- src/librustc_resolve/lib.rs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index ad43f8c25b2cc..6a46a83a412a0 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -34,7 +34,6 @@ use crate::ty::{InferConst, ParamConst}; use crate::ty::{List, TyKind, TyS}; use rustc_ast::ast; use rustc_ast::expand::allocator::AllocatorKind; -use rustc_ast::node_id::NodeMap; use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; @@ -923,7 +922,7 @@ pub struct GlobalCtxt<'tcx> { pub consts: CommonConsts<'tcx>, /// Resolutions of `extern crate` items produced by resolver. - extern_crate_map: NodeMap, + extern_crate_map: FxHashMap, /// Map indicating what traits are in scope for places where this /// is relevant; generated by resolve. @@ -2682,10 +2681,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { let id = tcx.hir().local_def_id_to_hir_id(id.expect_local()); tcx.stability().local_deprecation_entry(id) }; - providers.extern_mod_stmt_cnum = |tcx, id| { - let id = tcx.hir().as_local_node_id(id).unwrap(); - tcx.extern_crate_map.get(&id).cloned() - }; + providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned(); providers.all_crate_nums = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); tcx.arena.alloc_slice(&tcx.cstore.crates_untracked()) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index f246d8cf4c09d..73b4074bd6205 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -17,7 +17,6 @@ use crate::ty; use crate::ty::subst::{InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use rustc_ast::ast; -use rustc_ast::node_id::NodeMap; use rustc_attr as attr; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; @@ -121,7 +120,7 @@ mod sty; pub struct ResolverOutputs { pub definitions: rustc_hir::definitions::Definitions, pub cstore: Box, - pub extern_crate_map: NodeMap, + pub extern_crate_map: FxHashMap, pub trait_map: FxHashMap>>, pub maybe_unused_trait_imports: FxHashSet, pub maybe_unused_extern_crates: Vec<(DefId, Span)>, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 03fc6a6ab4b16..d09b5b5d701d2 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1274,6 +1274,13 @@ impl<'a> Resolver<'a> { pub fn into_outputs(self) -> ResolverOutputs { let definitions = self.definitions; + let extern_crate_map = { + let mut map = FxHashMap::default(); + for (k, v) in self.extern_crate_map.into_iter() { + map.insert(definitions.local_def_id(k).to_def_id(), v); + } + map + }; let export_map = { let mut map = FxHashMap::default(); for (k, v) in self.export_map.into_iter() { @@ -1316,7 +1323,7 @@ impl<'a> Resolver<'a> { ResolverOutputs { definitions: definitions, cstore: Box::new(self.crate_loader.into_cstore()), - extern_crate_map: self.extern_crate_map, + extern_crate_map, export_map, trait_map, glob_map, @@ -1334,7 +1341,13 @@ impl<'a> Resolver<'a> { ResolverOutputs { definitions: self.definitions.clone(), cstore: Box::new(self.cstore().clone()), - extern_crate_map: self.extern_crate_map.clone(), + extern_crate_map: { + let mut map = FxHashMap::default(); + for (k, v) in self.extern_crate_map.iter() { + map.insert(self.definitions.local_def_id(k.clone()).to_def_id(), v.clone()); + } + map + }, export_map: { let mut map = FxHashMap::default(); for (k, v) in self.export_map.iter() { From 4c4cb464912b82f08e4144b88dd4a0dc1a671a7e Mon Sep 17 00:00:00 2001 From: marmeladema Date: Thu, 21 May 2020 01:02:15 +0100 Subject: [PATCH 08/13] Use `collect()` instead of manually inserting elements into maps --- src/librustc_resolve/lib.rs | 88 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d09b5b5d701d2..bd4cb89939e1d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1274,37 +1274,35 @@ impl<'a> Resolver<'a> { pub fn into_outputs(self) -> ResolverOutputs { let definitions = self.definitions; - let extern_crate_map = { - let mut map = FxHashMap::default(); - for (k, v) in self.extern_crate_map.into_iter() { - map.insert(definitions.local_def_id(k).to_def_id(), v); - } - map - }; - let export_map = { - let mut map = FxHashMap::default(); - for (k, v) in self.export_map.into_iter() { - map.insert( + let extern_crate_map = self + .extern_crate_map + .into_iter() + .map(|(k, v)| (definitions.local_def_id(k).to_def_id(), v)) + .collect(); + let export_map = self + .export_map + .into_iter() + .map(|(k, v)| { + ( k, v.into_iter() .map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id))) .collect(), - ); - } - map - }; - let trait_map = { - let mut map = FxHashMap::default(); - for (k, v) in self.trait_map.into_iter() { - map.insert( + ) + }) + .collect(); + let trait_map = self + .trait_map + .into_iter() + .map(|(k, v)| { + ( definitions.node_id_to_hir_id(k), v.into_iter() .map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id))) .collect(), - ); - } - map - }; + ) + }) + .collect(); let maybe_unused_trait_imports = self .maybe_unused_trait_imports .into_iter() @@ -1341,29 +1339,28 @@ impl<'a> Resolver<'a> { ResolverOutputs { definitions: self.definitions.clone(), cstore: Box::new(self.cstore().clone()), - extern_crate_map: { - let mut map = FxHashMap::default(); - for (k, v) in self.extern_crate_map.iter() { - map.insert(self.definitions.local_def_id(k.clone()).to_def_id(), v.clone()); - } - map - }, - export_map: { - let mut map = FxHashMap::default(); - for (k, v) in self.export_map.iter() { - map.insert( + extern_crate_map: self + .extern_crate_map + .iter() + .map(|(k, v)| (self.definitions.local_def_id(k.clone()).to_def_id(), v.clone())) + .collect(), + export_map: self + .export_map + .iter() + .map(|(k, v)| { + ( k.clone(), v.iter() .map(|e| e.clone().map_id(|id| self.definitions.node_id_to_hir_id(id))) .collect(), - ); - } - map - }, - trait_map: { - let mut map = FxHashMap::default(); - for (k, v) in self.trait_map.iter() { - map.insert( + ) + }) + .collect(), + trait_map: self + .trait_map + .iter() + .map(|(k, v)| { + ( self.definitions.node_id_to_hir_id(k.clone()), v.iter() .map(|tc| { @@ -1371,10 +1368,9 @@ impl<'a> Resolver<'a> { .map_import_ids(|id| self.definitions.node_id_to_hir_id(id)) }) .collect(), - ); - } - map - }, + ) + }) + .collect(), glob_map: self .glob_map .iter() From f31e076d98e3b6f457f975a0dcba9c4b0f43fc91 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Thu, 21 May 2020 17:34:54 +0100 Subject: [PATCH 09/13] Replace unecessary calls to `.clone()` by argument binding pattern for `Copy` types --- src/librustc_resolve/lib.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index bd4cb89939e1d..9699aff69c013 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1342,16 +1342,16 @@ impl<'a> Resolver<'a> { extern_crate_map: self .extern_crate_map .iter() - .map(|(k, v)| (self.definitions.local_def_id(k.clone()).to_def_id(), v.clone())) + .map(|(&k, &v)| (self.definitions.local_def_id(k).to_def_id(), v)) .collect(), export_map: self .export_map .iter() - .map(|(k, v)| { + .map(|(&k, v)| { ( - k.clone(), + k, v.iter() - .map(|e| e.clone().map_id(|id| self.definitions.node_id_to_hir_id(id))) + .map(|e| e.map_id(|id| self.definitions.node_id_to_hir_id(id))) .collect(), ) }) @@ -1359,13 +1359,13 @@ impl<'a> Resolver<'a> { trait_map: self .trait_map .iter() - .map(|(k, v)| { + .map(|(&k, v)| { ( - self.definitions.node_id_to_hir_id(k.clone()), + self.definitions.node_id_to_hir_id(k), v.iter() + .cloned() .map(|tc| { - tc.clone() - .map_import_ids(|id| self.definitions.node_id_to_hir_id(id)) + tc.map_import_ids(|id| self.definitions.node_id_to_hir_id(id)) }) .collect(), ) @@ -1374,17 +1374,17 @@ impl<'a> Resolver<'a> { glob_map: self .glob_map .iter() - .map(|(id, names)| (self.definitions.local_def_id(id.clone()), names.clone())) + .map(|(&id, names)| (self.definitions.local_def_id(id), names.clone())) .collect(), maybe_unused_trait_imports: self .maybe_unused_trait_imports .iter() - .map(|id| self.definitions.local_def_id(id.clone())) + .map(|&id| self.definitions.local_def_id(id)) .collect(), maybe_unused_extern_crates: self .maybe_unused_extern_crates .iter() - .map(|(id, sp)| (self.definitions.local_def_id(id.clone()).to_def_id(), sp.clone())) + .map(|&(id, sp)| (self.definitions.local_def_id(id).to_def_id(), sp)) .collect(), extern_prelude: self .extern_prelude From 7a121ad77f0c9b501d127e23af4c53b5a9fd85ee Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 24 May 2020 09:45:14 +0200 Subject: [PATCH 10/13] bootstrap: propagate test-args to miri and clippy test suites --- src/bootstrap/test.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 96196a80be466..ed50f950fb697 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -439,6 +439,8 @@ impl Step for Miri { cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler)); cargo.env("MIRI_PATH", miri); + cargo.arg("--").args(builder.config.cmd.test_args()); + builder.add_rustc_lib_path(compiler, &mut cargo); if !try_run(builder, &mut cargo.into()) { @@ -545,6 +547,8 @@ impl Step for Clippy { // clippy tests need to find the driver cargo.env("CLIPPY_DRIVER_PATH", clippy); + cargo.arg("--").args(builder.config.cmd.test_args()); + builder.add_rustc_lib_path(compiler, &mut cargo); try_run(builder, &mut cargo.into()); From 2220eb4d8a06cae7c23b733dee17ebad477cca25 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 24 May 2020 12:52:45 +0200 Subject: [PATCH 11/13] Clean up E0602 explanation --- src/librustc_error_codes/error_codes/E0602.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0602.md b/src/librustc_error_codes/error_codes/E0602.md index ca7138a60cc4e..dcaf251a96b5b 100644 --- a/src/librustc_error_codes/error_codes/E0602.md +++ b/src/librustc_error_codes/error_codes/E0602.md @@ -1,9 +1,9 @@ An unknown lint was used on the command line. -Erroneous example: +Erroneous code example: ```sh -rustc -D bogus omse_file.rs +rustc -D bogus rust_file.rs ``` Maybe you just misspelled the lint name or the lint doesn't exist anymore. From d1f4796845d6a1ce00367a3f8af2bb11790687f9 Mon Sep 17 00:00:00 2001 From: ratijas Date: Sun, 24 May 2020 14:46:50 +0300 Subject: [PATCH 12/13] Use `dyn` trait syntax in more comments and docs Probably missed it out during earlier `dyn` refactoring. --- src/libcore/raw.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index cb0fb8795e581..741a9dc8797be 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -9,15 +9,15 @@ //! Their definition should always match the ABI defined in //! `rustc_middle::ty::layout`. -/// The representation of a trait object like `&SomeTrait`. +/// The representation of a trait object like `&dyn SomeTrait`. /// -/// This struct has the same layout as types like `&SomeTrait` and +/// This struct has the same layout as types like `&dyn SomeTrait` and /// `Box`. /// /// `TraitObject` is guaranteed to match layouts, but it is not the /// type of trait objects (e.g., the fields are not directly accessible -/// on a `&SomeTrait`) nor does it control that layout (changing the -/// definition will not change the layout of a `&SomeTrait`). It is +/// on a `&dyn SomeTrait`) nor does it control that layout (changing the +/// definition will not change the layout of a `&dyn SomeTrait`). It is /// only designed to be used by unsafe code that needs to manipulate /// the low-level details. /// From df2f9a4bd11b2067379c0c97eca3a249fe67fc17 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 24 May 2020 14:56:57 +0200 Subject: [PATCH 13/13] Use sort_unstable_by in its own docs --- src/libcore/slice/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index b5ce165cb43db..2361749f16645 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1654,7 +1654,7 @@ impl [T] { /// /// ``` /// let mut floats = [5f64, 4.0, 1.0, 3.0, 2.0]; - /// floats.sort_by(|a, b| a.partial_cmp(b).unwrap()); + /// floats.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap()); /// assert_eq!(floats, [1.0, 2.0, 3.0, 4.0, 5.0]); /// ``` ///