Skip to content

Commit a96fc9b

Browse files
Rollup merge of #151476 - nnethercote:no-unit-ret-ty-in-derive, r=Kobzol
Avoid `-> ()` in derived functions. `hash` and `assert_receiver_is_total_eq` have no return type. This commit removes the `-> ()` that is currently printed for them. r? @Kobzol
2 parents 7912aa8 + ced38b5 commit a96fc9b

3 files changed

Lines changed: 40 additions & 46 deletions

File tree

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -986,16 +986,6 @@ impl<'a> MethodDef<'a> {
986986
f(cx, span, &substructure)
987987
}
988988

989-
fn get_ret_ty(
990-
&self,
991-
cx: &ExtCtxt<'_>,
992-
trait_: &TraitDef<'_>,
993-
generics: &Generics,
994-
type_ident: Ident,
995-
) -> Box<ast::Ty> {
996-
self.ret_ty.to_ty(cx, trait_.span, type_ident, generics)
997-
}
998-
999989
fn is_static(&self) -> bool {
1000990
!self.explicit_self
1001991
}
@@ -1068,10 +1058,14 @@ impl<'a> MethodDef<'a> {
10681058
self_arg.into_iter().chain(nonself_args).collect()
10691059
};
10701060

1071-
let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident);
1061+
let ret_type = if let Ty::Unit = &self.ret_ty {
1062+
ast::FnRetTy::Default(span)
1063+
} else {
1064+
ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics))
1065+
};
10721066

10731067
let method_ident = Ident::new(self.name, span);
1074-
let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type));
1068+
let fn_decl = cx.fn_decl(args, ret_type);
10751069
let body_block = body.into_block(cx, span);
10761070

10771071
let trait_lo_sp = span.shrink_to_lo();

