@@ -192,20 +192,20 @@ macro_rules! match_span_kind {
192
192
if $span. len_with_tag_or_marker != BASE_LEN_INTERNED_MARKER {
193
193
if $span. len_with_tag_or_marker & PARENT_TAG == 0 {
194
194
// Inline-context format.
195
- let $span1: & mut InlineCtxt = unsafe { transmute( & mut * $span) } ;
195
+ let $span1: InlineCtxt = unsafe { transmute( $span) } ;
196
196
$arm1
197
197
} else {
198
198
// Inline-parent format.
199
- let $span2: & mut InlineParent = unsafe { transmute( & mut * $span) } ;
199
+ let $span2: InlineParent = unsafe { transmute( $span) } ;
200
200
$arm2
201
201
}
202
202
} else if $span. ctxt_or_parent_or_marker != CTXT_INTERNED_MARKER {
203
203
// Partially-interned format.
204
- let $span3: & mut PartiallyInterned = unsafe { transmute( & mut * $span) } ;
204
+ let $span3: PartiallyInterned = unsafe { transmute( $span) } ;
205
205
$arm3
206
206
} else {
207
207
// Interned format.
208
- let $span4: & mut Interned = unsafe { transmute( & mut * $span) } ;
208
+ let $span4: Interned = unsafe { transmute( $span) } ;
209
209
$arm4
210
210
}
211
211
} ;
@@ -273,9 +273,9 @@ impl Span {
273
273
/// Internal function to translate between an encoded span and the expanded representation.
274
274
/// This function must not be used outside the incremental engine.
275
275
#[ inline]
276
- pub fn data_untracked ( mut self ) -> SpanData {
276
+ pub fn data_untracked ( self ) -> SpanData {
277
277
match_span_kind ! {
278
- & mut self ,
278
+ self ,
279
279
InlineCtxt ( span) => span. data( ) ,
280
280
InlineParent ( span) => span. data( ) ,
281
281
PartiallyInterned ( span) => span. data( ) ,
@@ -304,7 +304,7 @@ impl Span {
304
304
// update doesn't change format. All non-inline or format changing scenarios require accessing
305
305
// interner and can fall back to `Span::new`.
306
306
#[ inline]
307
- pub fn update_ctxt ( & mut self , update : impl FnOnce ( SyntaxContext ) -> SyntaxContext ) {
307
+ pub fn map_ctxt ( self , update : impl FnOnce ( SyntaxContext ) -> SyntaxContext ) -> Span {
308
308
let ( updated_ctxt32, data) ;
309
309
match_span_kind ! {
310
310
self ,
@@ -313,8 +313,7 @@ impl Span {
313
313
update( SyntaxContext :: from_u32( span. ctxt as u32 ) ) . as_u32( ) ;
314
314
// Any small new context including zero will preserve the format.
315
315
if updated_ctxt32 <= MAX_CTXT {
316
- span. ctxt = updated_ctxt32 as u16 ;
317
- return ;
316
+ return InlineCtxt :: span( span. lo, span. len, updated_ctxt32 as u16 ) ;
318
317
}
319
318
data = span. data( ) ;
320
319
} ,
@@ -323,7 +322,7 @@ impl Span {
323
322
// Only if the new context is zero the format will be preserved.
324
323
if updated_ctxt32 == 0 {
325
324
// Do nothing.
326
- return ;
325
+ return self ;
327
326
}
328
327
data = span. data( ) ;
329
328
} ,
@@ -332,8 +331,7 @@ impl Span {
332
331
// Any small new context excluding zero will preserve the format.
333
332
// Zero may change the format to `InlineParent` if parent and len are small enough.
334
333
if updated_ctxt32 <= MAX_CTXT && updated_ctxt32 != 0 {
335
- span. ctxt = updated_ctxt32 as u16 ;
336
- return ;
334
+ return PartiallyInterned :: span( span. index, updated_ctxt32 as u16 ) ;
337
335
}
338
336
data = span. data( ) ;
339
337
} ,
@@ -344,15 +342,15 @@ impl Span {
344
342
}
345
343
346
344
// We could not keep the span in the same inline format, fall back to the complete logic.
347
- * self = data. with_ctxt ( SyntaxContext :: from_u32 ( updated_ctxt32) ) ;
345
+ data. with_ctxt ( SyntaxContext :: from_u32 ( updated_ctxt32) )
348
346
}
349
347
350
348
// Returns either syntactic context, if it can be retrieved without taking the interner lock,
351
349
// or an index into the interner if it cannot.
352
350
#[ inline]
353
- fn inline_ctxt ( mut self ) -> Result < SyntaxContext , usize > {
351
+ fn inline_ctxt ( self ) -> Result < SyntaxContext , usize > {
354
352
match_span_kind ! {
355
- & mut self ,
353
+ self ,
356
354
InlineCtxt ( span) => Ok ( SyntaxContext :: from_u32( span. ctxt as u32 ) ) ,
357
355
InlineParent ( _span) => Ok ( SyntaxContext :: root( ) ) ,
358
356
PartiallyInterned ( span) => Ok ( SyntaxContext :: from_u32( span. ctxt as u32 ) ) ,
0 commit comments