Skip to content

Don't ICE when codegen_select_candidate returns ambiguity in new solver #124374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,11 @@ fn resolve_associated_item<'tcx>(

let vtbl = match tcx.codegen_select_candidate((param_env, trait_ref)) {
Ok(vtbl) => vtbl,
Err(CodegenObligationError::Ambiguity) => {
let reported = tcx.dcx().span_delayed_bug(
tcx.def_span(trait_item_id),
format!(
"encountered ambiguity selecting `{trait_ref:?}` during codegen, presuming due to \
overflow or prior type error",
),
);
return Err(reported);
}
Err(CodegenObligationError::Unimplemented) => return Ok(None),
Err(CodegenObligationError::FulfillmentError) => return Ok(None),
Err(
CodegenObligationError::Ambiguity
| CodegenObligationError::Unimplemented
| CodegenObligationError::FulfillmentError,
) => return Ok(None),
};

// Now that we know which impl is being used, we can dispatch to
Expand Down
1 change: 0 additions & 1 deletion tests/ui/issues/issue-69602-type-err-during-codegen-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ impl TraitB for B { //~ ERROR not all trait items implemented, missing: `MyA`

fn main() {
let _ = [0; B::VALUE];
//~^ constant
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ LL | type MyA: TraitA;
LL | impl TraitB for B {
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation

note: erroneous constant encountered
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:21:17
|
LL | let _ = [0; B::VALUE];
| ^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0046, E0437.
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/traits/next-solver/ambiguous-impl-in-resolve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ check-pass
//@ compile-flags: -Znext-solver

trait Local {}

trait Overlap { fn f(); }
impl<T> Overlap for Option<T> where Self: Clone, { fn f() {} }
impl<T> Overlap for Option<T> where Self: Local, { fn f() {} }

fn test<T>()
where
Option<T>: Clone + Local,
{
<Option<T> as Overlap>::f();
}

fn main() {}
Loading