Skip to content

Commit 02f6d8e

Browse files
authored
Make discriminant function const (#82)
1 parent ddad3aa commit 02f6d8e

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

src/test/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn enum_() -> Result<()> {
197197
};
198198
#[cfg(not(feature = "nightly"))]
199199
let ord = quote! {
200-
fn __discriminant<T>(__this: &Test<T>) -> isize {
200+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
201201
match __this {
202202
Test::A { field: ref __field_field } => 0,
203203
Test::B { } => 1,

src/test/discriminant.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn default() -> Result<()> {
1414
};
1515
#[cfg(not(feature = "nightly"))]
1616
let partial_ord = quote! {
17-
fn __discriminant(__this: &Test) -> isize {
17+
const fn __discriminant(__this: &Test) -> isize {
1818
match __this {
1919
Test::A => 0,
2020
Test::B => (0) + 1,
@@ -152,7 +152,7 @@ fn default_reverse() -> Result<()> {
152152
};
153153
#[cfg(not(feature = "nightly"))]
154154
let partial_ord = quote! {
155-
fn __discriminant(__this: &Test) -> isize {
155+
const fn __discriminant(__this: &Test) -> isize {
156156
match __this {
157157
Test::A => 2,
158158
Test::B => 1,
@@ -199,7 +199,7 @@ fn default_mix() -> Result<()> {
199199
};
200200
#[cfg(not(feature = "nightly"))]
201201
let partial_ord = quote! {
202-
fn __discriminant(__this: &Test) -> isize {
202+
const fn __discriminant(__this: &Test) -> isize {
203203
match __this {
204204
Test::A => 1,
205205
Test::B => 0,
@@ -248,7 +248,7 @@ fn default_skip() -> Result<()> {
248248
};
249249
#[cfg(not(feature = "nightly"))]
250250
let partial_ord = quote! {
251-
fn __discriminant(__this: &Test) -> isize {
251+
const fn __discriminant(__this: &Test) -> isize {
252252
match __this {
253253
Test::A => 0,
254254
Test::B => 3,
@@ -299,7 +299,7 @@ fn default_expr() -> Result<()> {
299299
};
300300
#[cfg(not(feature = "nightly"))]
301301
let partial_ord = quote! {
302-
fn __discriminant(__this: &Test) -> isize {
302+
const fn __discriminant(__this: &Test) -> isize {
303303
match __this {
304304
Test::A => isize::MAX - 2,
305305
Test::B => (isize::MAX - 2) + 1,
@@ -349,7 +349,7 @@ fn repr_c() -> Result<()> {
349349
#[repr(C)]
350350
enum EnsureReprCIsIsize { Test = 0_isize }
351351

352-
fn __discriminant(__this: &Test) -> isize {
352+
const fn __discriminant(__this: &Test) -> isize {
353353
match __this {
354354
Test::A => 0,
355355
Test::B => (0) + 1,
@@ -397,7 +397,7 @@ fn repr_c_without_discriminant() -> Result<()> {
397397
};
398398
#[cfg(not(feature = "nightly"))]
399399
let partial_ord = quote! {
400-
fn __discriminant(__this: &Test) -> isize {
400+
const fn __discriminant(__this: &Test) -> isize {
401401
match __this {
402402
Test::A => 0,
403403
Test::B => 1,
@@ -640,7 +640,7 @@ fn repr_c_reverse() -> Result<()> {
640640
#[repr(C)]
641641
enum EnsureReprCIsIsize { Test = 0_isize }
642642

643-
fn __discriminant(__this: &Test) -> isize {
643+
const fn __discriminant(__this: &Test) -> isize {
644644
match __this {
645645
Test::A => 2,
646646
Test::B => 1,
@@ -691,7 +691,7 @@ fn repr_c_mix() -> Result<()> {
691691
#[repr(C)]
692692
enum EnsureReprCIsIsize { Test = 0_isize }
693693

694-
fn __discriminant(__this: &Test) -> isize {
694+
const fn __discriminant(__this: &Test) -> isize {
695695
match __this {
696696
Test::A => 1,
697697
Test::B => 0,
@@ -744,7 +744,7 @@ fn repr_c_skip() -> Result<()> {
744744
#[repr(C)]
745745
enum EnsureReprCIsIsize { Test = 0_isize }
746746

747-
fn __discriminant(__this: &Test) -> isize {
747+
const fn __discriminant(__this: &Test) -> isize {
748748
match __this {
749749
Test::A => 0,
750750
Test::B => 3,
@@ -799,7 +799,7 @@ fn repr_c_expr() -> Result<()> {
799799
#[repr(C)]
800800
enum EnsureReprCIsIsize { Test = 0_isize }
801801

802-
fn __discriminant(__this: &Test) -> isize {
802+
const fn __discriminant(__this: &Test) -> isize {
803803
match __this {
804804
Test::A => u64::MAX - 2,
805805
Test::B => (u64::MAX - 2) + 1,
@@ -861,7 +861,7 @@ fn repr_c_with_value() -> Result<()> {
861861
};
862862
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
863863
let partial_ord = quote! {
864-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
864+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
865865
match __this {
866866
Test::A(ref __field_0) => 0,
867867
Test::B => (0) + 1,
@@ -931,7 +931,7 @@ fn repr_c_with_value_reverse() -> Result<()> {
931931
};
932932
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
933933
let partial_ord = quote! {
934-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
934+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
935935
match __this {
936936
Test::A(ref __field_0) => 2,
937937
Test::B => 1,
@@ -1001,7 +1001,7 @@ fn repr_c_with_value_mix() -> Result<()> {
10011001
};
10021002
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
10031003
let partial_ord = quote! {
1004-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1004+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
10051005
match __this {
10061006
Test::A(ref __field_0) => 1,
10071007
Test::B => 0,
@@ -1071,7 +1071,7 @@ fn repr_c_with_value_skip() -> Result<()> {
10711071
};
10721072
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
10731073
let partial_ord = quote! {
1074-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1074+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
10751075
match __this {
10761076
Test::A(ref __field_0) => 0,
10771077
Test::B => 3,
@@ -1143,7 +1143,7 @@ fn repr_c_with_value_expr() -> Result<()> {
11431143
};
11441144
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
11451145
let partial_ord = quote! {
1146-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1146+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
11471147
match __this {
11481148
Test::A(ref __field_0) => isize::MAX - 2,
11491149
Test::B => (isize::MAX - 2) + 1,
@@ -1206,7 +1206,7 @@ fn repr() -> Result<()> {
12061206
};
12071207
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
12081208
let partial_ord = quote! {
1209-
fn __discriminant(__this: &Test) -> u64 {
1209+
const fn __discriminant(__this: &Test) -> u64 {
12101210
match __this {
12111211
Test::A => 0,
12121212
Test::B => (0) + 1,
@@ -1354,7 +1354,7 @@ fn repr_reverse() -> Result<()> {
13541354
};
13551355
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
13561356
let partial_ord = quote! {
1357-
fn __discriminant(__this: &Test) -> u64 {
1357+
const fn __discriminant(__this: &Test) -> u64 {
13581358
match __this {
13591359
Test::A => 2,
13601360
Test::B => 1,
@@ -1409,7 +1409,7 @@ fn repr_mix() -> Result<()> {
14091409
};
14101410
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
14111411
let partial_ord = quote! {
1412-
fn __discriminant(__this: &Test) -> u64 {
1412+
const fn __discriminant(__this: &Test) -> u64 {
14131413
match __this {
14141414
Test::A => 1,
14151415
Test::B => 0,
@@ -1466,7 +1466,7 @@ fn repr_skip() -> Result<()> {
14661466
};
14671467
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
14681468
let partial_ord = quote! {
1469-
fn __discriminant(__this: &Test) -> u64 {
1469+
const fn __discriminant(__this: &Test) -> u64 {
14701470
match __this {
14711471
Test::A => 0,
14721472
Test::B => 3,
@@ -1525,7 +1525,7 @@ fn repr_expr() -> Result<()> {
15251525
};
15261526
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
15271527
let partial_ord = quote! {
1528-
fn __discriminant(__this: &Test) -> u64 {
1528+
const fn __discriminant(__this: &Test) -> u64 {
15291529
match __this {
15301530
Test::A => u64::MAX - 2,
15311531
Test::B => (u64::MAX - 2) + 1,
@@ -1587,7 +1587,7 @@ fn repr_with_value() -> Result<()> {
15871587
};
15881588
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
15891589
let partial_ord = quote! {
1590-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1590+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
15911591
match __this {
15921592
Test::A(ref __field_0) => 0,
15931593
Test::B => (0) + 1,
@@ -1657,7 +1657,7 @@ fn repr_with_value_reverse() -> Result<()> {
16571657
};
16581658
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
16591659
let partial_ord = quote! {
1660-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1660+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
16611661
match __this {
16621662
Test::A(ref __field_0) => 2,
16631663
Test::B => 1,
@@ -1727,7 +1727,7 @@ fn repr_with_value_mix() -> Result<()> {
17271727
};
17281728
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
17291729
let partial_ord = quote! {
1730-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1730+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
17311731
match __this {
17321732
Test::A(ref __field_0) => 1,
17331733
Test::B => 0,
@@ -1797,7 +1797,7 @@ fn repr_with_value_skip() -> Result<()> {
17971797
};
17981798
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
17991799
let partial_ord = quote! {
1800-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1800+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
18011801
match __this {
18021802
Test::A(ref __field_0) => 0,
18031803
Test::B => 3,
@@ -1869,7 +1869,7 @@ fn repr_with_value_expr() -> Result<()> {
18691869
};
18701870
#[cfg(all(not(feature = "nightly"), feature = "safe"))]
18711871
let partial_ord = quote! {
1872-
fn __discriminant<T>(__this: &Test<T>) -> u8 {
1872+
const fn __discriminant<T>(__this: &Test<T>) -> u8 {
18731873
match __this {
18741874
Test::A(ref __field_0) => isize::MAX - 2,
18751875
Test::B => (isize::MAX - 2) + 1,

src/test/enum_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn two_data() -> Result<()> {
128128
};
129129
#[cfg(not(feature = "nightly"))]
130130
let partial_ord = quote! {
131-
fn __discriminant<T>(__this: &Test<T>) -> isize {
131+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
132132
match __this {
133133
Test::A(ref __field_0) => 0,
134134
Test::B(ref __field_0) => 1
@@ -210,7 +210,7 @@ fn unit() -> Result<()> {
210210
};
211211
#[cfg(not(feature = "nightly"))]
212212
let partial_ord = quote! {
213-
fn __discriminant<T>(__this: &Test<T>) -> isize {
213+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
214214
match __this {
215215
Test::A(ref __field_0) => 0,
216216
Test::B => 1
@@ -285,7 +285,7 @@ fn struct_unit() -> Result<()> {
285285
};
286286
#[cfg(not(feature = "nightly"))]
287287
let partial_ord = quote! {
288-
fn __discriminant<T>(__this: &Test<T>) -> isize {
288+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
289289
match __this {
290290
Test::A(ref __field_0) => 0,
291291
Test::B { } => 1
@@ -360,7 +360,7 @@ fn tuple_unit() -> Result<()> {
360360
};
361361
#[cfg(not(feature = "nightly"))]
362362
let partial_ord = quote! {
363-
fn __discriminant<T>(__this: &Test<T>) -> isize {
363+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
364364
match __this {
365365
Test::A(ref __field_0) => 0,
366366
Test::B() => 1

src/test/incomparable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn variants() -> Result<()> {
5555
_ => ::core::option::Option::Some(::core::cmp::Ordering::Equal),
5656
}
5757
} else {
58-
fn __discriminant(__this: &Test) -> isize {
58+
const fn __discriminant(__this: &Test) -> isize {
5959
match __this {
6060
Test::A => 0,
6161
Test::B(ref __field_0) => 1,

src/test/partial_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn enum_() -> Result<()> {
7171
};
7272
#[cfg(not(feature = "nightly"))]
7373
let partial_ord = quote! {
74-
fn __discriminant<T>(__this: &Test<T>) -> isize {
74+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
7575
match __this {
7676
Test::A { field: ref __field_field } => 0,
7777
Test::B { } => 1,

src/test/skip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn variants_empty() -> Result<()> {
102102
};
103103
#[cfg(not(feature = "nightly"))]
104104
let ord = quote! {
105-
fn __discriminant<T>(__this: &Test<T>) -> isize {
105+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
106106
match __this {
107107
Test::A(ref __field_0) => 0,
108108
Test::B(ref __field_0) => 1
@@ -151,7 +151,7 @@ fn variants_partly_empty() -> Result<()> {
151151
};
152152
#[cfg(not(feature = "nightly"))]
153153
let ord = quote! {
154-
fn __discriminant<T>(__this: &Test<T>) -> isize {
154+
const fn __discriminant<T>(__this: &Test<T>) -> isize {
155155
match __this {
156156
Test::A(ref __field_0) => 0,
157157
Test::B(ref __field_0, ref __field_1) => 1

src/trait_/common_ord.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn build_discriminant_order(
349349
quote! {
350350
#validate_c
351351

352-
fn __discriminant #imp(__this: &#item #ty) -> #repr #where_clause {
352+
const fn __discriminant #imp(__this: &#item #ty) -> #repr #where_clause {
353353
match __this {
354354
#(#variants),*
355355
}

0 commit comments

Comments
 (0)