@@ -737,7 +737,7 @@ impl ExprCollector<'_> {
737
737
/// `try { <stmts>; }` into `'<new_label>: { <stmts>; ::std::ops::Try::from_output(()) }`
738
738
/// and save the `<new_label>` to use it as a break target for desugaring of the `?` operator.
739
739
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 {
741
741
return self . collect_block ( e) ;
742
742
} ;
743
743
let label = self
@@ -840,10 +840,10 @@ impl ExprCollector<'_> {
840
840
fn collect_for_loop ( & mut self , syntax_ptr : AstPtr < ast:: Expr > , e : ast:: ForExpr ) -> ExprId {
841
841
let Some ( ( into_iter_fn, iter_next_fn, option_some, option_none) ) = ( || {
842
842
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 ) ?,
847
847
) )
848
848
} ) ( ) else {
849
849
// Some of the needed lang items are missing, so we can't desugar
@@ -896,6 +896,15 @@ impl ExprCollector<'_> {
896
896
Expr :: Match { expr : iter_next_expr, arms : Box :: new ( [ none_arm, some_arm] ) } ,
897
897
syntax_ptr,
898
898
) ;
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
+ ) ;
899
908
let loop_outer = self . alloc_expr ( Expr :: Loop { body : loop_inner, label } , syntax_ptr) ;
900
909
let iter_binding = self . alloc_binding ( iter_name, BindingAnnotation :: Mutable ) ;
901
910
let iter_pat = self . alloc_pat_desugared ( Pat :: Bind { id : iter_binding, subpat : None } ) ;
@@ -923,10 +932,10 @@ impl ExprCollector<'_> {
923
932
fn collect_try_operator ( & mut self , syntax_ptr : AstPtr < ast:: Expr > , e : ast:: TryExpr ) -> ExprId {
924
933
let Some ( ( try_branch, cf_continue, cf_break, try_from_residual) ) = ( || {
925
934
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 ) ?,
930
939
) )
931
940
} ) ( ) else {
932
941
// Some of the needed lang items are missing, so we can't desugar
@@ -2053,6 +2062,10 @@ impl ExprCollector<'_> {
2053
2062
} )
2054
2063
}
2055
2064
// endregion: format
2065
+
2066
+ fn lang_path ( & self , lang : LangItem ) -> Option < Path > {
2067
+ lang. path ( self . db , self . krate )
2068
+ }
2056
2069
}
2057
2070
2058
2071
fn pat_literal_to_hir ( lit : & ast:: LiteralPat ) -> Option < ( Literal , ast:: Literal ) > {
0 commit comments