Skip to content

Commit 09f2981

Browse files
Implement a dummy drop-in-favor-of for the new solver
1 parent a447e66 commit 09f2981

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

compiler/rustc_trait_selection/src/solve/project_goals.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::traits::{specialization_graph, translate_substs};
33
use super::assembly::{self, Candidate, CandidateSource};
44
use super::infcx_ext::InferCtxtExt;
55
use super::trait_goals::structural_traits;
6-
use super::{Certainty, EvalCtxt, Goal, QueryResult};
6+
use super::{Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
77
use rustc_errors::ErrorGuaranteed;
88
use rustc_hir::def::DefKind;
99
use rustc_hir::def_id::DefId;
@@ -182,11 +182,17 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
182182
// If there are *STILL* multiple candidates, give up
183183
// and report ambiguity.
184184
i += 1;
185-
if i > 1 {
186-
debug!("multiple matches, ambig");
187-
// FIXME: return overflow if all candidates overflow, otherwise return ambiguity.
188-
unimplemented!();
189-
}
185+
}
186+
187+
if candidates.len() > 1 {
188+
let certainty = if candidates.iter().all(|x| {
189+
matches!(x.result.value.certainty, Certainty::Maybe(MaybeCause::Overflow))
190+
}) {
191+
Certainty::Maybe(MaybeCause::Overflow)
192+
} else {
193+
Certainty::AMBIGUOUS
194+
};
195+
return self.make_canonical_response(certainty);
190196
}
191197
}
192198

@@ -203,7 +209,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
203209
(CandidateSource::Impl(_), _)
204210
| (CandidateSource::ParamEnv(_), _)
205211
| (CandidateSource::BuiltinImpl, _)
206-
| (CandidateSource::AliasBound, _) => unimplemented!(),
212+
| (CandidateSource::AliasBound, _) => false,
207213
}
208214
}
209215
}
@@ -452,7 +458,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
452458
[ty::GenericArg::from(goal.predicate.self_ty())],
453459
));
454460

455-
let is_sized_certainty = ecx.evaluate_goal(goal.with(tcx, sized_predicate))?.1;
461+
let (_, is_sized_certainty) =
462+
ecx.evaluate_goal(goal.with(tcx, sized_predicate))?;
456463
return ecx.eq_term_and_make_canonical_response(
457464
goal,
458465
is_sized_certainty,

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::iter;
44

55
use super::assembly::{self, Candidate, CandidateSource};
66
use super::infcx_ext::InferCtxtExt;
7-
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult};
7+
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
88
use rustc_hir::def_id::DefId;
99
use rustc_infer::infer::InferCtxt;
1010
use rustc_infer::traits::query::NoSolution;
@@ -511,11 +511,17 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
511511
// If there are *STILL* multiple candidates, give up
512512
// and report ambiguity.
513513
i += 1;
514-
if i > 1 {
515-
debug!("multiple matches, ambig");
516-
// FIXME: return overflow if all candidates overflow, otherwise return ambiguity.
517-
unimplemented!();
518-
}
514+
}
515+
516+
if candidates.len() > 1 {
517+
let certainty = if candidates.iter().all(|x| {
518+
matches!(x.result.value.certainty, Certainty::Maybe(MaybeCause::Overflow))
519+
}) {
520+
Certainty::Maybe(MaybeCause::Overflow)
521+
} else {
522+
Certainty::AMBIGUOUS
523+
};
524+
return self.make_canonical_response(certainty);
519525
}
520526
}
521527

@@ -532,17 +538,18 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
532538
(CandidateSource::Impl(_), _)
533539
| (CandidateSource::ParamEnv(_), _)
534540
| (CandidateSource::AliasBound, _)
535-
| (CandidateSource::BuiltinImpl, _) => unimplemented!(),
541+
| (CandidateSource::BuiltinImpl, _) => false,
536542
}
537543
}
538544

539-
fn discard_reservation_impl(&self, candidate: Candidate<'tcx>) -> Candidate<'tcx> {
545+
fn discard_reservation_impl(&self, mut candidate: Candidate<'tcx>) -> Candidate<'tcx> {
540546
if let CandidateSource::Impl(def_id) = candidate.source {
541547
if let ty::ImplPolarity::Reservation = self.tcx().impl_polarity(def_id) {
542548
debug!("Selected reservation impl");
543-
// FIXME: reduce candidate to ambiguous
544-
// FIXME: replace `var_values` with identity, yeet external constraints.
545-
unimplemented!()
549+
// We assemble all candidates inside of a probe so by
550+
// making a new canonical response here our result will
551+
// have no constraints.
552+
candidate.result = self.make_canonical_response(Certainty::AMBIGUOUS).unwrap();
546553
}
547554
}
548555

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
// Checks that we don't explode when we assemble >1 candidate for a goal.
5+
6+
struct Wrapper<T>(T);
7+
8+
trait Foo {}
9+
10+
impl Foo for Wrapper<i32> {}
11+
12+
impl Foo for Wrapper<()> {}
13+
14+
fn needs_foo(_: impl Foo) {}
15+
16+
fn main() {
17+
let mut x = Default::default();
18+
let w = Wrapper(x);
19+
needs_foo(w);
20+
x = 1;
21+
drop(x);
22+
}

0 commit comments

Comments
 (0)