Skip to content

Commit 9d3192a

Browse files
Rollup merge of rust-lang#155433 - oli-obk:bye-bye-long-attribute, r=RalfJung,ShoyuVanilla
Rip out rustc_layout_scalar_valid_range_* attribute support And either removes tests for it or replaces the uses with pattern types. primarily fixes rust-lang#135996 fixes rust-lang#147761 fixes rust-lang#133652
2 parents e1e72db + 3e0e895 commit 9d3192a

3 files changed

Lines changed: 39 additions & 33 deletions

File tree

tests/ui/eager_transmute.fixed

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#![feature(rustc_attrs)]
1+
#![feature(rustc_attrs, pattern_types, pattern_type_macro)]
22
#![warn(clippy::eager_transmute)]
33
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
44

55
use std::num::NonZero;
6+
use std::pat::pattern_type;
67

78
#[repr(u8)]
89
enum Opcode {
@@ -77,23 +78,25 @@ unsafe fn f2(op: u8) {
7778
}
7879
}
7980

80-
#[rustc_layout_scalar_valid_range_end(254)]
81-
struct NonMaxU8(u8);
82-
#[rustc_layout_scalar_valid_range_end(254)]
83-
#[rustc_layout_scalar_valid_range_start(1)]
84-
struct NonZeroNonMaxU8(u8);
81+
struct NonMaxU8(pattern_type!(u8 is 0..=254));
82+
struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254));
8583

8684
macro_rules! impls {
8785
($($t:ty),*) => {
8886
$(
87+
impl $t {
88+
fn get(&self) -> u8 {
89+
unsafe { std::mem::transmute(self.0) }
90+
}
91+
}
8992
impl PartialEq<u8> for $t {
9093
fn eq(&self, other: &u8) -> bool {
91-
self.0 == *other
94+
self.get() == *other
9295
}
9396
}
9497
impl PartialOrd<u8> for $t {
9598
fn partial_cmp(&self, other: &u8) -> Option<std::cmp::Ordering> {
96-
self.0.partial_cmp(other)
99+
self.get().partial_cmp(other)
97100
}
98101
}
99102
)*

tests/ui/eager_transmute.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#![feature(rustc_attrs)]
1+
#![feature(rustc_attrs, pattern_types, pattern_type_macro)]
22
#![warn(clippy::eager_transmute)]
33
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
44

55
use std::num::NonZero;
6+
use std::pat::pattern_type;
67

78
#[repr(u8)]
89
enum Opcode {
@@ -77,23 +78,25 @@ unsafe fn f2(op: u8) {
7778
}
7879
}
7980

80-
#[rustc_layout_scalar_valid_range_end(254)]
81-
struct NonMaxU8(u8);
82-
#[rustc_layout_scalar_valid_range_end(254)]
83-
#[rustc_layout_scalar_valid_range_start(1)]
84-
struct NonZeroNonMaxU8(u8);
81+
struct NonMaxU8(pattern_type!(u8 is 0..=254));
82+
struct NonZeroNonMaxU8(pattern_type!(u8 is 1..=254));
8583

8684
macro_rules! impls {
8785
($($t:ty),*) => {
8886
$(
87+
impl $t {
88+
fn get(&self) -> u8 {
89+
unsafe { std::mem::transmute(self.0) }
90+
}
91+
}
8992
impl PartialEq<u8> for $t {
9093
fn eq(&self, other: &u8) -> bool {
91-
self.0 == *other
94+
self.get() == *other
9295
}
9396
}
9497
impl PartialOrd<u8> for $t {
9598
fn partial_cmp(&self, other: &u8) -> Option<std::cmp::Ordering> {
96-
self.0.partial_cmp(other)
99+
self.get().partial_cmp(other)
97100
}
98101
}
99102
)*

tests/ui/eager_transmute.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this transmute is always evaluated eagerly, even if the condition is false
2-
--> tests/ui/eager_transmute.rs:21:33
2+
--> tests/ui/eager_transmute.rs:22:33
33
|
44
LL | (op < 4).then_some(unsafe { std::mem::transmute(op) })
55
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -13,7 +13,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute(op) })
1313
|
1414

1515
error: this transmute is always evaluated eagerly, even if the condition is false
16-
--> tests/ui/eager_transmute.rs:28:33
16+
--> tests/ui/eager_transmute.rs:29:33
1717
|
1818
LL | (op < 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) });
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL + (op < 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) });
2525
|
2626

2727
error: this transmute is always evaluated eagerly, even if the condition is false
28-
--> tests/ui/eager_transmute.rs:30:33
28+
--> tests/ui/eager_transmute.rs:31:33
2929
|
3030
LL | (op > 4).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) });
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -37,7 +37,7 @@ LL + (op > 4).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) });
3737
|
3838

3939
error: this transmute is always evaluated eagerly, even if the condition is false
40-
--> tests/ui/eager_transmute.rs:32:34
40+
--> tests/ui/eager_transmute.rs:33:34
4141
|
4242
LL | (op == 0).then_some(unsafe { std::mem::transmute::<_, Opcode>(op) });
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL + (op == 0).then(|| unsafe { std::mem::transmute::<_, Opcode>(op) });
4949
|
5050

