@@ -425,6 +425,38 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
425
425
}
426
426
}
427
427
428
+ #[ derive( Clone , Copy , Debug , Eq , TyEncodable , TyDecodable , TypeFoldable ) ]
429
+ pub enum ImplicitTraitPredicate {
430
+ Yes ,
431
+ No ,
432
+ }
433
+
434
+ impl Hash for ImplicitTraitPredicate {
435
+ fn hash < H > ( & self , _: & mut H )
436
+ where
437
+ H : Hasher ,
438
+ {
439
+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
440
+ // type parameters and associated types, it has no incidence whatsoever on anything else.
441
+ }
442
+ }
443
+
444
+ impl < CTX > :: rustc_data_structures:: stable_hasher:: HashStable < CTX > for ImplicitTraitPredicate {
445
+ #[ inline]
446
+ fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
447
+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
448
+ // type parameters and associated types, it has no incidence whatsoever on anything else.
449
+ }
450
+ }
451
+
452
+ impl PartialEq for ImplicitTraitPredicate {
453
+ fn eq ( & self , _: & ImplicitTraitPredicate ) -> bool {
454
+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
455
+ // type parameters and associated types, it has no incidence whatsoever on anything else.
456
+ true
457
+ }
458
+ }
459
+
428
460
#[ derive( Clone , Copy , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
429
461
#[ derive( HashStable , TypeFoldable ) ]
430
462
pub enum PredicateKind < ' tcx > {
@@ -435,7 +467,7 @@ pub enum PredicateKind<'tcx> {
435
467
/// A trait predicate will have `Constness::Const` if it originates
436
468
/// from a bound on a `const fn` without the `?const` opt-out (e.g.,
437
469
/// `const fn foobar<Foo: Bar>() {}`).
438
- Trait ( TraitPredicate < ' tcx > , Constness ) ,
470
+ Trait ( TraitPredicate < ' tcx > , Constness , ImplicitTraitPredicate ) ,
439
471
440
472
/// `where 'a: 'b`
441
473
RegionOutlives ( RegionOutlivesPredicate < ' tcx > ) ,
@@ -724,24 +756,47 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
724
756
725
757
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < TraitRef < ' tcx > > {
726
758
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
727
- PredicateKind :: Trait ( ty:: TraitPredicate { trait_ref : self . value } , self . constness )
728
- . to_predicate ( tcx)
759
+ PredicateKind :: Trait (
760
+ ty:: TraitPredicate { trait_ref : self . value } ,
761
+ self . constness ,
762
+ ImplicitTraitPredicate :: No ,
763
+ )
764
+ . to_predicate ( tcx)
765
+ }
766
+ }
767
+
768
+ impl < ' tcx > ToPredicate < ' tcx > for ImplicitSized < ConstnessAnd < Binder < ' tcx , TraitRef < ' tcx > > > > {
769
+ fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
770
+ PredicateKind :: Trait (
771
+ ty:: TraitPredicate { trait_ref : self . 0 . value . skip_binder ( ) } ,
772
+ self . 0 . constness ,
773
+ ImplicitTraitPredicate :: Yes ,
774
+ )
775
+ . to_predicate ( tcx)
729
776
}
730
777
}
731
778
732
779
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitRef < ' tcx > > {
733
780
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
734
781
self . value
735
782
. map_bound ( |trait_ref| {
736
- PredicateKind :: Trait ( ty:: TraitPredicate { trait_ref } , self . constness )
783
+ PredicateKind :: Trait (
784
+ ty:: TraitPredicate { trait_ref } ,
785
+ self . constness ,
786
+ ImplicitTraitPredicate :: No ,
787
+ )
737
788
} )
738
789
. to_predicate ( tcx)
739
790
}
740
791
}
741
792
742
793
impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
743
794
fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
744
- self . value . map_bound ( |value| PredicateKind :: Trait ( value, self . constness ) ) . to_predicate ( tcx)
795
+ self . value
796
+ . map_bound ( |value| {
797
+ PredicateKind :: Trait ( value, self . constness , ImplicitTraitPredicate :: No )
798
+ } )
799
+ . to_predicate ( tcx)
745
800
}
746
801
}
747
802
@@ -767,7 +822,7 @@ impl<'tcx> Predicate<'tcx> {
767
822
pub fn to_opt_poly_trait_ref ( self ) -> Option < ConstnessAnd < PolyTraitRef < ' tcx > > > {
768
823
let predicate = self . kind ( ) ;
769
824
match predicate. skip_binder ( ) {
770
- PredicateKind :: Trait ( t, constness) => {
825
+ PredicateKind :: Trait ( t, constness, _ ) => {
771
826
Some ( ConstnessAnd { constness, value : predicate. rebind ( t. trait_ref ) } )
772
827
}
773
828
PredicateKind :: Projection ( ..)
@@ -1259,7 +1314,17 @@ pub trait WithConstness: Sized {
1259
1314
}
1260
1315
}
1261
1316
1317
+ pub struct ImplicitSized < T > ( T ) ;
1318
+
1319
+ pub trait WithImplicitSized : Sized {
1320
+ #[ inline]
1321
+ fn with_implicit ( self ) -> ImplicitSized < Self > {
1322
+ ImplicitSized ( self )
1323
+ }
1324
+ }
1325
+
1262
1326
impl < T > WithConstness for T { }
1327
+ impl < T > WithImplicitSized for T { }
1263
1328
1264
1329
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable ) ]
1265
1330
pub struct ParamEnvAnd < ' tcx , T > {
0 commit comments