Skip to content

Commit

Permalink
Multiple candidates with same response is not ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 10, 2023
1 parent 8996ea9 commit 3c4e1f8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,7 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
name = "rustc_trait_selection"
version = "0.0.0"
dependencies = [
"itertools",
"rustc_ast",
"rustc_attr",
"rustc_data_structures",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
itertools = "0.10.1"
8 changes: 5 additions & 3 deletions compiler/rustc_trait_selection/src/solve/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
#[cfg(doc)]
use super::trait_goals::structural_traits::*;
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
use itertools::Itertools;
use rustc_hir::def_id::DefId;
use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::util::elaborate_predicates;
Expand Down Expand Up @@ -489,9 +490,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
i += 1;
}

// If there are *STILL* multiple candidates, give up
// and report ambiguity.
if candidates.len() > 1 {
// If there are *STILL* multiple candidates that have *different* response
// results, give up and report ambiguity.
if candidates.len() > 1 && !candidates.iter().map(|cand| cand.result).all_equal() {
let certainty = if candidates.iter().all(|x| {
matches!(x.result.value.certainty, Certainty::Maybe(MaybeCause::Overflow))
}) {
Expand All @@ -503,6 +504,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
}

// FIXME: What if there are >1 candidates left with the same response, and one is a reservation impl?
Ok(self.discard_reservation_impl(candidates.pop().unwrap()).result)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/new-solver/provisional-result-done.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// known-bug: unknown
// compile-flags: -Ztrait-solver=next
// check-pass

// This tests checks that we update results in the provisional cache when
// we pop a goal from the stack.
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/traits/new-solver/provisional-result-done.stderr

This file was deleted.

0 comments on commit 3c4e1f8

Please sign in to comment.