@@ -425,6 +425,38 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
425425 }
426426}
427427
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+
428460#[ derive( Clone , Copy , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
429461#[ derive( HashStable , TypeFoldable ) ]
430462pub enum PredicateKind < ' tcx > {
@@ -435,7 +467,7 @@ pub enum PredicateKind<'tcx> {
435467 /// A trait predicate will have `Constness::Const` if it originates
436468 /// from a bound on a `const fn` without the `?const` opt-out (e.g.,
437469 /// `const fn foobar<Foo: Bar>() {}`).
438- Trait ( TraitPredicate < ' tcx > , Constness ) ,
470+ Trait ( TraitPredicate < ' tcx > , Constness , ImplicitTraitPredicate ) ,
439471
440472 /// `where 'a: 'b`
441473 RegionOutlives ( RegionOutlivesPredicate < ' tcx > ) ,
@@ -724,24 +756,47 @@ impl ToPredicate<'tcx> for PredicateKind<'tcx> {
724756
725757impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < TraitRef < ' tcx > > {
726758 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)
729776 }
730777}
731778
732779impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitRef < ' tcx > > {
733780 fn to_predicate ( self , tcx : TyCtxt < ' tcx > ) -> Predicate < ' tcx > {
734781 self . value
735782 . 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+ )
737788 } )
738789 . to_predicate ( tcx)
739790 }
740791}
741792
742793impl < ' tcx > ToPredicate < ' tcx > for ConstnessAnd < PolyTraitPredicate < ' tcx > > {
743794 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)
745800 }
746801}
747802
@@ -767,7 +822,7 @@ impl<'tcx> Predicate<'tcx> {
767822 pub fn to_opt_poly_trait_ref ( self ) -> Option < ConstnessAnd < PolyTraitRef < ' tcx > > > {
768823 let predicate = self . kind ( ) ;
769824 match predicate. skip_binder ( ) {
770- PredicateKind :: Trait ( t, constness) => {
825+ PredicateKind :: Trait ( t, constness, _ ) => {
771826 Some ( ConstnessAnd { constness, value : predicate. rebind ( t. trait_ref ) } )
772827 }
773828 PredicateKind :: Projection ( ..)
@@ -1259,7 +1314,17 @@ pub trait WithConstness: Sized {
12591314 }
12601315}
12611316
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+
12621326impl < T > WithConstness for T { }
1327+ impl < T > WithImplicitSized for T { }
12631328
12641329#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable ) ]
12651330pub struct ParamEnvAnd < ' tcx , T > {
0 commit comments