Skip to content

Commit 1708ad6

Browse files
committed
update recursion depth in confirm_candidate
1 parent 19ca569 commit 1708ad6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

compiler/rustc_middle/src/traits/mod.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ impl<'tcx, N> ImplSource<'tcx, N> {
701701
}
702702

703703
pub fn borrow_nested_obligations(&self) -> &[N] {
704-
match &self {
705-
ImplSource::UserDefined(i) => &i.nested[..],
706-
ImplSource::Param(n, _) => &n,
704+
match self {
705+
ImplSource::UserDefined(i) => &i.nested,
706+
ImplSource::Param(n, _) => n,
707707
ImplSource::Builtin(i) => &i.nested,
708708
ImplSource::AutoImpl(d) => &d.nested,
709709
ImplSource::Closure(c) => &c.nested,
@@ -717,6 +717,23 @@ impl<'tcx, N> ImplSource<'tcx, N> {
717717
}
718718
}
719719

720+
pub fn borrow_nested_obligations_mut(&mut self) -> &mut [N] {
721+
match self {
722+
ImplSource::UserDefined(i) => &mut i.nested,
723+
ImplSource::Param(n, _) => n,
724+
ImplSource::Builtin(i) => &mut i.nested,
725+
ImplSource::AutoImpl(d) => &mut d.nested,
726+
ImplSource::Closure(c) => &mut c.nested,
727+
ImplSource::Generator(c) => &mut c.nested,
728+
ImplSource::Future(c) => &mut c.nested,
729+
ImplSource::Object(d) => &mut d.nested,
730+
ImplSource::FnPointer(d) => &mut d.nested,
731+
ImplSource::TraitAlias(d) => &mut d.nested,
732+
ImplSource::TraitUpcasting(d) => &mut d.nested,
733+
ImplSource::ConstDestruct(i) => &mut i.nested,
734+
}
735+
}
736+
720737
pub fn map<M, F>(self, f: F) -> ImplSource<'tcx, M>
721738
where
722739
F: FnMut(N) -> M,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
132132
}
133133
};
134134

135+
// The obligations returned by confirmation are recursively evaluated
136+
// so we need to make sure they have the correct depth.
137+
for subobligation in impl_src.borrow_nested_obligations_mut() {
138+
subobligation.set_depth_from_parent(obligation.recursion_depth);
139+
}
140+
135141
if !obligation.predicate.is_const_if_const() {
136142
// normalize nested predicates according to parent predicate's constness.
137143
impl_src = impl_src.map(|mut o| {

0 commit comments

Comments
 (0)