Skip to content

Commit 8b4785d

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 07108f9 commit 8b4785d

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ pub use rustc_middle::traits::*;
3636
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
3737
/// satisfies the obligation, or else finding a bound that is in
3838
/// scope. The eventual result is usually a `Selection` (defined below).
39-
#[derive(Clone)]
39+
#[derive(Clone, TypeFoldable, TypeVisitable)]
4040
pub struct Obligation<'tcx, T> {
4141
/// The reason we have to prove this thing.
42+
// FIXME: provide more detailed justification for `#[skip_traversal]`, or else remove
43+
// see https://github.com/rust-lang/rust/pull/108214#issuecomment-1479424793
44+
#[skip_traversal(despite_potential_miscompilation_because = "perf")]
4245
pub cause: ObligationCause<'tcx>,
4346

4447
/// The environment in which we should prove this thing.

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

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

0 commit comments

Comments
 (0)