File tree 3 files changed +16
-26
lines changed
3 files changed +16
-26
lines changed Original file line number Diff line number Diff line change @@ -120,15 +120,16 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
120
120
_ => cx. span_bug ( sp, "malformed macro rhs" ) ,
121
121
} ;
122
122
123
+ let rhs_spans = rhs. iter ( ) . map ( |t| t. span ( ) ) . collect :: < Vec < _ > > ( ) ;
123
124
// 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) ;
125
126
126
127
// Replace all the tokens for the corresponding positions in the macro, to maintain
127
128
// 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| {
130
131
let mut tt = tt. clone ( ) ;
131
- let mut sp = rhs [ i] . span ( ) ;
132
+ let mut sp = rhs_spans [ i] ;
132
133
sp. ctxt = tt. span ( ) . ctxt ;
133
134
tt. set_span ( sp) ;
134
135
tt
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ impl TokenStream {
258
258
}
259
259
}
260
260
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 {
262
262
let mut trees = self . into_trees ( ) ;
263
263
let mut result = Vec :: new ( ) ;
264
264
let mut i = 0 ;
Original file line number Diff line number Diff line change @@ -185,29 +185,18 @@ impl Span {
185
185
result
186
186
}
187
187
188
- pub fn empty_ctxt ( & self ) -> bool {
189
- self . ctxt == SyntaxContext :: empty ( )
190
- }
191
-
192
188
/// Return a `Span` that would enclose both `self` and `end`.
193
189
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
+ }
211
200
}
212
201
213
202
/// Return a `Span` between the end of `self` to the beginning of `end`.
You can’t perform that action at this time.
0 commit comments