Skip to content

Commit 1ffc6ca

Browse files
Consider a goal as NOT changed if its response is identity modulo regions
1 parent 99f60ec commit 1ffc6ca

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
344344
Ok(response) => response,
345345
};
346346

347-
let has_changed = !canonical_response.value.var_values.is_identity()
347+
let has_changed = !canonical_response.value.var_values.is_identity_modulo_regions()
348348
|| !canonical_response.value.external_constraints.opaque_types.is_empty();
349349
let (certainty, nested_goals) = match self.instantiate_and_apply_query_response(
350350
goal.param_env,

tests/ui/impl-trait/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// revisions: current next
2-
//[next] compile-flag: -Ztrait-solver=next
2+
//[next] compile-flags: -Ztrait-solver=next
33
// check-pass
44

55
use std::path::Path;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
trait Eq<'a, 'b, T> {}
5+
6+
trait Ambig {}
7+
impl Ambig for () {}
8+
9+
impl<'a, T> Eq<'a, 'a, T> for () where T: Ambig {}
10+
11+
fn eq<'a, 'b, T>(t: T)
12+
where
13+
(): Eq<'a, 'b, T>,
14+
{
15+
}
16+
17+
fn test<'r>() {
18+
let mut x = Default::default();
19+
20+
// When we evaluate `(): Eq<'r, 'r, ?0>` we uniquify the regions.
21+
// That leads us to evaluate `(): Eq<'?0, '?1, ?0>`. The response of this
22+
// will be ambiguous (because `?0: Ambig` is ambig) and also not an "identity"
23+
// response, since the region constraints will contain `'?0 == '?1` (so
24+
// `is_changed` will return true). Since it's both ambig and changed,
25+
// fulfillment will both re-register the goal AND loop again. This hits the
26+
// overflow limit. This should neither be considered overflow, nor ICE.
27+
eq::<'r, 'r, _>(x);
28+
29+
x = ();
30+
}
31+
32+
fn main() {}

0 commit comments

Comments
 (0)