Skip to content

Commit c563296

Browse files
authoredJun 16, 2023
Rollup merge of #112163 - bvanjoi:fix-105231-2, r=compiler-errors
fix: inline `predicate_may_hold_fatal` and remove expect call in it - Fixes #105231 - Discussion: #111985 (comment) r? ``@compiler-errors``
2 parents 0966f32 + b792198 commit c563296

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed
 

‎compiler/rustc_trait_selection/src/traits/coherence.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ fn impl_intersection_has_impossible_obligation<'cx, 'tcx>(
292292
Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, predicate)
293293
})
294294
.chain(obligations)
295-
.find(|o| !selcx.predicate_may_hold_fatal(o));
295+
.find(|o| {
296+
selcx.evaluate_root_obligation(o).map_or(
297+
false, // Overflow has occurred, and treat the obligation as possibly holding.
298+
|result| !result.may_apply(),
299+
)
300+
});
296301

297302
if let Some(failing_obligation) = opt_failing_obligation {
298303
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -518,19 +518,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
518518
// The result is "true" if the obligation *may* hold and "false" if
519519
// we can be sure it does not.
520520

521-
/// Evaluates whether the obligation `obligation` can be satisfied (by any means).
522-
pub fn predicate_may_hold_fatal(&mut self, obligation: &PredicateObligation<'tcx>) -> bool {
523-
debug!(?obligation, "predicate_may_hold_fatal");
524-
525-
// This fatal query is a stopgap that should only be used in standard mode,
526-
// where we do not expect overflow to be propagated.
527-
assert!(self.query_mode == TraitQueryMode::Standard);
528-
529-
self.evaluate_root_obligation(obligation)
530-
.expect("Overflow should be caught earlier in standard query mode")
531-
.may_apply()
532-
}
533-
534521
/// Evaluates whether the obligation `obligation` can be satisfied
535522
/// and returns an `EvaluationResult`. This is meant for the
536523
/// *initial* call.

‎tests/ui/traits/issue-105231.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//~ ERROR overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send`
2+
struct A<T>(B<T>);
3+
//~^ ERROR recursive types `A` and `B` have infinite size
4+
struct B<T>(A<A<T>>);
5+
trait Foo {}
6+
impl<T> Foo for T where T: Send {}
7+
impl Foo for B<u8> {}
8+
9+
fn main() {}

‎tests/ui/traits/issue-105231.stderr

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0072]: recursive types `A` and `B` have infinite size
2+
--> $DIR/issue-105231.rs:2:1
3+
|
4+
LL | struct A<T>(B<T>);
5+
| ^^^^^^^^^^^ ---- recursive without indirection
6+
LL |
7+
LL | struct B<T>(A<A<T>>);
8+
| ^^^^^^^^^^^ ------- recursive without indirection
9+
|
10+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
11+
|
12+
LL ~ struct A<T>(Box<B<T>>);
13+
LL |
14+
LL ~ struct B<T>(Box<A<A<T>>>);
15+
|
16+
17+
error[E0275]: overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send`
18+
|
19+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_105231`)
20+
note: required because it appears within the type `B<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<u8>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
21+
--> $DIR/issue-105231.rs:4:8
22+
|
23+
LL | struct B<T>(A<A<T>>);
24+
| ^
25+
26+
error: aborting due to 2 previous errors
27+
28+
Some errors have detailed explanations: E0072, E0275.
29+
For more information about an error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)
Please sign in to comment.