Skip to content

Commit 3e8ca48

Browse files
authored
Rollup merge of rust-lang#125829 - petrochenkov:upctxt2, r=michaelwoerister
rustc_span: Add conveniences for working with span formats This is the refactoring part of rust-lang#125017.
2 parents b81fa04 + 220f3ec commit 3e8ca48

File tree

3 files changed

+179
-114
lines changed

3 files changed

+179
-114
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl MutVisitor for Marker {
3030
// it's some advanced case with macro-generated macros. So if we cache the marked version
3131
// of that context once, we'll typically have a 100% cache hit rate after that.
3232
let Marker(expn_id, transparency, ref mut cache) = *self;
33-
span.update_ctxt(|ctxt| {
33+
*span = span.map_ctxt(|ctxt| {
3434
*cache
3535
.entry(ctxt)
3636
.or_insert_with(|| ctxt.apply_mark(expn_id.to_expn_id(), transparency))

compiler/rustc_span/src/lib.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ impl SpanData {
520520
pub fn with_hi(&self, hi: BytePos) -> Span {
521521
Span::new(self.lo, hi, self.ctxt, self.parent)
522522
}
523+
/// Avoid if possible, `Span::map_ctxt` should be preferred.
523524
#[inline]
524525
fn with_ctxt(&self, ctxt: SyntaxContext) -> Span {
525526
Span::new(self.lo, self.hi, ctxt, self.parent)
@@ -576,9 +577,8 @@ impl Span {
576577
self.data().with_hi(hi)
577578
}
578579
#[inline]
579-
pub fn with_ctxt(mut self, ctxt: SyntaxContext) -> Span {
580-
self.update_ctxt(|_| ctxt);
581-
self
580+
pub fn with_ctxt(self, ctxt: SyntaxContext) -> Span {
581+
self.map_ctxt(|_| ctxt)
582582
}
583583
#[inline]
584584
pub fn parent(self) -> Option<LocalDefId> {
@@ -1059,9 +1059,8 @@ impl Span {
10591059
}
10601060

10611061
#[inline]
1062-
pub fn apply_mark(mut self, expn_id: ExpnId, transparency: Transparency) -> Span {
1063-
self.update_ctxt(|ctxt| ctxt.apply_mark(expn_id, transparency));
1064-
self
1062+
pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
1063+
self.map_ctxt(|ctxt| ctxt.apply_mark(expn_id, transparency))
10651064
}
10661065

10671066
#[inline]
@@ -1109,15 +1108,13 @@ impl Span {
11091108
}
11101109

11111110
#[inline]
1112-
pub fn normalize_to_macros_2_0(mut self) -> Span {
1113-
self.update_ctxt(|ctxt| ctxt.normalize_to_macros_2_0());
1114-
self
1111+
pub fn normalize_to_macros_2_0(self) -> Span {
1112+
self.map_ctxt(|ctxt| ctxt.normalize_to_macros_2_0())
11151113
}
11161114

11171115
#[inline]
1118-
pub fn normalize_to_macro_rules(mut self) -> Span {
1119-
self.update_ctxt(|ctxt| ctxt.normalize_to_macro_rules());
1120-
self
1116+
pub fn normalize_to_macro_rules(self) -> Span {
1117+
self.map_ctxt(|ctxt| ctxt.normalize_to_macro_rules())
11211118
}
11221119
}
11231120

0 commit comments

Comments
 (0)