@@ -28,7 +28,7 @@ use crate::{
2828/// When constructed by the framework (via the rule! macro), `BuildCtx` also
2929/// carries a [`TranslatorHandle`] that the [`translate`] method delegates
3030/// to. When constructed by hand (e.g. in tests), the translator is `None`
31- /// and [`translate`] returns an error .
31+ /// and [`translate`] panics .
3232pub struct BuildCtx < ' a , C : ' a = ( ) > {
3333 ast : & ' a Ast ,
3434 pub output : & ' a mut OutputAst ,
@@ -44,10 +44,6 @@ pub struct BuildCtx<'a, C: 'a = ()> {
4444 /// Optional translator handle, populated when the context is built by
4545 /// the framework's rule driver. None when the context is built by hand.
4646 pub ( crate ) translator : Option < TranslatorHandle < ' a , C > > ,
47- /// First failure encountered while auto-translating an input `Id` during
48- /// template construction. Templates remain infallible expressions, so
49- /// [`finish_rule`](Self::finish_rule) returns this error at the rule boundary.
50- deferred_translation_error : Option < String > ,
5147 /// Nodes built directly through this context without an explicit source
5248 /// range in either their content or constructor argument. Recursive
5349 /// translations use their own context and therefore do not contribute to
@@ -64,7 +60,6 @@ impl<'a, C> BuildCtx<'a, C> {
6460 source_range : None ,
6561 user_ctx,
6662 translator : None ,
67- deferred_translation_error : None ,
6863 created_nodes_without_source_range : BTreeSet :: new ( ) ,
6964 }
7065 }
@@ -82,7 +77,6 @@ impl<'a, C> BuildCtx<'a, C> {
8277 source_range,
8378 user_ctx,
8479 translator : None ,
85- deferred_translation_error : None ,
8680 created_nodes_without_source_range : BTreeSet :: new ( ) ,
8781 }
8882 }
@@ -102,7 +96,6 @@ impl<'a, C> BuildCtx<'a, C> {
10296 source_range,
10397 user_ctx,
10498 translator : Some ( translator) ,
105- deferred_translation_error : None ,
10699 created_nodes_without_source_range : BTreeSet :: new ( ) ,
107100 }
108101 }
@@ -159,18 +152,15 @@ impl<'a, C> BuildCtx<'a, C> {
159152 /// Finish the current rule invocation by applying the matched source range
160153 /// to locally-created result roots.
161154 #[ doc( hidden) ]
162- pub fn finish_rule ( self , results : Vec < OutputId > ) -> Result < Vec < OutputId > , String > {
163- if let Some ( error) = self . deferred_translation_error {
164- return Err ( error) ;
165- }
155+ pub fn finish_rule ( self , results : Vec < OutputId > ) -> Vec < OutputId > {
166156 if let Some ( source_range) = self . source_range {
167157 for & id in & results {
168158 if self . created_nodes_without_source_range . contains ( & id) {
169159 self . output . extend_source_range ( id, source_range) ;
170160 }
171161 }
172162 }
173- Ok ( results)
163+ results
174164 }
175165
176166 /// Assign an explicit source range to a newly-built result root.
@@ -300,40 +290,31 @@ impl<C: Clone> BuildCtx<'_, C> {
300290
301291 #[ doc( hidden) ]
302292 pub fn translate_into ( & mut self , id : Id , out : & mut Vec < OutputId > ) {
303- if self . deferred_translation_error . is_some ( ) {
304- return ;
305- }
306- match self . translate ( id) {
307- Ok ( ids) => out. extend ( ids) ,
308- Err ( error) => self . deferred_translation_error = Some ( error) ,
309- }
293+ out. extend ( self . translate ( id) ) ;
310294 }
311295
312296 /// Recursively translate every id in the given iterable via the
313297 /// framework's rule machinery and return the accumulated resulting node
314298 /// ids in order.
315299 ///
316300 /// The single-`Id` case works too, because `Id: IntoIterator<Item
317- /// = Id>` is a singleton iterator — so `ctx.translate(some_id)? `
301+ /// = Id>` is a singleton iterator — so `ctx.translate(some_id)`
318302 /// returns a `Vec<OutputId>` containing whatever `some_id` translated to.
319303 ///
320- /// Errors if this `BuildCtx` was constructed by hand (without a
304+ /// Panics if this `BuildCtx` was constructed by hand (without a
321305 /// translator handle) — for example, in unit tests that don't go
322306 /// through the rule driver.
323- pub fn translate (
324- & mut self ,
325- ids : impl IntoIterator < Item = Id > ,
326- ) -> Result < Vec < OutputId > , String > {
307+ pub fn translate ( & mut self , ids : impl IntoIterator < Item = Id > ) -> Vec < OutputId > {
327308 let translator = self
328309 . translator
329310 . as_ref ( )
330- . ok_or ( "translate() called on a BuildCtx without a translator handle" ) ? ;
311+ . expect ( "translate() called on a BuildCtx without a translator handle" ) ;
331312 let mut out = Vec :: new ( ) ;
332313 for id in ids {
333- let translated = translator. translate ( self . ast , self . output , self . user_ctx , id) ? ;
314+ let translated = translator. translate ( self . ast , self . output , self . user_ctx , id) ;
334315 out. extend ( translated) ;
335316 }
336- Ok ( out)
317+ out
337318 }
338319
339320 /// Run `f` with a temporary child [`BuildCtx`] whose `user_ctx` is
@@ -358,9 +339,9 @@ impl<C: Clone> BuildCtx<'_, C> {
358339 /// let val = ctx.scoped(|ctx| {
359340 /// ctx.reset();
360341 /// ctx.translate(val)
361- /// })? ;
342+ /// });
362343 /// // `ctx` here is untouched by the reset inside the closure.
363- /// let other = ctx.translate(other_id)? ;
344+ /// let other = ctx.translate(other_id);
364345 /// ```
365346 pub fn scoped < F , R > ( & mut self , f : F ) -> R
366347 where
@@ -373,15 +354,11 @@ impl<C: Clone> BuildCtx<'_, C> {
373354 source_range : self . source_range ,
374355 user_ctx : & mut child_user_ctx,
375356 translator : self . translator ,
376- deferred_translation_error : None ,
377357 created_nodes_without_source_range : BTreeSet :: new ( ) ,
378358 } ;
379359 let result = f ( & mut child) ;
380360 let created_nodes_without_source_range =
381361 std:: mem:: take ( & mut child. created_nodes_without_source_range ) ;
382- if self . deferred_translation_error . is_none ( ) {
383- self . deferred_translation_error = child. deferred_translation_error . take ( ) ;
384- }
385362 drop ( child) ;
386363 self . created_nodes_without_source_range
387364 . extend ( created_nodes_without_source_range) ;
0 commit comments