Skip to content

Commit ef97776

Browse files
committed
Derive traversable impls for Obligation
Ever since folding was first added in c5754f3, obligations have not folded or visited their causes the ObligationCauseCode potentially containing types that may be of interest to a folder or visitor. By using the derive macro to implement the visitable traits, we ensure that all contained types of interest are folded/visited.
1 parent 408ba98 commit ef97776

File tree

2 files changed

+2
-33
lines changed

2 files changed

+2
-33
lines changed

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use rustc_middle::traits::*;
3434
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
3535
/// satisfies the obligation, or else finding a bound that is in
3636
/// scope. The eventual result is usually a `Selection` (defined below).
37-
#[derive(Clone, PartialEq, Eq, Hash)]
37+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
3838
pub struct Obligation<'tcx, T> {
3939
/// The reason we have to prove this thing.
4040
pub cause: ObligationCause<'tcx>,

compiler/rustc_infer/src/traits/structural_impls.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use crate::traits;
22
use crate::traits::project::Normalized;
3-
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable};
4-
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor};
5-
use rustc_middle::ty::{self, TyCtxt};
3+
use rustc_middle::ty;
64

75
use std::fmt;
8-
use std::ops::ControlFlow;
96

107
// Structural impls for the structs in `traits`.
118

@@ -57,31 +54,3 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
5754
write!(f, "MismatchedProjectionTypes({:?})", self.err)
5855
}
5956
}
60-
61-
///////////////////////////////////////////////////////////////////////////
62-
// TypeFoldable implementations.
63-
64-
impl<'tcx, O: TypeFoldable<TyCtxt<'tcx>>> TypeFoldable<TyCtxt<'tcx>>
65-
for traits::Obligation<'tcx, O>
66-
{
67-
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
68-
self,
69-
folder: &mut F,
70-
) -> Result<Self, F::Error> {
71-
Ok(traits::Obligation {
72-
cause: self.cause,
73-
recursion_depth: self.recursion_depth,
74-
predicate: self.predicate.try_fold_with(folder)?,
75-
param_env: self.param_env.try_fold_with(folder)?,
76-
})
77-
}
78-
}
79-
80-
impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>>
81-
for traits::Obligation<'tcx, O>
82-
{
83-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
84-
self.predicate.visit_with(visitor)?;
85-
self.param_env.visit_with(visitor)
86-
}
87-
}

0 commit comments

Comments
 (0)