Skip to content

Commit 6772661

Browse files
committed
Review comments
1 parent 09c712d commit 6772661

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

Diff for: src/libsyntax/ext/tt/macro_rules.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
120120
_ => cx.span_bug(sp, "malformed macro rhs"),
121121
};
122122

123+
let rhs_spans = rhs.iter().map(|t| t.span()).collect::<Vec<_>>();
123124
// rhs has holes ( `$id` and `$(...)` that need filled)
124-
let mut tts = transcribe(cx, Some(named_matches), rhs.clone());
125+
let mut tts = transcribe(cx, Some(named_matches), rhs);
125126

126127
// Replace all the tokens for the corresponding positions in the macro, to maintain
127128
// proper positions in error reporting, while maintaining the macro_backtrace.
128-
if rhs.len() == tts.len() {
129-
tts = tts.map_pos(|i, tt| {
129+
if rhs_spans.len() == tts.len() {
130+
tts = tts.map_enumerated(|i, tt| {
130131
let mut tt = tt.clone();
131-
let mut sp = rhs[i].span();
132+
let mut sp = rhs_spans[i];
132133
sp.ctxt = tt.span().ctxt;
133134
tt.set_span(sp);
134135
tt

Diff for: src/libsyntax/tokenstream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl TokenStream {
258258
}
259259
}
260260

261-
pub fn map_pos<F: FnMut(usize, TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream {
261+
pub fn map_enumerated<F: FnMut(usize, TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream {
262262
let mut trees = self.into_trees();
263263
let mut result = Vec::new();
264264
let mut i = 0;

Diff for: src/libsyntax_pos/lib.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -185,29 +185,18 @@ impl Span {
185185
result
186186
}
187187

188-
pub fn empty_ctxt(&self) -> bool {
189-
self.ctxt == SyntaxContext::empty()
190-
}
191-
192188
/// Return a `Span` that would enclose both `self` and `end`.
193189
pub fn to(self, end: Span) -> Span {
194-
let lo = if self.lo < end.lo {
195-
self.lo
196-
} else {
197-
end.lo
198-
};
199-
let hi = if self.hi > end.hi {
200-
self.hi
201-
} else {
202-
end.hi
203-
};
204-
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
205-
let ctxt = if self.ctxt == SyntaxContext::empty() {
206-
end.ctxt
207-
} else {
208-
self.ctxt
209-
};
210-
Span {lo, hi, ctxt}
190+
Span {
191+
lo: cmp::min(self.lo, end.lo),
192+
hi: cmp::max(self.hi, end.hi),
193+
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
194+
ctxt: if self.ctxt == SyntaxContext::empty() {
195+
end.ctxt
196+
} else {
197+
self.ctxt
198+
},
199+
}
211200
}
212201

213202
/// Return a `Span` between the end of `self` to the beginning of `end`.

0 commit comments

Comments
 (0)