@@ -666,10 +666,7 @@ impl ExprCollector<'_> {
666666 let fields = e. fields ( ) . map ( |it| it. as_name ( ) ) . collect ( ) ;
667667 self . alloc_expr ( Expr :: OffsetOf ( OffsetOf { container, fields } ) , syntax_ptr)
668668 }
669- ast:: Expr :: FormatArgsExpr ( f) => match self . collect_format_args ( f, syntax_ptr) {
670- Ok ( value) => value,
671- Err ( value) => return value,
672- } ,
669+ ast:: Expr :: FormatArgsExpr ( f) => self . collect_format_args ( f, syntax_ptr) ,
673670 } )
674671 }
675672
@@ -1576,7 +1573,7 @@ impl ExprCollector<'_> {
15761573 & mut self ,
15771574 f : ast:: FormatArgsExpr ,
15781575 syntax_ptr : AstPtr < ast:: Expr > ,
1579- ) -> Result < la_arena :: Idx < Expr > , Option < la_arena :: Idx < Expr > > > {
1576+ ) -> ExprId {
15801577 let mut args = FormatArgumentsCollector :: new ( ) ;
15811578 f. args ( ) . for_each ( |arg| {
15821579 args. add ( FormatArgument {
@@ -1613,7 +1610,7 @@ impl ExprCollector<'_> {
16131610 }
16141611 }
16151612 }
1616- todo ! ( ) ;
1613+ return self . missing_expr ( ) ;
16171614 } ;
16181615
16191616 // Create a list of all _unique_ (argument, format trait) combinations.
@@ -1735,12 +1732,12 @@ impl ExprCollector<'_> {
17351732 let Some ( new_v1_formatted) =
17361733 LangItem :: FormatArguments . ty_rel_path ( self . db , self . krate , name ! [ new_v1_formatted] )
17371734 else {
1738- todo ! ( )
1735+ return self . missing_expr ( ) ;
17391736 } ;
17401737 let Some ( unsafe_arg_new) =
17411738 LangItem :: FormatUnsafeArg . ty_rel_path ( self . db , self . krate , name ! [ new] )
17421739 else {
1743- todo ! ( )
1740+ return self . missing_expr ( ) ;
17441741 } ;
17451742 let new_v1_formatted = self . alloc_expr_desugared ( Expr :: Path ( new_v1_formatted) ) ;
17461743
@@ -1756,14 +1753,14 @@ impl ExprCollector<'_> {
17561753 tail : Some ( unsafe_arg_new) ,
17571754 } ) ;
17581755
1759- Ok ( self . alloc_expr (
1756+ self . alloc_expr (
17601757 Expr :: Call {
17611758 callee : new_v1_formatted,
17621759 args : Box :: new ( [ lit_pieces, args, format_options, unsafe_arg_new] ) ,
17631760 is_assignee_expr : false ,
17641761 } ,
17651762 syntax_ptr,
1766- ) )
1763+ )
17671764 }
17681765
17691766 /// Generate a hir expression for a format_args placeholder specification.
@@ -1808,19 +1805,22 @@ impl ExprCollector<'_> {
18081805 } = & placeholder. format_options ;
18091806 let fill = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Char ( fill. unwrap_or ( ' ' ) ) ) ) ;
18101807
1811- let Some ( align) = LangItem :: FormatAlignment . ty_rel_path (
1812- self . db ,
1813- self . krate ,
1814- match alignment {
1815- Some ( FormatAlignment :: Left ) => name ! [ Left ] ,
1816- Some ( FormatAlignment :: Right ) => name ! [ Right ] ,
1817- Some ( FormatAlignment :: Center ) => name ! [ Center ] ,
1818- None => name ! [ Unknown ] ,
1819- } ,
1820- ) else {
1821- todo ! ( )
1808+ let align = {
1809+ let align = LangItem :: FormatAlignment . ty_rel_path (
1810+ self . db ,
1811+ self . krate ,
1812+ match alignment {
1813+ Some ( FormatAlignment :: Left ) => name ! [ Left ] ,
1814+ Some ( FormatAlignment :: Right ) => name ! [ Right ] ,
1815+ Some ( FormatAlignment :: Center ) => name ! [ Center ] ,
1816+ None => name ! [ Unknown ] ,
1817+ } ,
1818+ ) ;
1819+ match align {
1820+ Some ( path) => self . alloc_expr_desugared ( Expr :: Path ( path) ) ,
1821+ None => self . missing_expr ( ) ,
1822+ }
18221823 } ;
1823- let align = self . alloc_expr_desugared ( Expr :: Path ( align) ) ;
18241824 // This needs to match `Flag` in library/core/src/fmt/rt.rs.
18251825 let flags: u32 = ( ( sign == Some ( FormatSign :: Plus ) ) as u32 )
18261826 | ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 1
@@ -1834,12 +1834,16 @@ impl ExprCollector<'_> {
18341834 ) ) ) ;
18351835 let precision = self . make_count ( & precision, argmap) ;
18361836 let width = self . make_count ( & width, argmap) ;
1837- let Some ( format_placeholder_new) =
1838- LangItem :: FormatPlaceholder . ty_rel_path ( self . db , self . krate , name ! [ new] )
1839- else {
1840- todo ! ( )
1837+
1838+ let format_placeholder_new = {
1839+ let format_placeholder_new =
1840+ LangItem :: FormatPlaceholder . ty_rel_path ( self . db , self . krate , name ! [ new] ) ;
1841+ match format_placeholder_new {
1842+ Some ( path) => self . alloc_expr_desugared ( Expr :: Path ( path) ) ,
1843+ None => self . missing_expr ( ) ,
1844+ }
18411845 } ;
1842- let format_placeholder_new = self . alloc_expr_desugared ( Expr :: Path ( format_placeholder_new ) ) ;
1846+
18431847 self . alloc_expr_desugared ( Expr :: Call {
18441848 callee : format_placeholder_new,
18451849 args : Box :: new ( [ position, fill, align, flags, precision, width] ) ,
@@ -1873,52 +1877,49 @@ impl ExprCollector<'_> {
18731877 ) -> ExprId {
18741878 match count {
18751879 Some ( FormatCount :: Literal ( n) ) => {
1876- let Some ( count_is ) =
1877- LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Is ] )
1878- else {
1879- todo ! ( )
1880- } ;
1881- let count_is = self . alloc_expr_desugared ( Expr :: Path ( count_is ) ) ;
1882- let args = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Uint (
1883- * n as u128 ,
1884- Some ( BuiltinUint :: Usize ) ,
1885- ) ) ) ;
1886- self . alloc_expr_desugared ( Expr :: Call {
1887- callee : count_is ,
1888- args : Box :: new ( [ args ] ) ,
1889- is_assignee_expr : false ,
1890- } )
1880+ match LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Is ] ) {
1881+ Some ( count_is ) => {
1882+ let count_is = self . alloc_expr_desugared ( Expr :: Path ( count_is ) ) ;
1883+ let args = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Uint (
1884+ * n as u128 ,
1885+ Some ( BuiltinUint :: Usize ) ,
1886+ ) ) ) ;
1887+ self . alloc_expr_desugared ( Expr :: Call {
1888+ callee : count_is ,
1889+ args : Box :: new ( [ args ] ) ,
1890+ is_assignee_expr : false ,
1891+ } )
1892+ }
1893+ None => self . missing_expr ( ) ,
1894+ }
18911895 }
18921896 Some ( FormatCount :: Argument ( arg) ) => {
18931897 if let Ok ( arg_index) = arg. index {
18941898 let ( i, _) = argmap. insert_full ( ( arg_index, ArgumentType :: Usize ) ) ;
1895- let Some ( count_param) =
1896- LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Param ] )
1897- else {
1898- todo ! ( )
1899- } ;
1900- let count_param = self . alloc_expr_desugared ( Expr :: Path ( count_param) ) ;
1901- let args = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Uint (
1902- i as u128 ,
1903- Some ( BuiltinUint :: Usize ) ,
1904- ) ) ) ;
1905- self . alloc_expr_desugared ( Expr :: Call {
1906- callee : count_param,
1907- args : Box :: new ( [ args] ) ,
1908- is_assignee_expr : false ,
1909- } )
1899+
1900+ match LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Param ] ) {
1901+ Some ( count_param) => {
1902+ let count_param = self . alloc_expr_desugared ( Expr :: Path ( count_param) ) ;
1903+ let args = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Uint (
1904+ i as u128 ,
1905+ Some ( BuiltinUint :: Usize ) ,
1906+ ) ) ) ;
1907+ self . alloc_expr_desugared ( Expr :: Call {
1908+ callee : count_param,
1909+ args : Box :: new ( [ args] ) ,
1910+ is_assignee_expr : false ,
1911+ } )
1912+ }
1913+ None => self . missing_expr ( ) ,
1914+ }
19101915 } else {
19111916 self . missing_expr ( )
19121917 }
19131918 }
1914- None => {
1915- let Some ( count_param) =
1916- LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Implied ] )
1917- else {
1918- todo ! ( )
1919- } ;
1920- self . alloc_expr_desugared ( Expr :: Path ( count_param) )
1921- }
1919+ None => match LangItem :: FormatCount . ty_rel_path ( self . db , self . krate , name ! [ Implied ] ) {
1920+ Some ( count_param) => self . alloc_expr_desugared ( Expr :: Path ( count_param) ) ,
1921+ None => self . missing_expr ( ) ,
1922+ } ,
19221923 }
19231924 }
19241925
@@ -1932,7 +1933,7 @@ impl ExprCollector<'_> {
19321933 fn make_argument ( & mut self , arg : ExprId , ty : ArgumentType ) -> ExprId {
19331934 use ArgumentType :: * ;
19341935 use FormatTrait :: * ;
1935- let Some ( new_fn ) = LangItem :: FormatArgument . ty_rel_path (
1936+ match LangItem :: FormatArgument . ty_rel_path (
19361937 self . db ,
19371938 self . krate ,
19381939 match ty {
@@ -1947,15 +1948,17 @@ impl ExprCollector<'_> {
19471948 Format ( UpperHex ) => name ! [ new_upper_hex] ,
19481949 Usize => name ! [ from_usize] ,
19491950 } ,
1950- ) else {
1951- todo ! ( )
1952- } ;
1953- let new_fn = self . alloc_expr_desugared ( Expr :: Path ( new_fn) ) ;
1954- self . alloc_expr_desugared ( Expr :: Call {
1955- callee : new_fn,
1956- args : Box :: new ( [ arg] ) ,
1957- is_assignee_expr : false ,
1958- } )
1951+ ) {
1952+ Some ( new_fn) => {
1953+ let new_fn = self . alloc_expr_desugared ( Expr :: Path ( new_fn) ) ;
1954+ self . alloc_expr_desugared ( Expr :: Call {
1955+ callee : new_fn,
1956+ args : Box :: new ( [ arg] ) ,
1957+ is_assignee_expr : false ,
1958+ } )
1959+ }
1960+ None => self . missing_expr ( ) ,
1961+ }
19591962 }
19601963 // endregion: format
19611964}
0 commit comments