Change Ty::Tuple to Ty::Unit.

Because that's all that is needed in practice.
This commit is contained in:
Nicholas Nethercote 2022-06-30 10:22:41 +10:00
parent 00307a5b6f
commit 85e8d94e05
4 changed files with 8 additions and 14 deletions

View File

@ -33,7 +33,7 @@ pub fn expand_deriving_eq(
generics: Bounds::empty(), generics: Bounds::empty(),
explicit_self: true, explicit_self: true,
args: vec![], args: vec![],
ret_ty: nil_ty(), ret_ty: Unit,
attributes: attrs, attributes: attrs,
unify_fieldless_variants: true, unify_fieldless_variants: true,
combine_substructure: combine_substructure(Box::new(|a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {

View File

@ -125,7 +125,7 @@ pub fn expand_deriving_rustc_encodable(
ret_ty: Path(Path::new_( ret_ty: Path(Path::new_(
pathvec_std!(result::Result), pathvec_std!(result::Result),
vec![ vec![
Box::new(Tuple(Vec::new())), Box::new(Unit),
Box::new(Path(Path::new_(vec![typaram, sym::Error], vec![], PathKind::Local))), Box::new(Path(Path::new_(vec![typaram, sym::Error], vec![], PathKind::Local))),
], ],
PathKind::Std, PathKind::Std,

View File

@ -78,18 +78,14 @@ pub enum Ty {
/// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type /// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type
/// parameter, and things like `i32` /// parameter, and things like `i32`
Path(Path), Path(Path),
/// includes unit /// For () return types.
Tuple(Vec<Ty>), Unit,
} }
pub fn self_ref() -> Ty { pub fn self_ref() -> Ty {
Ref(Box::new(Self_), ast::Mutability::Not) Ref(Box::new(Self_), ast::Mutability::Not)
} }
pub fn nil_ty() -> Ty {
Tuple(Vec::new())
}
impl Ty { impl Ty {
pub fn to_ty( pub fn to_ty(
&self, &self,
@ -105,10 +101,8 @@ impl Ty {
} }
Path(p) => p.to_ty(cx, span, self_ty, self_generics), Path(p) => p.to_ty(cx, span, self_ty, self_generics),
Self_ => cx.ty_path(self.to_path(cx, span, self_ty, self_generics)), Self_ => cx.ty_path(self.to_path(cx, span, self_ty, self_generics)),
Tuple(fields) => { Unit => {
let ty = ast::TyKind::Tup( let ty = ast::TyKind::Tup(vec![]);
fields.iter().map(|f| f.to_ty(cx, span, self_ty, self_generics)).collect(),
);
cx.ty(span, ty) cx.ty(span, ty)
} }
} }
@ -143,7 +137,7 @@ impl Ty {
} }
Path(ref p) => p.to_path(cx, span, self_ty, generics), Path(ref p) => p.to_path(cx, span, self_ty, generics),
Ref(..) => cx.span_bug(span, "ref in a path in generic `derive`"), Ref(..) => cx.span_bug(span, "ref in a path in generic `derive`"),
Tuple(..) => cx.span_bug(span, "tuple in a path in generic `derive`"), Unit => cx.span_bug(span, "unit in a path in generic `derive`"),
} }
} }
} }

View File

@ -32,7 +32,7 @@ pub fn expand_deriving_hash(
generics: Bounds { bounds: vec![(typaram, vec![path_std!(hash::Hasher)])] }, generics: Bounds { bounds: vec![(typaram, vec![path_std!(hash::Hasher)])] },
explicit_self: true, explicit_self: true,
args: vec![(Ref(Box::new(Path(arg)), Mutability::Mut), sym::state)], args: vec![(Ref(Box::new(Path(arg)), Mutability::Mut), sym::state)],
ret_ty: nil_ty(), ret_ty: Unit,
attributes: vec![], attributes: vec![],
unify_fieldless_variants: true, unify_fieldless_variants: true,
combine_substructure: combine_substructure(Box::new(|a, b, c| { combine_substructure: combine_substructure(Box::new(|a, b, c| {