@@ -37,11 +37,12 @@ use rustc_middle::hir::map::Map;
37
37
use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
38
38
use rustc_middle:: mir:: mono:: Linkage ;
39
39
use rustc_middle:: ty:: query:: Providers ;
40
- use rustc_middle:: ty:: subst:: InternalSubsts ;
40
+ use rustc_middle:: ty:: subst:: { InternalSubsts , SubstsRef } ;
41
41
use rustc_middle:: ty:: util:: Discr ;
42
42
use rustc_middle:: ty:: util:: IntTypeExt ;
43
43
use rustc_middle:: ty:: { self , AdtKind , Const , ToPolyTraitRef , Ty , TyCtxt } ;
44
44
use rustc_middle:: ty:: { ReprOptions , ToPredicate , WithConstness } ;
45
+ use rustc_middle:: ty:: { TypeFoldable , TypeVisitor } ;
45
46
use rustc_session:: config:: SanitizerSet ;
46
47
use rustc_session:: lint;
47
48
use rustc_session:: parse:: feature_err;
@@ -50,6 +51,8 @@ use rustc_span::{Span, DUMMY_SP};
50
51
use rustc_target:: spec:: abi;
51
52
use rustc_trait_selection:: traits:: error_reporting:: suggestions:: NextTypeParamName ;
52
53
54
+ use smallvec:: SmallVec ;
55
+
53
56
mod type_of;
54
57
55
58
struct OnlySelfBounds ( bool ) ;
@@ -1672,10 +1675,46 @@ fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicate
1672
1675
. alloc_from_iter ( result. predicates . iter ( ) . chain ( inferred_outlives) . copied ( ) ) ;
1673
1676
}
1674
1677
}
1678
+
1679
+ if tcx. features ( ) . const_evaluatable_checked {
1680
+ let const_evaluatable = const_evaluatable_predicates_of ( tcx, def_id, & result) ;
1681
+ result. predicates =
1682
+ tcx. arena . alloc_from_iter ( result. predicates . iter ( ) . copied ( ) . chain ( const_evaluatable) ) ;
1683
+ }
1684
+
1675
1685
debug ! ( "predicates_defined_on({:?}) = {:?}" , def_id, result) ;
1676
1686
result
1677
1687
}
1678
1688
1689
+ pub fn const_evaluatable_predicates_of < ' tcx > (
1690
+ tcx : TyCtxt < ' tcx > ,
1691
+ def_id : DefId ,
1692
+ predicates : & ty:: GenericPredicates < ' tcx > ,
1693
+ ) -> impl Iterator < Item = ( ty:: Predicate < ' tcx > , Span ) > {
1694
+ #[ derive( Default ) ]
1695
+ struct ConstCollector < ' tcx > {
1696
+ ct : SmallVec < [ ( ty:: WithOptConstParam < DefId > , SubstsRef < ' tcx > ) ; 4 ] > ,
1697
+ }
1698
+
1699
+ impl < ' tcx > TypeVisitor < ' tcx > for ConstCollector < ' tcx > {
1700
+ fn visit_const ( & mut self , ct : & ' tcx Const < ' tcx > ) -> bool {
1701
+ if let ty:: ConstKind :: Unevaluated ( def, substs, None ) = ct. val {
1702
+ self . ct . push ( ( def, substs) ) ;
1703
+ }
1704
+ false
1705
+ }
1706
+ }
1707
+
1708
+ let mut collector = ConstCollector :: default ( ) ;
1709
+ for ( pred, _span) in predicates. predicates . iter ( ) {
1710
+ pred. visit_with ( & mut collector) ;
1711
+ }
1712
+ warn ! ( "const_evaluatable_predicates_of({:?}) = {:?}" , def_id, collector. ct) ;
1713
+ collector. ct . into_iter ( ) . map ( move |( def_id, subst) | {
1714
+ ( ty:: PredicateAtom :: ConstEvaluatable ( def_id, subst) . to_predicate ( tcx) , DUMMY_SP )
1715
+ } )
1716
+ }
1717
+
1679
1718
/// Returns a list of all type predicates (explicit and implicit) for the definition with
1680
1719
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
1681
1720
/// `Self: Trait` predicates for traits.
0 commit comments