@@ -72,16 +72,22 @@ use rustc_data_structures::fx::FxIndexSet;
7272// #[cfg_attr(not(bootstrap), rustc_pass_by_value)]
7373pub struct Span {
7474 base_or_index : u32 ,
75- len_or_tag : u16 ,
75+ len_or_tag : LenOrTag ,
7676 ctxt_or_zero : u16 ,
7777}
7878
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 ) } ;
8085const MAX_LEN : u32 = 0b0111_1111_1111_1111 ;
8186const MAX_CTXT : u32 = 0b1111_1111_1111_1111 ;
8287
8388/// 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 } ;
8591
8692impl Span {
8793 #[ inline]
@@ -99,7 +105,11 @@ impl Span {
99105
100106 if len <= MAX_LEN && ctxt2 <= MAX_CTXT && parent. is_none ( ) {
101107 // 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+ }
103113 } else {
104114 // Interned format.
105115 let index =
@@ -123,10 +133,10 @@ impl Span {
123133 pub fn data_untracked ( self ) -> SpanData {
124134 if self . len_or_tag != LEN_TAG {
125135 // 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 ) ;
127137 SpanData {
128138 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 ) ,
130140 ctxt : SyntaxContext :: from_u32 ( self . ctxt_or_zero as u32 ) ,
131141 parent : None ,
132142 }
0 commit comments