File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -884,6 +884,7 @@ rustc_queries! {
884
884
query is_sized_raw( env: ty:: ParamEnvAnd <' tcx, Ty <' tcx>>) -> bool {
885
885
desc { "computing whether `{}` is `Sized`" , env. value }
886
886
}
887
+
887
888
/// Query backing `TyS::is_freeze`.
888
889
query is_freeze_raw( env: ty:: ParamEnvAnd <' tcx, Ty <' tcx>>) -> bool {
889
890
desc { "computing whether `{}` is freeze" , env. value }
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ use rustc_hir::def_id::DefId;
19
19
use rustc_index:: vec:: Idx ;
20
20
use rustc_macros:: HashStable ;
21
21
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
22
- use rustc_target:: abi:: VariantIdx ;
22
+ use rustc_target:: abi:: { Layout , VariantIdx } ;
23
23
use rustc_target:: spec:: abi;
24
24
use std:: borrow:: Cow ;
25
25
use std:: cmp:: Ordering ;
@@ -2251,4 +2251,22 @@ impl<'tcx> TyS<'tcx> {
2251
2251
pub fn is_zst ( & ' tcx self , tcx : TyCtxt < ' tcx > , did : DefId ) -> bool {
2252
2252
tcx. layout_of ( tcx. param_env ( did) . and ( self ) ) . map ( |layout| layout. is_zst ( ) ) . unwrap_or ( false )
2253
2253
}
2254
+
2255
+ /// Returns an iterator over the sized layouts of the variants of a type given context and
2256
+ /// specific definition. If the type is not an ADT, returns None.
2257
+ pub fn layout_of_variants (
2258
+ & ' tcx self ,
2259
+ tcx : TyCtxt < ' tcx > ,
2260
+ ) -> Option < impl Iterator < Item = & ' tcx Layout > + ' tcx > {
2261
+ let iter = match self . kind {
2262
+ ty:: Adt ( def, _substs) => def. variants . iter ( ) . flat_map ( move |var_def| {
2263
+ tcx. layout_of ( tcx. param_env ( var_def. def_id ) . and ( self ) )
2264
+ . ok ( )
2265
+ . filter ( |ty_and_layout| !ty_and_layout. is_unsized ( ) )
2266
+ . map ( |ty_and_layout| ty_and_layout. layout )
2267
+ } ) ,
2268
+ _ => return None ,
2269
+ } ;
2270
+ Some ( iter)
2271
+ }
2254
2272
}
You can’t perform that action at this time.
0 commit comments