Skip to content

Commit a365f58

Browse files
lcnrcuviper
authored andcommitted
update recursion depth in confirm_candidate
(cherry picked from commit 1708ad6)
1 parent 1a42cb7 commit a365f58

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ impl<'tcx, N> ImplSource<'tcx, N> {
697697
}
698698

699699
pub fn borrow_nested_obligations(&self) -> &[N] {
700-
match &self {
701-
ImplSource::UserDefined(i) => &i.nested[..],
702-
ImplSource::Param(n, _) => &n,
700+
match self {
701+
ImplSource::UserDefined(i) => &i.nested,
702+
ImplSource::Param(n, _) => n,
703703
ImplSource::Builtin(i) => &i.nested,
704704
ImplSource::AutoImpl(d) => &d.nested,
705705
ImplSource::Closure(c) => &c.nested,
@@ -713,6 +713,23 @@ impl<'tcx, N> ImplSource<'tcx, N> {
713713
}
714714
}
715715

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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
131131
}
132132
};
133133

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

0 commit comments

Comments
 (0)