@@ -72,16 +72,22 @@ use rustc_data_structures::fx::FxIndexSet;
72
72
// #[cfg_attr(not(bootstrap), rustc_pass_by_value)]
73
73
pub struct Span {
74
74
base_or_index : u32 ,
75
- len_or_tag : u16 ,
75
+ len_or_tag : LenOrTag ,
76
76
ctxt_or_zero : u16 ,
77
77
}
78
78
79
- const LEN_TAG : u16 = 0b1000_0000_0000_0000 ;
79
+ // LEN_TAG allows for some extra values at the top. Declare them to rustc to use as niches.
80
+ #[ rustc_layout_scalar_valid_range_end( 0b1000_0000_0000_0000 ) ]
81
+ #[ derive( Copy , Clone , Eq , PartialEq , Hash ) ]
82
+ struct LenOrTag ( u16 ) ;
83
+
84
+ const LEN_TAG : LenOrTag = unsafe { LenOrTag ( 0b1000_0000_0000_0000 ) } ;
80
85
const MAX_LEN : u32 = 0b0111_1111_1111_1111 ;
81
86
const MAX_CTXT : u32 = 0b1111_1111_1111_1111 ;
82
87
83
88
/// Dummy span, both position and length are zero, syntax context is zero as well.
84
- pub const DUMMY_SP : Span = Span { base_or_index : 0 , len_or_tag : 0 , ctxt_or_zero : 0 } ;
89
+ pub const DUMMY_SP : Span =
90
+ Span { base_or_index : 0 , len_or_tag : unsafe { LenOrTag ( 0 ) } , ctxt_or_zero : 0 } ;
85
91
86
92
impl Span {
87
93
#[ inline]
@@ -99,7 +105,11 @@ impl Span {
99
105
100
106
if len <= MAX_LEN && ctxt2 <= MAX_CTXT && parent. is_none ( ) {
101
107
// Inline format.
102
- Span { base_or_index : base, len_or_tag : len as u16 , ctxt_or_zero : ctxt2 as u16 }
108
+ Span {
109
+ base_or_index : base,
110
+ len_or_tag : unsafe { LenOrTag ( len as u16 ) } ,
111
+ ctxt_or_zero : ctxt2 as u16 ,
112
+ }
103
113
} else {
104
114
// Interned format.
105
115
let index =
@@ -123,10 +133,10 @@ impl Span {
123
133
pub fn data_untracked ( self ) -> SpanData {
124
134
if self . len_or_tag != LEN_TAG {
125
135
// Inline format.
126
- debug_assert ! ( self . len_or_tag as u32 <= MAX_LEN ) ;
136
+ debug_assert ! ( self . len_or_tag. 0 as u32 <= MAX_LEN ) ;
127
137
SpanData {
128
138
lo : BytePos ( self . base_or_index ) ,
129
- hi : BytePos ( self . base_or_index + self . len_or_tag as u32 ) ,
139
+ hi : BytePos ( self . base_or_index + self . len_or_tag . 0 as u32 ) ,
130
140
ctxt : SyntaxContext :: from_u32 ( self . ctxt_or_zero as u32 ) ,
131
141
parent : None ,
132
142
}
0 commit comments