Skip to content

Commit eba03a1

Browse files
Clear nested candidates in select if certainty is yes
1 parent aae43c4 commit eba03a1

File tree

1 file changed

+8
-1
lines changed
  • compiler/rustc_trait_selection/src/solve

1 file changed

+8
-1
lines changed

compiler/rustc_trait_selection/src/solve/select.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_infer::traits::{
1010
use rustc_macros::extension;
1111
use rustc_middle::{bug, span_bug};
1212
use rustc_span::Span;
13+
use thin_vec::ThinVec;
1314

1415
use crate::solve::inspect::{self, ProofTreeInferCtxtExt};
1516

@@ -147,7 +148,7 @@ fn to_selection<'tcx>(
147148
}
148149

149150
let (nested, impl_args) = cand.instantiate_nested_goals_and_opt_impl_args(span);
150-
let nested = nested
151+
let mut nested: ThinVec<_> = nested
151152
.into_iter()
152153
.map(|nested| {
153154
Obligation::new(
@@ -159,6 +160,12 @@ fn to_selection<'tcx>(
159160
})
160161
.collect();
161162

163+
// Drop nested goals from selection since they can't constrain the impl args
164+
// further if they're unambiguous.
165+
if let Ok(Certainty::Yes) = cand.result() {
166+
nested.clear();
167+
}
168+
162169
Some(match cand.kind() {
163170
ProbeKind::TraitCandidate { source, result: _ } => match source {
164171
CandidateSource::Impl(impl_def_id) => {

0 commit comments

Comments
 (0)