Skip to content

Commit d0c9ba3

Browse files
committed
Derive traversable impls for GenericArgKind
1 parent ba7c7a3 commit d0c9ba3

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

compiler/rustc_middle/src/ty/generic_args.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const REGION_TAG: usize = 0b01;
4747
const CONST_TAG: usize = 0b10;
4848

4949
#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)]
50+
#[derive(Clone, TypeFoldable, TypeVisitable)]
5051
pub enum GenericArgKind<'tcx> {
5152
Lifetime(ty::Region<'tcx>),
5253
Type(Ty<'tcx>),
@@ -210,21 +211,13 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArg<'tcx> {
210211
self,
211212
folder: &mut F,
212213
) -> Result<Self, F::Error> {
213-
match self.unpack() {
214-
GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into),
215-
GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into),
216-
GenericArgKind::Const(ct) => ct.try_fold_with(folder).map(Into::into),
217-
}
214+
self.unpack().try_fold_with(folder).map(GenericArgKind::pack)
218215
}
219216
}
220217

221218
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for GenericArg<'tcx> {
222219
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
223-
match self.unpack() {
224-
GenericArgKind::Lifetime(lt) => lt.visit_with(visitor),
225-
GenericArgKind::Type(ty) => ty.visit_with(visitor),
226-
GenericArgKind::Const(ct) => ct.visit_with(visitor),
227-
}
220+
self.unpack().visit_with(visitor)
228221
}
229222
}
230223

0 commit comments

Comments
 (0)