diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 946e6e77a3d..c2a7be80467 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2544,7 +2544,10 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let obligation = Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred); - self.predicate_may_hold(&obligation) + // We don't use `InferCtxt::predicate_may_hold` because that + // will re-run predicates that overflow locally, which ends up + // taking a really long time to compute. + self.evaluate_obligation(&obligation).map_or(false, |eval| eval.may_apply()) }) } diff --git a/src/test/ui/traits/predicate_can_apply-hang.rs b/src/test/ui/traits/predicate_can_apply-hang.rs new file mode 100644 index 00000000000..5f01645da52 --- /dev/null +++ b/src/test/ui/traits/predicate_can_apply-hang.rs @@ -0,0 +1,6 @@ +fn f(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq { + //~^ ERROR can't compare `Vec<[[[B; 1]; 1]; 1]>` with `B` + x +} + +fn main() {} diff --git a/src/test/ui/traits/predicate_can_apply-hang.stderr b/src/test/ui/traits/predicate_can_apply-hang.stderr new file mode 100644 index 00000000000..49fe63b412a --- /dev/null +++ b/src/test/ui/traits/predicate_can_apply-hang.stderr @@ -0,0 +1,21 @@ +error[E0277]: can't compare `Vec<[[[B; 1]; 1]; 1]>` with `B` + --> $DIR/predicate_can_apply-hang.rs:1:38 + | +LL | fn f(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq { + | ^^^^^^^^^^^^^^^^^ no implementation for `Vec<[[[B; 1]; 1]; 1]> == B` +LL | +LL | x + | - return type was inferred to be `Vec<[[[B; 1]; 1]; 1]>` here + | + = help: the trait `PartialEq` is not implemented for `Vec<[[[B; 1]; 1]; 1]>` + = help: the following other types implement trait `PartialEq`: + as PartialEq>> + as PartialEq<&[U; N]>> + as PartialEq<&[U]>> + as PartialEq<&mut [U]>> + as PartialEq<[U; N]>> + as PartialEq<[U]>> + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`.