@@ -666,10 +666,7 @@ impl ExprCollector<'_> {
666
666
let fields = e. fields ( ) . map ( |it| it. as_name ( ) ) . collect ( ) ;
667
667
self . alloc_expr ( Expr :: OffsetOf ( OffsetOf { container, fields } ) , syntax_ptr)
668
668
}
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) ,
673
670
} )
674
671
}
675
672
@@ -1576,7 +1573,7 @@ impl ExprCollector<'_> {
1576
1573
& mut self ,
1577
1574
f : ast:: FormatArgsExpr ,
1578
1575
syntax_ptr : AstPtr < ast:: Expr > ,
1579
- ) -> Result < la_arena :: Idx < Expr > , Option < la_arena :: Idx < Expr > > > {
1576
+ ) -> ExprId {
1580
1577
let mut args = FormatArgumentsCollector :: new ( ) ;
1581
1578
f. args ( ) . for_each ( |arg| {
1582
1579
args. add ( FormatArgument {
@@ -1613,7 +1610,7 @@ impl ExprCollector<'_> {
1613
1610
}
1614
1611
}
1615
1612
}
1616
- todo ! ( ) ;
1613
+ return self . missing_expr ( ) ;
1617
1614
} ;
1618
1615
1619
1616
// Create a list of all _unique_ (argument, format trait) combinations.
@@ -1735,12 +1732,12 @@ impl ExprCollector<'_> {
1735
1732
let Some ( new_v1_formatted) =
1736
1733
LangItem :: FormatArguments . ty_rel_path ( self . db , self . krate , name ! [ new_v1_formatted] )
1737
1734
else {
1738
- todo ! ( )
1735
+ return self . missing_expr ( ) ;
1739
1736
} ;
1740
1737
let Some ( unsafe_arg_new) =
1741
1738
LangItem :: FormatUnsafeArg . ty_rel_path ( self . db , self . krate , name ! [ new] )
1742
1739
else {
1743
- todo ! ( )
1740
+ return self . missing_expr ( ) ;
1744
1741
} ;
1745
1742
let new_v1_formatted = self . alloc_expr_desugared ( Expr :: Path ( new_v1_formatted) ) ;
1746
1743
@@ -1756,14 +1753,14 @@ impl ExprCollector<'_> {
1756
1753
tail : Some ( unsafe_arg_new) ,
1757
1754
} ) ;
1758
1755
1759
- Ok ( self . alloc_expr (
1756
+ self . alloc_expr (
1760
1757
Expr :: Call {
1761
1758
callee : new_v1_formatted,
1762
1759
args : Box :: new ( [ lit_pieces, args, format_options, unsafe_arg_new] ) ,
1763
1760
is_assignee_expr : false ,
1764
1761
} ,
1765
1762
syntax_ptr,
1766
- ) )
1763
+ )
1767
1764
}
1768
1765
1769
1766
/// Generate a hir expression for a format_args placeholder specification.
@@ -1808,19 +1805,22 @@ impl ExprCollector<'_> {
1808
1805
} = & placeholder. format_options ;
1809
1806
let fill = self . alloc_expr_desugared ( Expr :: Literal ( Literal :: Char ( fill. unwrap_or ( ' ' ) ) ) ) ;
1810
1807
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
+ }
1822
1823
} ;
1823
- let align = self . alloc_expr_desugared ( Expr :: Path ( align) ) ;
1824
1824
// This needs to match `Flag` in library/core/src/fmt/rt.rs.
1825
1825
let flags: u32 = ( ( sign == Some ( FormatSign :: Plus ) ) as u32 )
1826
1826
| ( ( sign == Some ( FormatSign :: Minus ) ) as u32 ) << 1
@@ -1834,12 +1834,16 @@ impl ExprCollector<'_> {
1834
1834
) ) ) ;
1835
1835
let precision = self . make_count ( & precision, argmap) ;
1836
1836
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
+ }
1841
1845
} ;
1842
- let format_placeholder_new = self . alloc_expr_desugared ( Expr :: Path ( format_placeholder_new ) ) ;
1846
+
1843
1847
self . alloc_expr_desugared ( Expr :: Call {
1844
1848
callee : format_placeholder_new,
1845
1849
args : Box :: new ( [ position, fill, align, flags, precision, width] ) ,
@@ -1873,52 +1877,49 @@ impl ExprCollector<'_> {
1873
1877
) -> ExprId {
1874
1878
match count {
1875
1879
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
+ }
1891
1895
}
1892
1896
Some ( FormatCount :: Argument ( arg) ) => {
1893
1897
if let Ok ( arg_index) = arg. index {
1894
1898
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
+ }
1910
1915
} else {
1911
1916
self . missing_expr ( )
1912
1917
}
1913
1918
}
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
+ } ,
1922
1923
}
1923
1924
}
1924
1925
@@ -1932,7 +1933,7 @@ impl ExprCollector<'_> {
1932
1933
fn make_argument ( & mut self , arg : ExprId , ty : ArgumentType ) -> ExprId {
1933
1934
use ArgumentType :: * ;
1934
1935
use FormatTrait :: * ;
1935
- let Some ( new_fn ) = LangItem :: FormatArgument . ty_rel_path (
1936
+ match LangItem :: FormatArgument . ty_rel_path (
1936
1937
self . db ,
1937
1938
self . krate ,
1938
1939
match ty {
@@ -1947,15 +1948,17 @@ impl ExprCollector<'_> {
1947
1948
Format ( UpperHex ) => name ! [ new_upper_hex] ,
1948
1949
Usize => name ! [ from_usize] ,
1949
1950
} ,
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
+ }
1959
1962
}
1960
1963
// endregion: format
1961
1964
}
0 commit comments