Skip to content

Commit 9300617

Browse files
authored
Rollup merge of #107863 - compiler-errors:new-solver-multiple-candidates, r=jackh726
Allow multiple candidates with same response in new solver Treat >1 candidates as *not* ambiguous if they return the same response.
2 parents dd5e4ad + 3c4e1f8 commit 9300617

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4773,6 +4773,7 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
47734773
name = "rustc_trait_selection"
47744774
version = "0.0.0"
47754775
dependencies = [
4776+
"itertools",
47764777
"rustc_ast",
47774778
"rustc_attr",
47784779
"rustc_data_structures",

compiler/rustc_trait_selection/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ rustc_span = { path = "../rustc_span" }
2424
rustc_target = { path = "../rustc_target" }
2525
rustc_transmute = { path = "../rustc_transmute", features = ["rustc"] }
2626
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
27+
itertools = "0.10.1"

compiler/rustc_trait_selection/src/solve/assembly.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
44
#[cfg(doc)]
55
use super::trait_goals::structural_traits::*;
66
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
7+
use itertools::Itertools;
78
use rustc_hir::def_id::DefId;
89
use rustc_infer::traits::query::NoSolution;
910
use rustc_infer::traits::util::elaborate_predicates;
@@ -489,9 +490,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
489490
i += 1;
490491
}
491492

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

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

tests/ui/traits/new-solver/provisional-result-done.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// known-bug: unknown
21
// compile-flags: -Ztrait-solver=next
2+
// check-pass
33

44
// This tests checks that we update results in the provisional cache when
55
// we pop a goal from the stack.

tests/ui/traits/new-solver/provisional-result-done.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)