Skip to content

Commit 13b4734

Browse files
Derive Obligation's fold impls
1 parent c580c49 commit 13b4734

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

compiler/rustc_infer/src/traits/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::hash::{Hash, Hasher};
1212

1313
use hir::def_id::LocalDefId;
1414
use rustc_hir as hir;
15+
use rustc_macros::{TypeFoldable, TypeVisitable};
1516
use rustc_middle::traits::query::NoSolution;
1617
use rustc_middle::traits::solve::Certainty;
1718
pub use rustc_middle::traits::*;
@@ -35,9 +36,11 @@ use crate::infer::InferCtxt;
3536
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
3637
/// satisfies the obligation, or else finding a bound that is in
3738
/// scope. The eventual result is usually a `Selection` (defined below).
38-
#[derive(Clone)]
39+
#[derive(Clone, TypeFoldable, TypeVisitable)]
3940
pub struct Obligation<'tcx, T> {
4041
/// The reason we have to prove this thing.
42+
#[type_foldable(identity)]
43+
#[type_visitable(ignore)]
4144
pub cause: ObligationCause<'tcx>,
4245

4346
/// The environment in which we should prove this thing.
@@ -51,6 +54,8 @@ pub struct Obligation<'tcx, T> {
5154
/// If this goes over a certain threshold, we abort compilation --
5255
/// in such cases, we can not say whether or not the predicate
5356
/// holds for certain. Stupid halting problem; such a drag.
57+
#[type_foldable(identity)]
58+
#[type_visitable(ignore)]
5459
pub recursion_depth: usize,
5560
}
5661

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::fmt;
22

3-
use rustc_middle::ty::{
4-
self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitor, try_visit,
5-
};
3+
use rustc_middle::ty;
64

75
use crate::traits;
86
use crate::traits::project::Normalized;
@@ -34,31 +32,3 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
3432
write!(f, "MismatchedProjectionTypes({:?})", self.err)
3533
}
3634
}
37-
38-
///////////////////////////////////////////////////////////////////////////
39-
// TypeFoldable implementations.
40-
41-
impl<'tcx, O: TypeFoldable<TyCtxt<'tcx>>> TypeFoldable<TyCtxt<'tcx>>
42-
for traits::Obligation<'tcx, O>
43-
{
44-
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
45-
self,
46-
folder: &mut F,
47-
) -> Result<Self, F::Error> {
48-
Ok(traits::Obligation {
49-
cause: self.cause,
50-
recursion_depth: self.recursion_depth,
51-
predicate: self.predicate.try_fold_with(folder)?,
52-
param_env: self.param_env.try_fold_with(folder)?,
53-
})
54-
}
55-
}
56-
57-
impl<'tcx, O: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>>
58-
for traits::Obligation<'tcx, O>
59-
{
60-
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
61-
try_visit!(self.predicate.visit_with(visitor));
62-
self.param_env.visit_with(visitor)
63-
}
64-
}

0 commit comments

Comments
 (0)