@@ -8,7 +8,7 @@ use rustc_ast::token::{self, NtTT, Token};
8
8
use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndJoint } ;
9
9
use rustc_data_structures:: fx:: FxHashMap ;
10
10
use rustc_data_structures:: sync:: Lrc ;
11
- use rustc_errors:: pluralize;
11
+ use rustc_errors:: { pluralize, PResult } ;
12
12
use rustc_span:: hygiene:: { ExpnId , Transparency } ;
13
13
use rustc_span:: symbol:: MacroRulesNormalizedIdent ;
14
14
use rustc_span:: Span ;
@@ -80,15 +80,15 @@ impl Iterator for Frame {
80
80
/// `transcribe` would return a `TokenStream` containing `println!("{}", stringify!(bar));`.
81
81
///
82
82
/// Along the way, we do some additional error checking.
83
- pub ( super ) fn transcribe (
84
- cx : & ExtCtxt < ' _ > ,
83
+ pub ( super ) fn transcribe < ' a > (
84
+ cx : & ExtCtxt < ' a > ,
85
85
interp : & FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
86
86
src : Vec < mbe:: TokenTree > ,
87
87
transparency : Transparency ,
88
- ) -> TokenStream {
88
+ ) -> PResult < ' a , TokenStream > {
89
89
// Nothing for us to transcribe...
90
90
if src. is_empty ( ) {
91
- return TokenStream :: default ( ) ;
91
+ return Ok ( TokenStream :: default ( ) ) ;
92
92
}
93
93
94
94
// We descend into the RHS (`src`), expanding things as we go. This stack contains the things
@@ -152,7 +152,7 @@ pub(super) fn transcribe(
152
152
Frame :: Delimited { forest, span, .. } => {
153
153
if result_stack. is_empty ( ) {
154
154
// No results left to compute! We are back at the top-level.
155
- return TokenStream :: new ( result) ;
155
+ return Ok ( TokenStream :: new ( result) ) ;
156
156
}
157
157
158
158
// Step back into the parent Delimited.
@@ -173,19 +173,19 @@ pub(super) fn transcribe(
173
173
seq @ mbe:: TokenTree :: Sequence ( ..) => {
174
174
match lockstep_iter_size ( & seq, interp, & repeats) {
175
175
LockstepIterSize :: Unconstrained => {
176
- cx. span_fatal (
176
+ return Err ( cx. struct_span_err (
177
177
seq. span ( ) , /* blame macro writer */
178
178
"attempted to repeat an expression containing no syntax variables \
179
179
matched as repeating at this depth",
180
- ) ;
180
+ ) ) ;
181
181
}
182
182
183
183
LockstepIterSize :: Contradiction ( ref msg) => {
184
184
// FIXME: this really ought to be caught at macro definition time... It
185
185
// happens when two meta-variables are used in the same repetition in a
186
186
// sequence, but they come from different sequence matchers and repeat
187
187
// different amounts.
188
- cx. span_fatal ( seq. span ( ) , & msg[ ..] ) ;
188
+ return Err ( cx. struct_span_err ( seq. span ( ) , & msg[ ..] ) ) ;
189
189
}
190
190
191
191
LockstepIterSize :: Constraint ( len, _) => {
@@ -203,7 +203,10 @@ pub(super) fn transcribe(
203
203
// FIXME: this really ought to be caught at macro definition
204
204
// time... It happens when the Kleene operator in the matcher and
205
205
// the body for the same meta-variable do not match.
206
- cx. span_fatal ( sp. entire ( ) , "this must repeat at least once" ) ;
206
+ return Err ( cx. struct_span_err (
207
+ sp. entire ( ) ,
208
+ "this must repeat at least once" ,
209
+ ) ) ;
207
210
}
208
211
} else {
209
212
// 0 is the initial counter (we have done 0 repretitions so far). `len`
@@ -242,10 +245,10 @@ pub(super) fn transcribe(
242
245
}
243
246
} else {
244
247
// We were unable to descend far enough. This is an error.
245
- cx. span_fatal (
248
+ return Err ( cx. struct_span_err (
246
249
sp, /* blame the macro writer */
247
250
& format ! ( "variable '{}' is still repeating at this depth" , ident) ,
248
- ) ;
251
+ ) ) ;
249
252
}
250
253
} else {
251
254
// If we aren't able to match the meta-var, we push it back into the result but
0 commit comments