Skip to content

Commit 8b3ee9f

Browse files
committed
rustc_public: Make CrateNum a newtype.
1 parent f2eb25e commit 8b3ee9f

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

compiler/rustc_public/src/compiler_interface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::ty::{
2525
use crate::unstable::{RustcInternal, Stable, new_item_kind};
2626
use crate::{
2727
AssocItems, Crate, CrateDef, CrateItem, CrateItems, CrateNum, DefId, Error, Filename,
28-
ImplTraitDecls, ItemKind, ReferencesTls, Symbol, TraitDecls, alloc, mir,
28+
ImplTraitDecls, ItemKind, Symbol, TraitDecls, alloc, mir,
2929
};
3030

3131
pub struct BridgeTys;
@@ -1093,7 +1093,7 @@ fn smir_crate<'tcx>(
10931093
) -> Crate {
10941094
let name = cx.crate_name(crate_num);
10951095
let is_local = cx.crate_is_local(crate_num);
1096-
let id = cx.crate_num_id(crate_num);
1096+
let id = CrateNum(cx.crate_num_id(crate_num));
10971097
debug!(?name, ?crate_num, "smir_crate");
1098-
Crate { id, name, is_local, references_tls: ReferencesTLS }
1098+
Crate { id, name, is_local }
10991099
}

compiler/rustc_public/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use std::fmt::Debug;
2323
use std::marker::PhantomData;
2424
use std::{fmt, io};
2525

26-
use rustc_public_bridge::context::CompilerCtxt;
2726
pub(crate) use rustc_public_bridge::IndexedVal;
2827
use rustc_public_bridge::Tables;
28+
use rustc_public_bridge::context::CompilerCtxt;
2929
/// Export the rustc_internal APIs. Note that this module has no stability
3030
/// guarantees and it is not taken into account for semver.
3131
#[cfg(feature = "rustc_internal")]
@@ -57,8 +57,8 @@ pub mod visitor;
5757
pub type Symbol = String;
5858

5959
/// The number that identifies a crate.
60-
// FIXME: Make this a newtype, so it can have a `ReferencesTls`
61-
pub type CrateNum = usize;
60+
#[derive(Clone, Copy, Serialize, PartialEq, Eq, Debug)]
61+
pub struct CrateNum(pub(crate) usize, ThreadLocalIndex);
6262

6363
impl Debug for DefId {
6464
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -84,9 +84,6 @@ pub struct Crate {
8484
pub id: CrateNum,
8585
pub name: Symbol,
8686
pub is_local: bool,
87-
// FIXME: Remove this when `CrateNum` holds `ReferencesTLS`
88-
#[serde(skip)]
89-
references_tls: ReferencesTls,
9087
}
9188

9289
impl Crate {

compiler/rustc_public/src/rustc_internal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ where
5353
}
5454

5555
pub fn crate_num(item: &crate::Crate) -> CrateNum {
56-
item.id.into()
56+
CrateNum::from_u32(item.id.0)
5757
}
5858

5959
// A thread local variable that stores a pointer to the tables mapping between TyCtxt

compiler/rustc_public/src/unstable/convert/internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl RustcInternal for CrateNum {
4040
_tables: &mut Tables<'_, BridgeTys>,
4141
_tcx: impl InternalCx<'tcx>,
4242
) -> Self::T<'tcx> {
43-
rustc_span::def_id::CrateNum::from_usize(*self)
43+
rustc_span::def_id::CrateNum::from_usize(self.0)
4444
}
4545
}
4646

0 commit comments

Comments
 (0)