@@ -15,6 +15,7 @@ use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst,
1515use rustc_middle:: ty:: { self , GenericParamDefKind , Ty , TyCtxt } ;
1616use rustc_middle:: ty:: { ToPolyTraitRef , ToPredicate } ;
1717use rustc_span:: def_id:: DefId ;
18+ use rustc_span:: sym;
1819
1920use crate :: traits:: project:: { normalize_with_depth, normalize_with_depth_to} ;
2021use crate :: traits:: util:: { self , closure_trait_ref_and_return_type, predicate_for_trait_def} ;
@@ -44,6 +45,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
4445 ) -> Result < Selection < ' tcx > , SelectionError < ' tcx > > {
4546 // let new_obligation;
4647
48+ // when const_trait_impl not enabled, all const predicates are unimplemented
49+ if obligation. predicate . constness ( ) == ty:: ConstnessArg :: Const {
50+ if !self . tcx ( ) . features ( ) . enabled ( sym:: const_trait_impl) {
51+ return Err ( SelectionError :: Unimplemented )
52+ }
53+ }
54+ // TODO rm
4755 // HACK(const_trait_impl): the surrounding environment is remapped to a non-const context
4856 // because nested obligations might be actually `~const` then (incorrectly) requiring
4957 // const impls. for example:
@@ -1233,10 +1241,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12331241 . rebind ( ty:: TraitPredicate {
12341242 trait_ref : ty:: TraitRef {
12351243 def_id : self . tcx ( ) . require_lang_item ( LangItem :: Destruct , None ) ,
1236- substs : self . tcx ( ) . mk_substs_trait (
1237- nested_ty,
1238- & [ ty:: ConstnessArg :: Const . into ( ) ] ,
1239- ) ,
1244+ substs : self
1245+ . tcx ( )
1246+ . mk_substs_trait ( nested_ty, & [ ty:: ConstnessArg :: Const . into ( ) ] ) ,
12401247 } ,
12411248 polarity : ty:: ImplPolarity :: Positive ,
12421249 } )
0 commit comments