Skip to content

Commit 6c21abf

Browse files
authored
Rollup merge of #124374 - compiler-errors:fix-ambiguity-ice, r=lcnr
Don't ICE when `codegen_select_candidate` returns ambiguity in new solver Because we merge identical candidates, we may have >1 impl candidate to in `codegen_select_error` but *not* have a trait error. r? lcnr
2 parents 60c825f + cc60617 commit 6c21abf

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

compiler/rustc_ty_utils/src/instance.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,11 @@ fn resolve_associated_item<'tcx>(
101101

102102
let vtbl = match tcx.codegen_select_candidate((param_env, trait_ref)) {
103103
Ok(vtbl) => vtbl,
104-
Err(CodegenObligationError::Ambiguity) => {
105-
let reported = tcx.dcx().span_delayed_bug(
106-
tcx.def_span(trait_item_id),
107-
format!(
108-
"encountered ambiguity selecting `{trait_ref:?}` during codegen, presuming due to \
109-
overflow or prior type error",
110-
),
111-
);
112-
return Err(reported);
113-
}
114-
Err(CodegenObligationError::Unimplemented) => return Ok(None),
115-
Err(CodegenObligationError::FulfillmentError) => return Ok(None),
104+
Err(
105+
CodegenObligationError::Ambiguity
106+
| CodegenObligationError::Unimplemented
107+
| CodegenObligationError::FulfillmentError,
108+
) => return Ok(None),
116109
};
117110

118111
// Now that we know which impl is being used, we can dispatch to

tests/ui/issues/issue-69602-type-err-during-codegen-ice.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ impl TraitB for B { //~ ERROR not all trait items implemented, missing: `MyA`
1919

2020
fn main() {
2121
let _ = [0; B::VALUE];
22-
//~^ constant
2322
}

tests/ui/issues/issue-69602-type-err-during-codegen-ice.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ LL | type MyA: TraitA;
1313
LL | impl TraitB for B {
1414
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation
1515

16-
note: erroneous constant encountered
17-
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:21:17
18-
|
19-
LL | let _ = [0; B::VALUE];
20-
| ^^^^^^^^
21-
2216
error: aborting due to 2 previous errors
2317

2418
Some errors have detailed explanations: E0046, E0437.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
4+
trait Local {}
5+
6+
trait Overlap { fn f(); }
7+
impl<T> Overlap for Option<T> where Self: Clone, { fn f() {} }
8+
impl<T> Overlap for Option<T> where Self: Local, { fn f() {} }
9+
10+
fn test<T>()
11+
where
12+
Option<T>: Clone + Local,
13+
{
14+
<Option<T> as Overlap>::f();
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)