Skip to content
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

Allow multiple candidates with same response in new solver #107863

Merged
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
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() {
Copy link
Member Author

@compiler-errors compiler-errors Feb 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could also take the intersection of the candidates' certainty... but if they're not all Certainty::Yes then we already return ambiguous, so I think this has the same effect.

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.