Skip to content

Commit 20b9ec8

Browse files
committed
Auto merge of #116530 - aliemjay:ice-on-ambiguity, r=compiler-errors
delay a bug when encountering an ambiguity in MIR typeck We shouldn't have any trait selection ambiguities in MIR typeck. See #114586 (comment) r? `@oli-obk` `@compiler-errors` `@lcnr`
2 parents 093b9d5 + 710c073 commit 20b9ec8

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,18 @@ where
157157
}
158158

159159
let mut region_constraints = QueryRegionConstraints::default();
160-
let (output, error_info, mut obligations, _) =
161-
Q::fully_perform_into(self, infcx, &mut region_constraints).map_err(|_| {
162-
infcx.tcx.sess.delay_span_bug(span, format!("error performing {self:?}"))
163-
})?;
160+
let (output, error_info, mut obligations) =
161+
Q::fully_perform_into(self, infcx, &mut region_constraints)
162+
.map_err(|_| {
163+
infcx.tcx.sess.delay_span_bug(span, format!("error performing {self:?}"))
164+
})
165+
.and_then(|(output, error_info, obligations, certainty)| match certainty {
166+
Certainty::Proven => Ok((output, error_info, obligations)),
167+
Certainty::Ambiguous => Err(infcx
168+
.tcx
169+
.sess
170+
.delay_span_bug(span, format!("ambiguity performing {self:?}"))),
171+
})?;
164172

165173
// Typically, instantiating NLL query results does not
166174
// create obligations. However, in some cases there
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
2+
3+
error: internal compiler error: ambiguity performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }))), bound_vars: [] } } }
4+
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5
5+
|
6+
LL | query(get_rpit);
7+
| ^^^^^^^^^^^^^^^
8+
|
9+
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5
10+
|
11+
LL | query(get_rpit);
12+
| ^^^^^^^^^^^^^^^
13+
14+
15+
16+
17+
query stack during panic:
18+
end of query stack
19+
error: aborting due to 2 previous errors
20+

tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
88
// revisions: current next
99
//[next] compile-flags: -Ztrait-solver=next
10-
// check-pass
10+
//[next] check-pass
11+
12+
//[current] known-bug: #108498
13+
//[current] failure-status: 101
14+
//[current] normalize-stderr-test: "DefId\(.*?\]::" -> "DefId("
15+
//[current] normalize-stderr-test: "(?m)^note: .*\n" -> ""
16+
//[current] normalize-stderr-test: "(?m)^ *\d+: .*\n" -> ""
17+
//[current] normalize-stderr-test: "(?m)^ *at .*\n" -> ""
1118

1219
#![feature(type_alias_impl_trait)]
1320

0 commit comments

Comments
 (0)