@@ -8,7 +8,7 @@ use rustc_ast::token::{self, NtTT, Token};
88use rustc_ast:: tokenstream:: { DelimSpan , TokenStream , TokenTree , TreeAndJoint } ;
99use rustc_data_structures:: fx:: FxHashMap ;
1010use rustc_data_structures:: sync:: Lrc ;
11- use rustc_errors:: pluralize;
11+ use rustc_errors:: { pluralize, PResult } ;
1212use rustc_span:: hygiene:: { ExpnId , Transparency } ;
1313use rustc_span:: symbol:: MacroRulesNormalizedIdent ;
1414use rustc_span:: Span ;
@@ -80,15 +80,15 @@ impl Iterator for Frame {
8080/// `transcribe` would return a `TokenStream` containing `println!("{}", stringify!(bar));`.
8181///
8282/// 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 > ,
8585 interp : & FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
8686 src : Vec < mbe:: TokenTree > ,
8787 transparency : Transparency ,
88- ) -> TokenStream {
88+ ) -> PResult < ' a , TokenStream > {
8989 // Nothing for us to transcribe...
9090 if src. is_empty ( ) {
91- return TokenStream :: default ( ) ;
91+ return Ok ( TokenStream :: default ( ) ) ;
9292 }
9393
9494 // We descend into the RHS (`src`), expanding things as we go. This stack contains the things
@@ -152,7 +152,7 @@ pub(super) fn transcribe(
152152 Frame :: Delimited { forest, span, .. } => {
153153 if result_stack. is_empty ( ) {
154154 // No results left to compute! We are back at the top-level.
155- return TokenStream :: new ( result) ;
155+ return Ok ( TokenStream :: new ( result) ) ;
156156 }
157157
158158 // Step back into the parent Delimited.
@@ -173,19 +173,19 @@ pub(super) fn transcribe(
173173 seq @ mbe:: TokenTree :: Sequence ( ..) => {
174174 match lockstep_iter_size ( & seq, interp, & repeats) {
175175 LockstepIterSize :: Unconstrained => {
176- cx. span_fatal (
176+ return Err ( cx. struct_span_err (
177177 seq. span ( ) , /* blame macro writer */
178178 "attempted to repeat an expression containing no syntax variables \
179179 matched as repeating at this depth",
180- ) ;
180+ ) ) ;
181181 }
182182
183183 LockstepIterSize :: Contradiction ( ref msg) => {
184184 // FIXME: this really ought to be caught at macro definition time... It
185185 // happens when two meta-variables are used in the same repetition in a
186186 // sequence, but they come from different sequence matchers and repeat
187187 // different amounts.
188- cx. span_fatal ( seq. span ( ) , & msg[ ..] ) ;
188+ return Err ( cx. struct_span_err ( seq. span ( ) , & msg[ ..] ) ) ;
189189 }
190190
191191 LockstepIterSize :: Constraint ( len, _) => {
@@ -203,7 +203,10 @@ pub(super) fn transcribe(
203203 // FIXME: this really ought to be caught at macro definition
204204 // time... It happens when the Kleene operator in the matcher and
205205 // 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+ ) ) ;
207210 }
208211 } else {
209212 // 0 is the initial counter (we have done 0 repretitions so far). `len`
@@ -242,10 +245,10 @@ pub(super) fn transcribe(
242245 }
243246 } else {
244247 // We were unable to descend far enough. This is an error.
245- cx. span_fatal (
248+ return Err ( cx. struct_span_err (
246249 sp, /* blame the macro writer */
247250 & format ! ( "variable '{}' is still repeating at this depth" , ident) ,
248- ) ;
251+ ) ) ;
249252 }
250253 } else {
251254 // If we aren't able to match the meta-var, we push it back into the result but
0 commit comments