@@ -1843,7 +1843,7 @@ impl<'tcx> Ty<'tcx> {
1843
1843
ty:: Infer ( ty:: TyVar ( _) ) => false ,
1844
1844
1845
1845
ty:: Infer ( ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) ) => {
1846
- bug ! ( "`is_trivially_sized ` applied to unexpected type: {:?}" , self )
1846
+ bug ! ( "`has_trivial_sizedness ` applied to unexpected type: {:?}" , self )
1847
1847
}
1848
1848
}
1849
1849
}
@@ -1907,6 +1907,52 @@ impl<'tcx> Ty<'tcx> {
1907
1907
}
1908
1908
}
1909
1909
1910
+ pub fn is_trivially_wf ( self , tcx : TyCtxt < ' tcx > ) -> bool {
1911
+ match * self . kind ( ) {
1912
+ ty:: Bool
1913
+ | ty:: Char
1914
+ | ty:: Int ( _)
1915
+ | ty:: Uint ( _)
1916
+ | ty:: Float ( _)
1917
+ | ty:: Str
1918
+ | ty:: Never
1919
+ | ty:: Param ( _)
1920
+ | ty:: Placeholder ( _)
1921
+ | ty:: Bound ( ..) => true ,
1922
+
1923
+ ty:: Slice ( ty) => {
1924
+ ty. is_trivially_wf ( tcx) && ty. has_trivial_sizedness ( tcx, SizedTraitKind :: Sized )
1925
+ }
1926
+ ty:: RawPtr ( ty, _) => ty. is_trivially_wf ( tcx) ,
1927
+
1928
+ ty:: FnPtr ( sig_tys, _) => {
1929
+ sig_tys. skip_binder ( ) . inputs_and_output . iter ( ) . all ( |ty| ty. is_trivially_wf ( tcx) )
1930
+ }
1931
+ ty:: Ref ( _, ty, _) => ty. is_global ( ) && ty. is_trivially_wf ( tcx) ,
1932
+
1933
+ ty:: Infer ( infer) => match infer {
1934
+ ty:: TyVar ( _) => false ,
1935
+ ty:: IntVar ( _) | ty:: FloatVar ( _) => true ,
1936
+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => true ,
1937
+ } ,
1938
+
1939
+ ty:: Adt ( _, _)
1940
+ | ty:: Tuple ( _)
1941
+ | ty:: Array ( ..)
1942
+ | ty:: Foreign ( _)
1943
+ | ty:: Pat ( _, _)
1944
+ | ty:: FnDef ( ..)
1945
+ | ty:: UnsafeBinder ( ..)
1946
+ | ty:: Dynamic ( ..)
1947
+ | ty:: Closure ( ..)
1948
+ | ty:: CoroutineClosure ( ..)
1949
+ | ty:: Coroutine ( ..)
1950
+ | ty:: CoroutineWitness ( ..)
1951
+ | ty:: Alias ( ..)
1952
+ | ty:: Error ( _) => false ,
1953
+ }
1954
+ }
1955
+
1910
1956
/// If `self` is a primitive, return its [`Symbol`].
1911
1957
pub fn primitive_symbol ( self ) -> Option < Symbol > {
1912
1958
match self . kind ( ) {
0 commit comments