@@ -1852,6 +1852,41 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
18521852 _ => bug ! ( "cannot convert type `{:?}` to a closure kind" , self ) ,
18531853 }
18541854 }
1855+
1856+ /// Fast path helper for testing if a type is `Sized`.
1857+ ///
1858+ /// Returning true means the type is known to be sized. Returning
1859+ /// `false` means nothing -- could be sized, might not be.
1860+ pub fn is_trivially_sized ( & self , tcx : TyCtxt < ' _ , ' _ , ' tcx > ) -> bool {
1861+ match self . sty {
1862+ ty:: TyInfer ( ty:: IntVar ( _) ) | ty:: TyInfer ( ty:: FloatVar ( _) ) |
1863+ ty:: TyUint ( _) | ty:: TyInt ( _) | ty:: TyBool | ty:: TyFloat ( _) |
1864+ ty:: TyFnDef ( ..) | ty:: TyFnPtr ( _) | ty:: TyRawPtr ( ..) |
1865+ ty:: TyChar | ty:: TyRef ( ..) | ty:: TyGenerator ( ..) |
1866+ ty:: TyGeneratorWitness ( ..) | ty:: TyArray ( ..) | ty:: TyClosure ( ..) |
1867+ ty:: TyNever | ty:: TyError =>
1868+ true ,
1869+
1870+ ty:: TyStr | ty:: TySlice ( _) | ty:: TyDynamic ( ..) | ty:: TyForeign ( ..) =>
1871+ false ,
1872+
1873+ ty:: TyTuple ( tys) =>
1874+ tys. iter ( ) . all ( |ty| ty. is_trivially_sized ( tcx) ) ,
1875+
1876+ ty:: TyAdt ( def, _substs) =>
1877+ def. sized_constraint ( tcx) . is_empty ( ) ,
1878+
1879+ ty:: TyProjection ( _) | ty:: TyParam ( _) | ty:: TyAnon ( ..) => false ,
1880+
1881+ ty:: TyInfer ( ty:: TyVar ( _) ) => false ,
1882+
1883+ ty:: TyInfer ( ty:: CanonicalTy ( _) ) |
1884+ ty:: TyInfer ( ty:: FreshTy ( _) ) |
1885+ ty:: TyInfer ( ty:: FreshIntTy ( _) ) |
1886+ ty:: TyInfer ( ty:: FreshFloatTy ( _) ) =>
1887+ bug ! ( "is_trivially_sized applied to unexpected type: {:?}" , self ) ,
1888+ }
1889+ }
18551890}
18561891
18571892/// Typed constant value.
0 commit comments