5151
error: this transmute is always evaluated eagerly, even if the condition is false
52-
--> tests/ui/eager_transmute.rs:35:68
52+
--> tests/ui/eager_transmute.rs:36:68
5353
|
5454
LL | let _: Option<Opcode> = (op > 0 && op < 10).then_some(unsafe { std::mem::transmute(op) });
5555
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -61,7 +61,7 @@ LL + let _: Option<Opcode> = (op > 0 && op < 10).then(|| unsafe { std::mem::
6161
|
6262

6363
error: this transmute is always evaluated eagerly, even if the condition is false
64-
--> tests/ui/eager_transmute.rs:37:86
64+
--> tests/ui/eager_transmute.rs:38:86
6565
|
6666
LL | let _: Option<Opcode> = (op > 0 && op < 10 && unrelated == 0).then_some(unsafe { std::mem::transmute(op) });
6767
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -73,7 +73,7 @@ LL + let _: Option<Opcode> = (op > 0 && op < 10 && unrelated == 0).then(|| u
7373
|
7474

7575
error: this transmute is always evaluated eagerly, even if the condition is false
76-
--> tests/ui/eager_transmute.rs:41:84
76+
--> tests/ui/eager_transmute.rs:42:84
7777
|
7878
LL | let _: Option<Opcode> = (op2.foo[0] > 0 && op2.foo[0] < 10).then_some(unsafe { std::mem::transmute(op2.foo[0]) });
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -85,7 +85,7 @@ LL + let _: Option<Opcode> = (op2.foo[0] > 0 && op2.foo[0] < 10).then(|| uns
8585
|
8686

8787
error: this transmute is always evaluated eagerly, even if the condition is false
88-
--> tests/ui/eager_transmute.rs:54:70
88+
--> tests/ui/eager_transmute.rs:55:70
8989
|
9090
LL | let _: Option<Opcode> = (1..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) });
9191
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -97,7 +97,7 @@ LL + let _: Option<Opcode> = (1..=3).contains(&op).then(|| unsafe { std::mem
9797
|
9898

9999
error: this transmute is always evaluated eagerly, even if the condition is false
100-
--> tests/ui/eager_transmute.rs:56:83
100+
--> tests/ui/eager_transmute.rs:57:83
101101
|
102102
LL | let _: Option<Opcode> = ((1..=3).contains(&op) || op == 4).then_some(unsafe { std::mem::transmute(op) });
103103
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -109,7 +109,7 @@ LL + let _: Option<Opcode> = ((1..=3).contains(&op) || op == 4).then(|| unsa
109109
|
110110

111111
error: this transmute is always evaluated eagerly, even if the condition is false
112-
--> tests/ui/eager_transmute.rs:58:69
112+
--> tests/ui/eager_transmute.rs:59:69
113113
|
114114
LL | let _: Option<Opcode> = (1..3).contains(&op).then_some(unsafe { std::mem::transmute(op) });
115115
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL + let _: Option<Opcode> = (1..3).contains(&op).then(|| unsafe { std::mem:
121121
|
122122

123123
error: this transmute is always evaluated eagerly, even if the condition is false
124-
--> tests/ui/eager_transmute.rs:60:68
124+
--> tests/ui/eager_transmute.rs:61:68
125125
|
126126
LL | let _: Option<Opcode> = (1..).contains(&op).then_some(unsafe { std::mem::transmute(op) });
127127
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -133,7 +133,7 @@ LL + let _: Option<Opcode> = (1..).contains(&op).then(|| unsafe { std::mem::
133133
|
134134

135135
error: this transmute is always evaluated eagerly, even if the condition is false
136-
--> tests/ui/eager_transmute.rs:62:68
136+
--> tests/ui/eager_transmute.rs:63:68
137137
|
138138
LL | let _: Option<Opcode> = (..3).contains(&op).then_some(unsafe { std::mem::transmute(op) });
139139
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -145,7 +145,7 @@ LL + let _: Option<Opcode> = (..3).contains(&op).then(|| unsafe { std::mem::
145145
|
146146

147147
error: this transmute is always evaluated eagerly, even if the condition is false
148-
--> tests/ui/eager_transmute.rs:64:69
148+
--> tests/ui/eager_transmute.rs:65:69
149149
|
150150
LL | let _: Option<Opcode> = (..=3).contains(&op).then_some(unsafe { std::mem::transmute(op) });
151151
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -157,7 +157,7 @@ LL + let _: Option<Opcode> = (..=3).contains(&op).then(|| unsafe { std::mem:
157157
|
158158

159159
error: this transmute is always evaluated eagerly, even if the condition is false
160-
--> tests/ui/eager_transmute.rs:75:28
160+
--> tests/ui/eager_transmute.rs:76:28
161161
|
162162
LL | (op < 4).then_some(std::mem::transmute::<_, Opcode>(op));
163163
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -169,7 +169,7 @@ LL + (op < 4).then(|| std::mem::transmute::<_, Opcode>(op));
169169
|
170170

171171
error: this transmute is always evaluated eagerly, even if the condition is false
172-
--> tests/ui/eager_transmute.rs:106:62
172+
--> tests/ui/eager_transmute.rs:109:62
173173
|
174174
LL | let _: Option<NonZero<u8>> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
175175
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -181,7 +181,7 @@ LL + let _: Option<NonZero<u8>> = (v1 > 0).then(|| unsafe { std::mem::transm
181181
|
182182

183183
error: this transmute is always evaluated eagerly, even if the condition is false
184-
--> tests/ui/eager_transmute.rs:113:86
184+
--> tests/ui/eager_transmute.rs:116:86
185185
|
186186
LL | let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
187187
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -193,7 +193,7 @@ LL + let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| u
193193
|
194194

195195
error: this transmute is always evaluated eagerly, even if the condition is false
196-
--> tests/ui/eager_transmute.rs:120:93
196+
--> tests/ui/eager_transmute.rs:123:93
197197
|
198198
LL | let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
199199
| ^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)