@@ -28,7 +28,6 @@ use std::ops::ControlFlow;
28
28
29
29
use rustc_errors:: ErrorGuaranteed ;
30
30
use rustc_hir:: def:: DefKind ;
31
- use rustc_infer:: infer:: canonical:: OriginalQueryValues ;
32
31
pub use rustc_infer:: traits:: * ;
33
32
use rustc_middle:: query:: Providers ;
34
33
use rustc_middle:: span_bug;
@@ -646,13 +645,18 @@ pub fn try_evaluate_const<'tcx>(
646
645
// it is well formed as otherwise CTFE will ICE. For the same reasons as with
647
646
// deferring evaluation of generic/uninferred constants, we do not have to worry
648
647
// about `generic_const_expr`
649
- let input = infcx
650
- . canonicalize_query ( param_env. and ( uv) , & mut OriginalQueryValues :: default ( ) ) ;
651
- if !tcx. check_constant_safe_to_evaluate ( input) {
652
- let e = tcx. dcx ( ) . delayed_bug (
653
- "Attempted to evaluate illformed constant but no error emitted" ,
654
- ) ;
655
- return Err ( EvaluateConstErr :: EvaluationFailure ( e) ) ;
648
+ if tcx. instantiate_and_check_impossible_predicates ( (
649
+ uv. def ,
650
+ tcx. erase_regions ( uv. args ) ,
651
+ ) ) {
652
+ // We treat these consts as rigid instead of an error or delaying a bug as we may
653
+ // be checking a constant with a trivialy-false where clause that is satisfied from
654
+ // a trivially-false clause in the environment.
655
+ //
656
+ // Delaying a bug would ICE the compiler as trivial bounds are somewhat supported.
657
+ // Emitting an error would be fine but feels weird as we allow the where clause to be
658
+ // written.
659
+ return Ok ( ct) ;
656
660
}
657
661
658
662
let typing_env = infcx
@@ -747,50 +751,6 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
747
751
args. fold_with ( & mut ReplaceParamAndInferWithPlaceholder { tcx, idx : 0 } )
748
752
}
749
753
750
- #[ instrument( level = "debug" , skip( tcx) , ret) ]
751
- fn check_constant_safe_to_evaluate < ' tcx > (
752
- tcx : TyCtxt < ' tcx > ,
753
- input : ty:: CanonicalQueryInput < TyCtxt < ' tcx > , ty:: ParamEnvAnd < ' tcx , ty:: UnevaluatedConst < ' tcx > > > ,
754
- ) -> bool {
755
- let ( infcx, param_env_and, _) = tcx. infer_ctxt ( ) . build_with_canonical ( DUMMY_SP , & input) ;
756
- let ( param_env, uv) = param_env_and. into_parts ( ) ;
757
-
758
- // We can't just register a wf goal for the constant as that would require evaluating the constant
759
- // which would result in a query cycle.
760
- let mut predicates = tcx. predicates_of ( uv. def ) . instantiate ( tcx, uv. args ) . predicates ;
761
-
762
- // Specifically check trait fulfillment to avoid an error when trying to resolve
763
- // associated items.
764
- if let Some ( trait_def_id) = tcx. trait_of_item ( uv. def ) {
765
- let trait_ref = ty:: TraitRef :: from_method ( tcx, trait_def_id, uv. args ) ;
766
- predicates. push ( trait_ref. upcast ( tcx) ) ;
767
- }
768
-
769
- let ocx = ObligationCtxt :: new ( & infcx) ;
770
- let predicates = ocx. normalize ( & ObligationCause :: dummy ( ) , param_env, predicates) ;
771
- for predicate in predicates {
772
- let obligation = Obligation :: new ( tcx, ObligationCause :: dummy ( ) , param_env, predicate) ;
773
- ocx. register_obligation ( obligation) ;
774
- }
775
- let errors = ocx. select_all_or_error ( ) ;
776
-
777
- if !errors. is_empty ( ) {
778
- return false ;
779
- }
780
-
781
- // Leak check for any higher-ranked trait mismatches.
782
- // We only need to do this in the old solver, since the new solver already
783
- // leak-checks.
784
- if !infcx. next_trait_solver ( ) && infcx. leak_check ( ty:: UniverseIndex :: ROOT , None ) . is_err ( ) {
785
- return false ;
786
- }
787
-
788
- // We don't check non-higher-ranked region constraints, but we don't need to as region
789
- // constraints cant affect coherence and therefore result in overlapping impls in codegen/ctfe
790
- // so it shouldn't matter to speculatively evaluate constants with failing region constraints.
791
- true
792
- }
793
-
794
754
/// Normalizes the predicates and checks whether they hold in a given empty. If this
795
755
/// returns true, then either normalize encountered an error or one of the predicates did not
796
756
/// hold. Used when creating vtables to check for unsatisfiable methods. This should not be
@@ -832,7 +792,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
832
792
// Specifically check trait fulfillment to avoid an error when trying to resolve
833
793
// associated items.
834
794
if let Some ( trait_def_id) = tcx. trait_of_item ( key. 0 ) {
835
- let trait_ref = ty:: TraitRef :: from_method ( tcx, trait_def_id, key. 1 ) ;
795
+ let trait_ref = ty:: TraitRef :: from_assoc_args ( tcx, trait_def_id, key. 1 ) ;
836
796
predicates. push ( trait_ref. upcast ( tcx) ) ;
837
797
}
838
798
@@ -934,7 +894,6 @@ pub fn provide(providers: &mut Providers) {
934
894
specialization_enabled_in : specialize:: specialization_enabled_in,
935
895
instantiate_and_check_impossible_predicates,
936
896
is_impossible_associated_item,
937
- check_constant_safe_to_evaluate,
938
897
..* providers
939
898
} ;
940
899
}
0 commit comments