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