Skip to content

Commit dfabe4b

Browse files
committed
Auto merge of #54032 - oli-obk:layout_scalar_ranges, r=eddyb
Add forever unstable attribute to allow specifying arbitrary scalar ranges r? @eddyb for the first commit and @nikomatsakis for the second one
2 parents fccde00 + a94c166 commit dfabe4b

File tree

23 files changed

+279
-161
lines changed

23 files changed

+279
-161
lines changed

src/libcore/nonzero.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use ops::CoerceUnsized;
1414

1515
/// A wrapper type for raw pointers and integers that will never be
1616
/// NULL or 0 that might allow certain optimizations.
17-
#[lang = "non_zero"]
17+
#[cfg_attr(stage0, lang = "non_zero")]
18+
#[cfg_attr(not(stage0), rustc_layout_scalar_valid_range_start(1))]
1819
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1920
#[repr(transparent)]
2021
pub(crate) struct NonZero<T>(pub(crate) T);

src/librustc/hir/def_id.rs

+70-15
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,53 @@ use std::fmt;
1616
use std::u32;
1717

1818
newtype_index! {
19-
pub struct CrateNum {
19+
pub struct CrateId {
2020
ENCODABLE = custom
21-
DEBUG_FORMAT = "crate{}",
21+
}
22+
}
23+
24+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
25+
pub enum CrateNum {
26+
/// Virtual crate for builtin macros
27+
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get
28+
// `CrateNum`s.
29+
BuiltinMacros,
30+
/// A CrateNum value that indicates that something is wrong.
31+
Invalid,
32+
/// A special CrateNum that we use for the tcx.rcache when decoding from
33+
/// the incr. comp. cache.
34+
ReservedForIncrCompCache,
35+
Index(CrateId),
36+
}
37+
38+
impl ::std::fmt::Debug for CrateNum {
39+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
40+
match self {
41+
CrateNum::Index(id) => write!(fmt, "crate{}", id.private),
42+
CrateNum::Invalid => write!(fmt, "invalid crate"),
43+
CrateNum::BuiltinMacros => write!(fmt, "bultin macros crate"),
44+
CrateNum::ReservedForIncrCompCache => write!(fmt, "crate for decoding incr comp cache"),
45+
}
46+
}
47+
}
2248

23-
/// Item definitions in the currently-compiled crate would have the CrateNum
24-
/// LOCAL_CRATE in their DefId.
25-
const LOCAL_CRATE = 0,
49+
/// Item definitions in the currently-compiled crate would have the CrateNum
50+
/// LOCAL_CRATE in their DefId.
51+
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0));
2652

27-
/// Virtual crate for builtin macros
28-
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get
29-
// `CrateNum`s.
30-
const BUILTIN_MACROS_CRATE = CrateNum::MAX_AS_U32,
3153

32-
/// A CrateNum value that indicates that something is wrong.
33-
const INVALID_CRATE = CrateNum::MAX_AS_U32 - 1,
54+
impl Idx for CrateNum {
55+
#[inline]
56+
fn new(value: usize) -> Self {
57+
CrateNum::Index(Idx::new(value))
58+
}
3459

35-
/// A special CrateNum that we use for the tcx.rcache when decoding from
36-
/// the incr. comp. cache.
37-
const RESERVED_FOR_INCR_COMP_CACHE = CrateNum::MAX_AS_U32 - 2,
60+
#[inline]
61+
fn index(self) -> usize {
62+
match self {
63+
CrateNum::Index(idx) => Idx::index(idx),
64+
_ => bug!("Tried to get crate index of {:?}", self),
65+
}
3866
}
3967
}
4068

@@ -43,12 +71,39 @@ impl CrateNum {
4371
CrateNum::from_usize(x)
4472
}
4573

74+
pub fn from_usize(x: usize) -> CrateNum {
75+
CrateNum::Index(CrateId::from_usize(x))
76+
}
77+
78+
pub fn from_u32(x: u32) -> CrateNum {
79+
CrateNum::Index(CrateId::from_u32(x))
80+
}
81+
82+
pub fn as_usize(self) -> usize {
83+
match self {
84+
CrateNum::Index(id) => id.as_usize(),
85+
_ => bug!("tried to get index of nonstandard crate {:?}", self),
86+
}
87+
}
88+
89+
pub fn as_u32(self) -> u32 {
90+
match self {
91+
CrateNum::Index(id) => id.as_u32(),
92+
_ => bug!("tried to get index of nonstandard crate {:?}", self),
93+
}
94+
}
95+
4696
pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX } }
4797
}
4898

4999
impl fmt::Display for CrateNum {
50100
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51-
fmt::Display::fmt(&self.as_u32(), f)
101+
match self {
102+
CrateNum::Index(id) => fmt::Display::fmt(&id.private, f),
103+
CrateNum::Invalid => write!(f, "invalid crate"),
104+
CrateNum::BuiltinMacros => write!(f, "bultin macros crate"),
105+
CrateNum::ReservedForIncrCompCache => write!(f, "crate for decoding incr comp cache"),
106+
}
52107
}
53108
}
54109

src/librustc/ich/impls_ty.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,15 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
772772
FnPtrAddrCast
773773
});
774774

775-
impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
775+
impl_stable_hash_for!(struct ::middle::region::Scope { id, data });
776+
777+
impl_stable_hash_for!(enum ::middle::region::ScopeData {
778+
Node,
779+
CallSite,
780+
Arguments,
781+
Destruction,
782+
Remainder(first_statement_index)
783+
});
776784

777785
impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
778786
type KeyType = region::Scope;
@@ -783,11 +791,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
783791
}
784792
}
785793

786-
impl_stable_hash_for!(struct ::middle::region::BlockRemainder {
787-
block,
788-
first_statement_index
789-
});
790-
791794
impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo {
792795
custom_kind
793796
});

src/librustc/infer/error_reporting/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
119119
}
120120
};
121121
let scope_decorated_tag = match scope.data() {
122-
region::ScopeData::Node(_) => tag,
123-
region::ScopeData::CallSite(_) => "scope of call-site for function",
124-
region::ScopeData::Arguments(_) => "scope of function body",
125-
region::ScopeData::Destruction(_) => {
122+
region::ScopeData::Node => tag,
123+
region::ScopeData::CallSite => "scope of call-site for function",
124+
region::ScopeData::Arguments => "scope of function body",
125+
region::ScopeData::Destruction => {
126126
new_string = format!("destruction scope surrounding {}", tag);
127127
&new_string[..]
128128
}
129-
region::ScopeData::Remainder(r) => {
129+
region::ScopeData::Remainder(first_statement_index) => {
130130
new_string = format!(
131131
"block suffix following statement {}",
132-
r.first_statement_index.index()
132+
first_statement_index.index()
133133
);
134134
&new_string[..]
135135
}

src/librustc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#![feature(optin_builtin_traits)]
5959
#![feature(refcell_replace_swap)]
6060
#![feature(rustc_diagnostic_macros)]
61+
#![feature(rustc_attrs)]
62+
#![cfg_attr(stage0, feature(attr_literals))]
6163
#![feature(slice_patterns)]
6264
#![feature(slice_sort_by_cached_key)]
6365
#![feature(specialization)]

src/librustc/middle/lang_items.rs

-2
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ language_item_table! {
326326

327327
PhantomDataItem, "phantom_data", phantom_data;
328328

329-
NonZeroItem, "non_zero", non_zero;
330-
331329
ManuallyDropItem, "manually_drop", manually_drop;
332330

333331
DebugTraitLangItem, "debug_trait", debug_trait;

0 commit comments

Comments
 (0)