@@ -424,6 +424,38 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
424424 }
425425}
426426
427+ #[ derive( Clone , Copy , Debug , Eq , TyEncodable , TyDecodable , TypeFoldable ) ]
428+ pub enum ImplicitTraitPredicate {
429+ Yes ,
430+ No ,
431+ }
432+
433+ impl Hash for ImplicitTraitPredicate {
434+ fn hash < H > ( & self , _: & mut H )
435+ where
436+ H : Hasher ,
437+ {
438+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
439+ // type parameters and associated types, it has no incidence whatsoever on anything else.
440+ }
441+ }
442+
443+ impl < CTX > :: rustc_data_structures:: stable_hasher:: HashStable < CTX > for ImplicitTraitPredicate {
444+ #[ inline]
445+ fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
446+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
447+ // type parameters and associated types, it has no incidence whatsoever on anything else.
448+ }
449+ }
450+
451+ impl PartialEq for ImplicitTraitPredicate {
452+ fn eq ( & self , _: & ImplicitTraitPredicate ) -> bool {
453+ // This type is used purely for improving diagnostics involving default `Sized` bounds on
454+ // type parameters and associated types, it has no incidence whatsoever on anything else.
455+ true
456+ }
457+ }
458+
427459#[ derive( Clone , Copy , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
428460#[ derive( HashStable , TypeFoldable ) ]
429461pub enum PredicateKind < ' tcx > {
@@ -434,7 +466,7 @@ pub enum PredicateKind<'tcx> {
434466 /// A trait predicate will have `Constness::Const` if it originates
435467 /// from a bound on a `const fn` without the `?const` opt-out (e.g.,
436468 /// `const fn foobar<Foo: Bar>() {}`).
437- Trait ( TraitPredicate < ' tcx > , Constness ) ,
469+ Trait ( TraitPredicate < ' tcx > , Constness , ImplicitTraitPredicate ) ,
438470
439471 /// `where 'a: 'b`
440472 RegionOutlives ( RegionOutlivesPredicate < ' tcx > ) ,
@@ -723,24 +755,47 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
723755
724756impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < TraitRef < ' tcx > > {
725757 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
726- PredicateKind :: Trait ( ty:: TraitPredicate { trait_ref : self . value } , self . constness )
727- . to_predicate ( tcx)
758+ PredicateKind :: Trait (
759+ ty:: TraitPredicate { trait_ref : self . value } ,
760+ self . constness ,
761+ ImplicitTraitPredicate :: No ,
762+ )
763+ . to_predicate ( tcx)
764+ }
765+ }
766+
767+ impl < ' tcx > ToPredicate < ' tcx > for ImplicitSized < ConstnessAnd < Binder < ' tcx , TraitRef < ' tcx > > > > {
768+ fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
769+ PredicateKind :: Trait (
770+ ty:: TraitPredicate { trait_ref : self . 0 . value . skip_binder ( ) } ,
771+ self . 0 . constness ,
772+ ImplicitTraitPredicate :: Yes ,
773+ )
774+ . to_predicate ( tcx)
728775 }
729776}
730777
731778impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitRef < ' tcx > > {
732779 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
733780 self . value
734781 . map_bound ( |trait_ref| {
735- PredicateKind :: Trait ( ty:: TraitPredicate { trait_ref } , self . constness )
782+ PredicateKind :: Trait (
783+ ty:: TraitPredicate { trait_ref } ,
784+ self . constness ,
785+ ImplicitTraitPredicate :: No ,
786+ )
736787 } )
737788 . to_predicate ( tcx)
738789 }
739790}
740791
741792impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
742793 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
743- self . value . map_bound ( |value| PredicateKind :: Trait ( value, self . constness ) ) . to_predicate ( tcx)
794+ self . value
795+ . map_bound ( |value| {
796+ PredicateKind :: Trait ( value, self . constness , ImplicitTraitPredicate :: No )
797+ } )
798+ . to_predicate ( tcx)
744799 }
745800}
746801
@@ -766,7 +821,7 @@ impl<'tcx> Predicate<'tcx> {
766821 pub fn to_opt_poly_trait_ref ( self ) -> Option < ConstnessAnd < PolyTraitRef < ' tcx > > > {
767822 let predicate = self . kind ( ) ;
768823 match predicate. skip_binder ( ) {
769- PredicateKind :: Trait ( t, constness) => {
824+ PredicateKind :: Trait ( t, constness, _ ) => {
770825 Some ( ConstnessAnd { constness, value : predicate. rebind ( t. trait_ref ) } )
771826 }
772827 PredicateKind :: Projection ( ..)
@@ -1264,7 +1319,17 @@ pub trait WithConstness: Sized {
12641319 }
12651320}
12661321
1322+ pub struct ImplicitSized < T > ( T ) ;
1323+
1324+ pub trait WithImplicitSized : Sized {
1325+ #[ inline]
1326+ fn with_implicit ( self ) -> ImplicitSized < Self > {
1327+ ImplicitSized ( self )
1328+ }
1329+ }
1330+
12671331impl < T > WithConstness for T { }
1332+ impl < T > WithImplicitSized for T { }
12681333
12691334#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable ) ]
12701335pub struct ParamEnvAnd < ' tcx , T > {
0 commit comments