@@ -737,7 +737,7 @@ impl ExprCollector<'_> {
737737 /// `try { <stmts>; }` into `'<new_label>: { <stmts>; ::std::ops::Try::from_output(()) }`
738738 /// and save the `<new_label>` to use it as a break target for desugaring of the `?` operator.
739739 fn desugar_try_block ( & mut self , e : BlockExpr ) -> ExprId {
740- let Some ( try_from_output) = LangItem :: TryTraitFromOutput . path ( self . db , self . krate ) else {
740+ let Some ( try_from_output) = self . lang_path ( LangItem :: TryTraitFromOutput ) else {
741741 return self . collect_block ( e) ;
742742 } ;
743743 let label = self
@@ -840,10 +840,10 @@ impl ExprCollector<'_> {
840840 fn collect_for_loop ( & mut self , syntax_ptr : AstPtr < ast:: Expr > , e : ast:: ForExpr ) -> ExprId {
841841 let Some ( ( into_iter_fn, iter_next_fn, option_some, option_none) ) = ( || {
842842 Some ( (
843- LangItem :: IntoIterIntoIter . path ( self . db , self . krate ) ?,
844- LangItem :: IteratorNext . path ( self . db , self . krate ) ?,
845- LangItem :: OptionSome . path ( self . db , self . krate ) ?,
846- LangItem :: OptionNone . path ( self . db , self . krate ) ?,
843+ self . lang_path ( LangItem :: IntoIterIntoIter ) ?,
844+ self . lang_path ( LangItem :: IteratorNext ) ?,
845+ self . lang_path ( LangItem :: OptionSome ) ?,
846+ self . lang_path ( LangItem :: OptionNone ) ?,
847847 ) )
848848 } ) ( ) else {
849849 // Some of the needed lang items are missing, so we can't desugar
@@ -896,6 +896,15 @@ impl ExprCollector<'_> {
896896 Expr :: Match { expr : iter_next_expr, arms : Box :: new ( [ none_arm, some_arm] ) } ,
897897 syntax_ptr,
898898 ) ;
899+ let loop_inner = self . alloc_expr (
900+ Expr :: Block {
901+ id : None ,
902+ statements : Box :: default ( ) ,
903+ tail : Some ( loop_inner) ,
904+ label : None ,
905+ } ,
906+ syntax_ptr,
907+ ) ;
899908 let loop_outer = self . alloc_expr ( Expr :: Loop { body : loop_inner, label } , syntax_ptr) ;
900909 let iter_binding = self . alloc_binding ( iter_name, BindingAnnotation :: Mutable ) ;
901910 let iter_pat = self . alloc_pat_desugared ( Pat :: Bind { id : iter_binding, subpat : None } ) ;
@@ -923,10 +932,10 @@ impl ExprCollector<'_> {
923932 fn collect_try_operator ( & mut self , syntax_ptr : AstPtr < ast:: Expr > , e : ast:: TryExpr ) -> ExprId {
924933 let Some ( ( try_branch, cf_continue, cf_break, try_from_residual) ) = ( || {
925934 Some ( (
926- LangItem :: TryTraitBranch . path ( self . db , self . krate ) ?,
927- LangItem :: ControlFlowContinue . path ( self . db , self . krate ) ?,
928- LangItem :: ControlFlowBreak . path ( self . db , self . krate ) ?,
929- LangItem :: TryTraitFromResidual . path ( self . db , self . krate ) ?,
935+ self . lang_path ( LangItem :: TryTraitBranch ) ?,
936+ self . lang_path ( LangItem :: ControlFlowContinue ) ?,
937+ self . lang_path ( LangItem :: ControlFlowBreak ) ?,
938+ self . lang_path ( LangItem :: TryTraitFromResidual ) ?,
930939 ) )
931940 } ) ( ) else {
932941 // Some of the needed lang items are missing, so we can't desugar
@@ -2053,6 +2062,10 @@ impl ExprCollector<'_> {
20532062 } )
20542063 }
20552064 // endregion: format
2065+
2066+ fn lang_path ( & self , lang : LangItem ) -> Option < Path > {
2067+ lang. path ( self . db , self . krate )
2068+ }
20562069}
20572070
20582071fn pat_literal_to_hir ( lit : & ast:: LiteralPat ) -> Option < ( Literal , ast:: Literal ) > {
0 commit comments