Skip to content

Commit 4991b7d

Browse files
committed
Auto merge of #768 - eggyal:remove-fold-result-type, r=jackh726
Remove unused Result assoc type from Fold trait r? `@jackh726`
2 parents ebdb87c + a9d086c commit 4991b7d

23 files changed

+88
-164
lines changed

chalk-derive/src/lib.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -275,33 +275,21 @@ fn derive_type_foldable(mut s: synstructure::Structure) -> TokenStream {
275275
});
276276

277277
let input = s.ast();
278-
let type_name = &input.ident;
279278

280-
let result = if kind == DeriveKind::FromHasInterner {
279+
if kind == DeriveKind::FromHasInterner {
281280
let param = get_generic_param_name(input).unwrap();
282-
s.add_impl_generic(parse_quote! { _U })
283-
.add_where_predicate(
284-
parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner, Result = _U> },
285-
)
286-
.add_where_predicate(
287-
parse_quote! { _U: ::chalk_ir::interner::HasInterner<Interner = #interner> },
288-
);
289-
quote! { #type_name <_U> }
290-
} else {
291-
quote! { #type_name < #interner > }
281+
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::fold::TypeFoldable<#interner> });
292282
};
293283

294284
s.add_bounds(synstructure::AddBounds::None);
295285
s.bound_impl(
296286
quote!(::chalk_ir::fold::TypeFoldable<#interner>),
297287
quote! {
298-
type Result = #result;
299-
300288
fn fold_with<E>(
301289
self,
302290
folder: &mut dyn ::chalk_ir::fold::TypeFolder < #interner, Error = E >,
303291
outer_binder: ::chalk_ir::DebruijnIndex,
304-
) -> ::std::result::Result<Self::Result, E> {
292+
) -> ::std::result::Result<Self, E> {
305293
Ok(match self { #body })
306294
}
307295
},

chalk-engine/src/normalize_deep.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<I: Interner> DeepNormalizer<'_, I> {
2525
table: &mut InferenceTable<I>,
2626
interner: I,
2727
value: T,
28-
) -> T::Result {
28+
) -> T {
2929
value
3030
.fold_with(
3131
&mut DeepNormalizer { interner, table },

chalk-engine/src/slg/resolvent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ impl<'i, I: Interner> Zipper<I> for AnswerSubstitutor<'i, I> {
708708
pending: &Binders<T>,
709709
) -> Fallible<()>
710710
where
711-
T: HasInterner<Interner = I> + Zip<I> + TypeFoldable<I, Result = T>,
711+
T: HasInterner<Interner = I> + Zip<I> + TypeFoldable<I>,
712712
{
713713
self.outer_binder.shift_in();
714714
Zip::zip_with(

chalk-engine/src/strand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ pub(crate) struct SelectedSubgoal {
3636
}
3737

3838
impl<I: Interner> TypeFoldable<I> for Strand<I> {
39-
type Result = Strand<I>;
4039
fn fold_with<E>(
4140
self,
4241
folder: &mut dyn TypeFolder<I, Error = E>,
4342
outer_binder: DebruijnIndex,
44-
) -> Result<Self::Result, E> {
43+
) -> Result<Self, E> {
4544
Ok(Strand {
4645
ex_clause: self.ex_clause.fold_with(folder, outer_binder)?,
4746
last_pursued_time: self.last_pursued_time,

chalk-ir/src/fold.rs

+9-26
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,7 @@ pub trait TypeFolder<I: Interner> {
310310
/// the source type, but in some cases we convert from borrowed
311311
/// to owned as well (e.g., the folder for `&T` will fold to a fresh
312312
/// `T`; well, actually `T::Result`).
313-
pub trait TypeFoldable<I: Interner>: Debug {
314-
/// The type of value that will be produced once folding is done.
315-
/// Typically this is `Self`, unless `Self` contains borrowed
316-
/// values, in which case owned values are produced (for example,
317-
/// one can fold over a `&T` value where `T: TypeFoldable`, in which case
318-
/// you get back a `T`, not a `&T`).
319-
type Result;
320-
313+
pub trait TypeFoldable<I: Interner>: Debug + Sized {
321314
/// Apply the given folder `folder` to `self`; `binders` is the
322315
/// number of binders that are in scope when beginning the
323316
/// folder. Typically `binders` starts as 0, but is adjusted when
@@ -327,7 +320,7 @@ pub trait TypeFoldable<I: Interner>: Debug {
327320
self,
328321
folder: &mut dyn TypeFolder<I, Error = E>,
329322
outer_binder: DebruijnIndex,
330-
) -> Result<Self::Result, E>;
323+
) -> Result<Self, E>;
331324
}
332325

333326
/// For types where "fold" invokes a callback on the `TypeFolder`, the
@@ -339,20 +332,18 @@ pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
339332
self,
340333
folder: &mut dyn TypeFolder<I, Error = E>,
341334
outer_binder: DebruijnIndex,
342-
) -> Result<Self::Result, E>;
335+
) -> Result<Self, E>;
343336
}
344337

345338
/// "Folding" a type invokes the `fold_ty` method on the folder; this
346339
/// usually (in turn) invokes `super_fold_ty` to fold the individual
347340
/// parts.
348341
impl<I: Interner> TypeFoldable<I> for Ty<I> {
349-
type Result = Ty<I>;
350-
351342
fn fold_with<E>(
352343
self,
353344
folder: &mut dyn TypeFolder<I, Error = E>,
354345
outer_binder: DebruijnIndex,
355-
) -> Result<Self::Result, E> {
346+
) -> Result<Self, E> {
356347
folder.fold_ty(self, outer_binder)
357348
}
358349
}
@@ -470,13 +461,11 @@ where
470461
/// usually (in turn) invokes `super_fold_lifetime` to fold the individual
471462
/// parts.
472463
impl<I: Interner> TypeFoldable<I> for Lifetime<I> {
473-
type Result = Lifetime<I>;
474-
475464
fn fold_with<E>(
476465
self,
477466
folder: &mut dyn TypeFolder<I, Error = E>,
478467
outer_binder: DebruijnIndex,
479-
) -> Result<Self::Result, E> {
468+
) -> Result<Self, E> {
480469
folder.fold_lifetime(self, outer_binder)
481470
}
482471
}
@@ -522,13 +511,11 @@ where
522511
/// usually (in turn) invokes `super_fold_const` to fold the individual
523512
/// parts.
524513
impl<I: Interner> TypeFoldable<I> for Const<I> {
525-
type Result = Const<I>;
526-
527514
fn fold_with<E>(
528515
self,
529516
folder: &mut dyn TypeFolder<I, Error = E>,
530517
outer_binder: DebruijnIndex,
531-
) -> Result<Self::Result, E> {
518+
) -> Result<Self, E> {
532519
folder.fold_const(self, outer_binder)
533520
}
534521
}
@@ -573,13 +560,11 @@ where
573560
/// Folding a goal invokes the `fold_goal` callback (which will, by
574561
/// default, invoke super-fold).
575562
impl<I: Interner> TypeFoldable<I> for Goal<I> {
576-
type Result = Goal<I>;
577-
578563
fn fold_with<E>(
579564
self,
580565
folder: &mut dyn TypeFolder<I, Error = E>,
581566
outer_binder: DebruijnIndex,
582-
) -> Result<Self::Result, E> {
567+
) -> Result<Self, E> {
583568
folder.fold_goal(self, outer_binder)
584569
}
585570
}
@@ -590,7 +575,7 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
590575
self,
591576
folder: &mut dyn TypeFolder<I, Error = E>,
592577
outer_binder: DebruijnIndex,
593-
) -> Result<Self::Result, E> {
578+
) -> Result<Self, E> {
594579
let interner = folder.interner();
595580
Ok(Goal::new(
596581
interner,
@@ -605,13 +590,11 @@ impl<I: Interner> TypeSuperFoldable<I> for Goal<I> {
605590
/// callback on the folder (which will, by default, invoke the
606591
/// `super_fold_with` method on the program clause).
607592
impl<I: Interner> TypeFoldable<I> for ProgramClause<I> {
608-
type Result = ProgramClause<I>;
609-
610593
fn fold_with<E>(
611594
self,
612595
folder: &mut dyn TypeFolder<I, Error = E>,
613596
outer_binder: DebruijnIndex,
614-
) -> Result<Self::Result, E> {
597+
) -> Result<Self, E> {
615598
folder.fold_program_clause(self, outer_binder)
616599
}
617600
}

chalk-ir/src/fold/binder_impls.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
use crate::*;
77

88
impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
9-
type Result = FnPointer<I>;
109
fn fold_with<E>(
1110
self,
1211
folder: &mut dyn TypeFolder<I, Error = E>,
1312
outer_binder: DebruijnIndex,
14-
) -> Result<Self::Result, E> {
13+
) -> Result<Self, E> {
1514
let FnPointer {
1615
num_binders,
1716
substitution,
@@ -32,15 +31,13 @@ impl<I: Interner> TypeFoldable<I> for FnPointer<I> {
3231
impl<T, I: Interner> TypeFoldable<I> for Binders<T>
3332
where
3433
T: HasInterner<Interner = I> + TypeFoldable<I>,
35-
<T as TypeFoldable<I>>::Result: HasInterner<Interner = I>,
3634
I: Interner,
3735
{
38-
type Result = Binders<T::Result>;
3936
fn fold_with<E>(
4037
self,
4138
folder: &mut dyn TypeFolder<I, Error = E>,
4239
outer_binder: DebruijnIndex,
43-
) -> Result<Self::Result, E> {
40+
) -> Result<Self, E> {
4441
let Binders {
4542
binders: self_binders,
4643
value: self_value,
@@ -57,14 +54,12 @@ impl<I, T> TypeFoldable<I> for Canonical<T>
5754
where
5855
I: Interner,
5956
T: HasInterner<Interner = I> + TypeFoldable<I>,
60-
<T as TypeFoldable<I>>::Result: HasInterner<Interner = I>,
6157
{
62-
type Result = Canonical<T::Result>;
6358
fn fold_with<E>(
6459
self,
6560
folder: &mut dyn TypeFolder<I, Error = E>,
6661
outer_binder: DebruijnIndex,
67-
) -> Result<Self::Result, E> {
62+
) -> Result<Self, E> {
6863
let Canonical {
6964
binders: self_binders,
7065
value: self_value,

0 commit comments

Comments
 (0)