]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_metadata/rmeta/decoder.rs
mir: use `FiniteBitSet<u32>` in polymorphization
[rust.git] / src / librustc_metadata / rmeta / decoder.rs
index df4bb2502cbebcaaef99932e391d0185ec297fdd..10dc407c060fe0f890582927497e9bed3b54643a 100644 (file)
     /// Same ID set as `cnum_map` plus maybe some injected crates like panic runtime.
     dependencies: Lock<Vec<CrateNum>>,
     /// How to link (or not link) this crate to the currently compiled crate.
-    dep_kind: Lock<DepKind>,
+    dep_kind: Lock<CrateDepKind>,
     /// Filesystem location of this crate.
     source: CrateSource,
     /// Whether or not this crate should be consider a private dependency
@@ -780,7 +780,6 @@ fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
 
     fn get_variant(
         &self,
-        tcx: TyCtxt<'tcx>,
         kind: &EntryKind,
         index: DefIndex,
         parent_did: DefId,
@@ -805,7 +804,6 @@ fn get_variant(
         let ctor_did = data.ctor.map(|index| self.local_def_id(index));
 
         ty::VariantDef::new(
-            tcx,
             self.item_ident(index, sess),
             variant_did,
             ctor_did,
@@ -826,6 +824,7 @@ fn get_variant(
             adt_kind,
             parent_did,
             false,
+            data.is_non_exhaustive,
         )
     }
 
@@ -847,10 +846,10 @@ fn get_adt_def(&self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> &'tcx ty::AdtDef
                 .get(self, item_id)
                 .unwrap_or(Lazy::empty())
                 .decode(self)
-                .map(|index| self.get_variant(tcx, &self.kind(index), index, did, tcx.sess))
+                .map(|index| self.get_variant(&self.kind(index), index, did, tcx.sess))
                 .collect()
         } else {
-            std::iter::once(self.get_variant(tcx, &kind, item_id, did, tcx.sess)).collect()
+            std::iter::once(self.get_variant(&kind, item_id, did, tcx.sess)).collect()
         };
 
         tcx.alloc_adt_def(did, adt_kind, variants, repr)
@@ -1151,7 +1150,7 @@ fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
             .decode((self, tcx))
     }
 
-    fn get_unused_generic_params(&self, id: DefIndex) -> FiniteBitSet<u64> {
+    fn get_unused_generic_params(&self, id: DefIndex) -> FiniteBitSet<u32> {
         self.root
             .tables
             .unused_generic_params
@@ -1503,6 +1502,9 @@ fn def_path(&self, id: DefIndex) -> DefPath {
     fn imported_source_files(&self, sess: &Session) -> &'a [ImportedSourceFile] {
         // Translate the virtual `/rustc/$hash` prefix back to a real directory
         // that should hold actual sources, where possible.
+        //
+        // NOTE: if you update this, you might need to also update bootstrap's code for generating
+        // the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`.
         let virtual_rust_source_base_dir = option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR")
             .map(Path::new)
             .filter(|_| {
@@ -1528,7 +1530,36 @@ fn imported_source_files(&self, sess: &Session) -> &'a [ImportedSourceFile] {
                         if let rustc_span::RealFileName::Named(one_path) = old_name {
                             if let Ok(rest) = one_path.strip_prefix(virtual_dir) {
                                 let virtual_name = one_path.clone();
-                                let new_path = real_dir.join(rest);
+
+                                // The std library crates are in
+                                // `$sysroot/lib/rustlib/src/rust/library`, whereas other crates
+                                // may be in `$sysroot/lib/rustlib/src/rust/` directly. So we
+                                // detect crates from the std libs and handle them specially.
+                                const STD_LIBS: &[&str] = &[
+                                    "core",
+                                    "alloc",
+                                    "std",
+                                    "test",
+                                    "term",
+                                    "unwind",
+                                    "proc_macro",
+                                    "panic_abort",
+                                    "panic_unwind",
+                                    "profiler_builtins",
+                                    "rtstartup",
+                                    "rustc-std-workspace-core",
+                                    "rustc-std-workspace-alloc",
+                                    "rustc-std-workspace-std",
+                                    "backtrace",
+                                ];
+                                let is_std_lib = STD_LIBS.iter().any(|l| rest.starts_with(l));
+
+                                let new_path = if is_std_lib {
+                                    real_dir.join("library").join(rest)
+                                } else {
+                                    real_dir.join(rest)
+                                };
+
                                 debug!(
                                     "try_to_translate_virtual_to_real: `{}` -> `{}`",
                                     virtual_name.display(),
@@ -1638,7 +1669,7 @@ impl CrateMetadata {
         raw_proc_macros: Option<&'static [ProcMacro]>,
         cnum: CrateNum,
         cnum_map: CrateNumMap,
-        dep_kind: DepKind,
+        dep_kind: CrateDepKind,
         source: CrateSource,
         private_dep: bool,
         host_hash: Option<Svh>,
@@ -1696,11 +1727,11 @@ impl CrateMetadata {
         &self.source
     }
 
-    crate fn dep_kind(&self) -> DepKind {
+    crate fn dep_kind(&self) -> CrateDepKind {
         *self.dep_kind.lock()
     }
 
-    crate fn update_dep_kind(&self, f: impl FnOnce(DepKind) -> DepKind) {
+    crate fn update_dep_kind(&self, f: impl FnOnce(CrateDepKind) -> CrateDepKind) {
         self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
     }