@@ -1780,33 +1780,26 @@ impl<'a, 'gcx, 'tcx> AdtDef {
1780
1780
queries:: adt_destructor:: get ( tcx, DUMMY_SP , self . did )
1781
1781
}
1782
1782
1783
- /// Returns a simpler type such that `Self: Sized` if and only
1783
+ /// Returns a list of types such that `Self: Sized` if and only
1784
1784
/// if that type is Sized, or `TyErr` if this type is recursive.
1785
1785
///
1786
- /// HACK: instead of returning a list of types, this function can
1787
- /// return a tuple. In that case, the result is Sized only if
1788
- /// all elements of the tuple are Sized.
1789
- ///
1790
- /// This is generally the `struct_tail` if this is a struct, or a
1791
- /// tuple of them if this is an enum.
1792
- ///
1793
1786
/// Oddly enough, checking that the sized-constraint is Sized is
1794
1787
/// actually more expressive than checking all members:
1795
1788
/// the Sized trait is inductive, so an associated type that references
1796
1789
/// Self would prevent its containing ADT from being Sized.
1797
1790
///
1798
1791
/// Due to normalization being eager, this applies even if
1799
1792
/// the associated type is behind a pointer, e.g. issue #31299.
1800
- pub fn sized_constraint ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> Ty < ' tcx > {
1793
+ pub fn sized_constraint ( & self , tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> & ' tcx [ Ty < ' tcx > ] {
1801
1794
match queries:: adt_sized_constraint:: try_get ( tcx, DUMMY_SP , self . did ) {
1802
- Ok ( ty ) => ty ,
1795
+ Ok ( tys ) => tys ,
1803
1796
Err ( _) => {
1804
1797
debug ! ( "adt_sized_constraint: {:?} is recursive" , self ) ;
1805
1798
// This should be reported as an error by `check_representable`.
1806
1799
//
1807
1800
// Consider the type as Sized in the meanwhile to avoid
1808
1801
// further errors.
1809
- tcx. types . err
1802
+ tcx. intern_type_list ( & [ tcx . types . err ] )
1810
1803
}
1811
1804
}
1812
1805
}
@@ -1836,18 +1829,13 @@ impl<'a, 'gcx, 'tcx> AdtDef {
1836
1829
1837
1830
TyAdt ( adt, substs) => {
1838
1831
// recursive case
1839
- let adt_ty =
1840
- adt. sized_constraint ( tcx)
1841
- . subst ( tcx, substs) ;
1832
+ let adt_tys = adt. sized_constraint ( tcx) ;
1842
1833
debug ! ( "sized_constraint_for_ty({:?}) intermediate = {:?}" ,
1843
- ty, adt_ty) ;
1844
- if let ty:: TyTuple ( ref tys, _) = adt_ty. sty {
1845
- tys. iter ( ) . flat_map ( |ty| {
1846
- self . sized_constraint_for_ty ( tcx, ty)
1847
- } ) . collect ( )
1848
- } else {
1849
- self . sized_constraint_for_ty ( tcx, adt_ty)
1850
- }
1834
+ ty, adt_tys) ;
1835
+ adt_tys. iter ( )
1836
+ . map ( |ty| ty. subst ( tcx, substs) )
1837
+ . flat_map ( |ty| self . sized_constraint_for_ty ( tcx, ty) )
1838
+ . collect ( )
1851
1839
}
1852
1840
1853
1841
TyProjection ( ..) | TyAnon ( ..) => {
@@ -2697,13 +2685,7 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
2697
2685
2698
2686
/// Calculates the Sized-constraint.
2699
2687
///
2700
- /// As the Sized-constraint of enums can be a *set* of types,
2701
- /// the Sized-constraint may need to be a set also. Because introducing
2702
- /// a new type of IVar is currently a complex affair, the Sized-constraint
2703
- /// may be a tuple.
2704
- ///
2705
- /// In fact, there are only a few options for the constraint:
2706
- /// - `bool`, if the type is always Sized
2688
+ /// In fact, there are only a few options for the types in the constraint:
2707
2689
/// - an obviously-unsized type
2708
2690
/// - a type parameter or projection whose Sizedness can't be known
2709
2691
/// - a tuple of type parameters or projections, if there are multiple
@@ -2712,26 +2694,18 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
2712
2694
/// check should catch this case.
2713
2695
fn adt_sized_constraint < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
2714
2696
def_id : DefId )
2715
- -> Ty < ' tcx > {
2697
+ -> & ' tcx [ Ty < ' tcx > ] {
2716
2698
let def = tcx. lookup_adt_def ( def_id) ;
2717
2699
2718
- let tys : Vec < _ > = def. variants . iter ( ) . flat_map ( |v| {
2700
+ let result = tcx . intern_type_list ( & def. variants . iter ( ) . flat_map ( |v| {
2719
2701
v. fields . last ( )
2720
2702
} ) . flat_map ( |f| {
2721
- let ty = tcx. item_type ( f. did ) ;
2722
- def. sized_constraint_for_ty ( tcx, ty)
2723
- } ) . collect ( ) ;
2724
-
2725
- let ty = match tys. len ( ) {
2726
- _ if tys. references_error ( ) => tcx. types . err ,
2727
- 0 => tcx. types . bool ,
2728
- 1 => tys[ 0 ] ,
2729
- _ => tcx. intern_tup ( & tys[ ..] , false )
2730
- } ;
2703
+ def. sized_constraint_for_ty ( tcx, tcx. item_type ( f. did ) )
2704
+ } ) . collect :: < Vec < _ > > ( ) ) ;
2731
2705
2732
- debug ! ( "adt_sized_constraint: {:?} => {:?}" , def, ty ) ;
2706
+ debug ! ( "adt_sized_constraint: {:?} => {:?}" , def, result ) ;
2733
2707
2734
- ty
2708
+ result
2735
2709
}
2736
2710
2737
2711
fn associated_item_def_ids < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments