Skip to content

Commit

Permalink
Do not need to account for overflow in predicate_can_apply
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 23, 2022
1 parent 604d521 commit cbe9328
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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())
})
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/traits/predicate_can_apply-hang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn f<B>(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq<B> {
//~^ ERROR can't compare `Vec<[[[B; 1]; 1]; 1]>` with `B`
x
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/traits/predicate_can_apply-hang.stderr
Original file line number Diff line number Diff line change
@@ -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<B>(x: Vec<[[[B; 1]; 1]; 1]>) -> impl PartialEq<B> {
| ^^^^^^^^^^^^^^^^^ 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<B>` is not implemented for `Vec<[[[B; 1]; 1]; 1]>`
= help: the following other types implement trait `PartialEq<Rhs>`:
<Vec<T, A1> as PartialEq<Vec<U, A2>>>
<Vec<T, A> as PartialEq<&[U; N]>>
<Vec<T, A> as PartialEq<&[U]>>
<Vec<T, A> as PartialEq<&mut [U]>>
<Vec<T, A> as PartialEq<[U; N]>>
<Vec<T, A> as PartialEq<[U]>>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit cbe9328

Please sign in to comment.