tests/ui/deriving/deriving-all-codegen.stdout

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl ::core::default::Default for Empty {
5151
#[automatically_derived]
5252
impl ::core::hash::Hash for Empty {
5353
#[inline]
54-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
54+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
5555
}
5656
#[automatically_derived]
5757
impl ::core::marker::StructuralPartialEq for Empty { }
@@ -65,7 +65,7 @@ impl ::core::cmp::Eq for Empty {
6565
#[inline]
6666
#[doc(hidden)]
6767
#[coverage(off)]
68-
fn assert_receiver_is_total_eq(&self) -> () {}
68+
fn assert_receiver_is_total_eq(&self) {}
6969
}
7070
#[automatically_derived]
7171
impl ::core::cmp::PartialOrd for Empty {
@@ -123,7 +123,7 @@ impl ::core::default::Default for Point {
123123
#[automatically_derived]
124124
impl ::core::hash::Hash for Point {
125125
#[inline]
126-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
126+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
127127
::core::hash::Hash::hash(&self.x, state);
128128
::core::hash::Hash::hash(&self.y, state)
129129
}
@@ -142,7 +142,7 @@ impl ::core::cmp::Eq for Point {
142142
#[inline]
143143
#[doc(hidden)]
144144
#[coverage(off)]
145-
fn assert_receiver_is_total_eq(&self) -> () {
145+
fn assert_receiver_is_total_eq(&self) {
146146
let _: ::core::cmp::AssertParamIsEq<u32>;
147147
}
148148
}
@@ -211,7 +211,7 @@ impl ::core::default::Default for PackedPoint {
211211
#[automatically_derived]
212212
impl ::core::hash::Hash for PackedPoint {
213213
#[inline]
214-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
214+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
215215
::core::hash::Hash::hash(&{ self.x }, state);
216216
::core::hash::Hash::hash(&{ self.y }, state)
217217
}
@@ -230,7 +230,7 @@ impl ::core::cmp::Eq for PackedPoint {
230230
#[inline]
231231
#[doc(hidden)]
232232
#[coverage(off)]
233-
fn assert_receiver_is_total_eq(&self) -> () {
233+
fn assert_receiver_is_total_eq(&self) {
234234
let _: ::core::cmp::AssertParamIsEq<u32>;
235235
}
236236
}
@@ -297,7 +297,7 @@ impl ::core::convert::From<u32> for TupleSingleField {
297297
#[automatically_derived]
298298
impl ::core::hash::Hash for TupleSingleField {
299299
#[inline]
300-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
300+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
301301
::core::hash::Hash::hash(&self.0, state)
302302
}
303303
}
@@ -313,7 +313,7 @@ impl ::core::cmp::Eq for TupleSingleField {
313313
#[inline]
314314
#[doc(hidden)]
315315
#[coverage(off)]
316-
fn assert_receiver_is_total_eq(&self) -> () {
316+
fn assert_receiver_is_total_eq(&self) {
317317
let _: ::core::cmp::AssertParamIsEq<u32>;
318318
}
319319
}
@@ -372,7 +372,7 @@ impl ::core::convert::From<bool> for SingleField {
372372
#[automatically_derived]
373373
impl ::core::hash::Hash for SingleField {
374374
#[inline]
375-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
375+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
376376
::core::hash::Hash::hash(&self.foo, state)
377377
}
378378
}
@@ -388,7 +388,7 @@ impl ::core::cmp::Eq for SingleField {
388388
#[inline]
389389
#[doc(hidden)]
390390
#[coverage(off)]
391-
fn assert_receiver_is_total_eq(&self) -> () {
391+
fn assert_receiver_is_total_eq(&self) {
392392
let _: ::core::cmp::AssertParamIsEq<bool>;
393393
}
394394
}
@@ -465,7 +465,7 @@ impl ::core::default::Default for Big {
465465
#[automatically_derived]
466466
impl ::core::hash::Hash for Big {
467467
#[inline]
468-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
468+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
469469
::core::hash::Hash::hash(&self.b1, state);
470470
::core::hash::Hash::hash(&self.b2, state);
471471
::core::hash::Hash::hash(&self.b3, state);
@@ -493,7 +493,7 @@ impl ::core::cmp::Eq for Big {
493493
#[inline]
494494
#[doc(hidden)]
495495
#[coverage(off)]
496-
fn assert_receiver_is_total_eq(&self) -> () {
496+
fn assert_receiver_is_total_eq(&self) {
497497
let _: ::core::cmp::AssertParamIsEq<u32>;
498498
}
499499
}
@@ -741,7 +741,7 @@ impl ::core::convert::From<[u32]> for Unsized {
741741
#[automatically_derived]
742742
impl ::core::hash::Hash for Unsized {
743743
#[inline]
744-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
744+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
745745
::core::hash::Hash::hash(&self.0, state)
746746
}
747747
}
@@ -757,7 +757,7 @@ impl ::core::cmp::Eq for Unsized {
757757
#[inline]
758758
#[doc(hidden)]
759759
#[coverage(off)]
760-
fn assert_receiver_is_total_eq(&self) -> () {
760+
fn assert_receiver_is_total_eq(&self) {
761761
let _: ::core::cmp::AssertParamIsEq<[u32]>;
762762
}
763763
}
@@ -829,7 +829,7 @@ impl<T: ::core::default::Default + Trait, U: ::core::default::Default>
829829
impl<T: ::core::hash::Hash + Trait, U: ::core::hash::Hash> ::core::hash::Hash
830830
for Generic<T, U> where T::A: ::core::hash::Hash {
831831
#[inline]
832-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
832+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
833833
::core::hash::Hash::hash(&self.t, state);
834834
::core::hash::Hash::hash(&self.ta, state);
835835
::core::hash::Hash::hash(&self.u, state)
@@ -852,7 +852,7 @@ impl<T: ::core::cmp::Eq + Trait, U: ::core::cmp::Eq> ::core::cmp::Eq for
852852
#[inline]
853853
#[doc(hidden)]
854854
#[coverage(off)]
855-
fn assert_receiver_is_total_eq(&self) -> () {
855+
fn assert_receiver_is_total_eq(&self) {
856856
let _: ::core::cmp::AssertParamIsEq<T>;
857857
let _: ::core::cmp::AssertParamIsEq<T::A>;
858858
let _: ::core::cmp::AssertParamIsEq<U>;
@@ -946,7 +946,7 @@ impl<T: ::core::hash::Hash + ::core::marker::Copy + Trait,
946946
PackedGeneric<T, U> where T::A: ::core::hash::Hash + ::core::marker::Copy
947947
{
948948
#[inline]
949-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
949+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
950950
::core::hash::Hash::hash(&{ self.0 }, state);
951951
::core::hash::Hash::hash(&{ self.1 }, state);
952952
::core::hash::Hash::hash(&{ self.2 }, state)
@@ -974,7 +974,7 @@ impl<T: ::core::cmp::Eq + ::core::marker::Copy + Trait, U: ::core::cmp::Eq +
974974
#[inline]
975975
#[doc(hidden)]
976976
#[coverage(off)]
977-
fn assert_receiver_is_total_eq(&self) -> () {
977+
fn assert_receiver_is_total_eq(&self) {
978978
let _: ::core::cmp::AssertParamIsEq<T>;
979979
let _: ::core::cmp::AssertParamIsEq<T::A>;
980980
let _: ::core::cmp::AssertParamIsEq<U>;
@@ -1043,7 +1043,7 @@ impl ::core::fmt::Debug for Enum0 {
10431043
#[automatically_derived]
10441044
impl ::core::hash::Hash for Enum0 {
10451045
#[inline]
1046-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1046+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
10471047
match *self {}
10481048
}
10491049
}
@@ -1059,7 +1059,7 @@ impl ::core::cmp::Eq for Enum0 {
10591059
#[inline]
10601060
#[doc(hidden)]
10611061
#[coverage(off)]
1062-
fn assert_receiver_is_total_eq(&self) -> () {}
1062+
fn assert_receiver_is_total_eq(&self) {}
10631063
}
10641064
#[automatically_derived]
10651065
impl ::core::cmp::PartialOrd for Enum0 {
@@ -1105,7 +1105,7 @@ impl ::core::fmt::Debug for Enum1 {
11051105
#[automatically_derived]
11061106
impl ::core::hash::Hash for Enum1 {
11071107
#[inline]
1108-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1108+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
11091109
match self {
11101110
Enum1::Single { x: __self_0 } =>
11111111
::core::hash::Hash::hash(__self_0, state),
@@ -1129,7 +1129,7 @@ impl ::core::cmp::Eq for Enum1 {
11291129
#[inline]
11301130
#[doc(hidden)]
11311131
#[coverage(off)]
1132-
fn assert_receiver_is_total_eq(&self) -> () {
1132+
fn assert_receiver_is_total_eq(&self) {
11331133
let _: ::core::cmp::AssertParamIsEq<u32>;
11341134
}
11351135
}
@@ -1181,7 +1181,7 @@ impl ::core::default::Default for Fieldless1 {
11811181
#[automatically_derived]
11821182
impl ::core::hash::Hash for Fieldless1 {
11831183
#[inline]
1184-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
1184+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {}
11851185
}
11861186
#[automatically_derived]
11871187
impl ::core::marker::StructuralPartialEq for Fieldless1 { }
@@ -1195,7 +1195,7 @@ impl ::core::cmp::Eq for Fieldless1 {
11951195
#[inline]
11961196
#[doc(hidden)]
11971197
#[coverage(off)]
1198-
fn assert_receiver_is_total_eq(&self) -> () {}
1198+
fn assert_receiver_is_total_eq(&self) {}
11991199
}
12001200
#[automatically_derived]
12011201
impl ::core::cmp::PartialOrd for Fieldless1 {
@@ -1251,7 +1251,7 @@ impl ::core::default::Default for Fieldless {
12511251
#[automatically_derived]
12521252
impl ::core::hash::Hash for Fieldless {
12531253
#[inline]
1254-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1254+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
12551255
let __self_discr = ::core::intrinsics::discriminant_value(self);
12561256
::core::hash::Hash::hash(&__self_discr, state)
12571257
}
@@ -1272,7 +1272,7 @@ impl ::core::cmp::Eq for Fieldless {
12721272
#[inline]
12731273
#[doc(hidden)]
12741274
#[coverage(off)]
1275-
fn assert_receiver_is_total_eq(&self) -> () {}
1275+
fn assert_receiver_is_total_eq(&self) {}
12761276
}
12771277
#[automatically_derived]
12781278
impl ::core::cmp::PartialOrd for Fieldless {
@@ -1345,7 +1345,7 @@ impl ::core::default::Default for Mixed {
13451345
#[automatically_derived]
13461346
impl ::core::hash::Hash for Mixed {
13471347
#[inline]
1348-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1348+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
13491349
let __self_discr = ::core::intrinsics::discriminant_value(self);
13501350
::core::hash::Hash::hash(&__self_discr, state);
13511351
match self {
@@ -1382,7 +1382,7 @@ impl ::core::cmp::Eq for Mixed {
13821382
#[inline]
13831383
#[doc(hidden)]
13841384
#[coverage(off)]
1385-
fn assert_receiver_is_total_eq(&self) -> () {
1385+
fn assert_receiver_is_total_eq(&self) {
13861386
let _: ::core::cmp::AssertParamIsEq<u32>;
13871387
let _: ::core::cmp::AssertParamIsEq<Option<u32>>;
13881388
let _: ::core::cmp::AssertParamIsEq<Option<i32>>;
@@ -1545,7 +1545,7 @@ impl ::core::fmt::Debug for Fielded {
15451545
#[automatically_derived]
15461546
impl ::core::hash::Hash for Fielded {
15471547
#[inline]
1548-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1548+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
15491549
let __self_discr = ::core::intrinsics::discriminant_value(self);
15501550
::core::hash::Hash::hash(&__self_discr, state);
15511551
match self {
@@ -1580,7 +1580,7 @@ impl ::core::cmp::Eq for Fielded {
15801580
#[inline]
15811581
#[doc(hidden)]
15821582
#[coverage(off)]
1583-
fn assert_receiver_is_total_eq(&self) -> () {
1583+
fn assert_receiver_is_total_eq(&self) {
15841584
let _: ::core::cmp::AssertParamIsEq<u32>;
15851585
let _: ::core::cmp::AssertParamIsEq<bool>;
15861586
let _: ::core::cmp::AssertParamIsEq<Option<i32>>;
@@ -1666,7 +1666,7 @@ impl<T: ::core::fmt::Debug, U: ::core::fmt::Debug> ::core::fmt::Debug for
16661666
impl<T: ::core::hash::Hash, U: ::core::hash::Hash> ::core::hash::Hash for
16671667
EnumGeneric<T, U> {
16681668
#[inline]
1669-
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
1669+
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
16701670
let __self_discr = ::core::intrinsics::discriminant_value(self);
16711671
::core::hash::Hash::hash(&__self_discr, state);
16721672
match self {
@@ -1702,7 +1702,7 @@ impl<T: ::core::cmp::Eq, U: ::core::cmp::Eq> ::core::cmp::Eq for
17021702
#[inline]
17031703
#[doc(hidden)]
17041704
#[coverage(off)]
1705-
fn assert_receiver_is_total_eq(&self) -> () {
1705+
fn assert_receiver_is_total_eq(&self) {
17061706
let _: ::core::cmp::AssertParamIsEq<T>;
17071707
let _: ::core::cmp::AssertParamIsEq<U>;
17081708
}

tests/ui/stats/macro-stats.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ macro-stats Macro Name Uses Lines Avg Lines B
44
macro-stats -----------------------------------------------------------------------------------
55
macro-stats #[derive(Clone)] 8 67 8.4 1_879 234.9
66
macro-stats #[derive(PartialOrd)] 1 17 17.0 675 675.0
7-
macro-stats #[derive(Hash)] 2 17 8.5 577 288.5
7+
macro-stats #[derive(Hash)] 2 17 8.5 565 282.5
88
macro-stats q! 1 26 26.0 519 519.0
99
macro-stats #[derive(Ord)] 1 15 15.0 503 503.0
1010
macro-stats #[derive(Default)] 2 16 8.0 403 201.5
11-
macro-stats #[derive(Eq)] 1 11 11.0 325 325.0
11+
macro-stats #[derive(Eq)] 1 11 11.0 319 319.0
1212
macro-stats #[derive(Debug)] 1 8 8.0 277 277.0
1313
macro-stats #[derive(PartialEq)] 1 9 9.0 267 267.0
1414
macro-stats #[derive(Copy)] 1 2 2.0 61 61.0

0 commit comments

Comments
 (0)