Skip to content

Commit a639e27

Browse files
committed
Allow transmuting generic pattern types to and from their base
1 parent 22f0741 commit a639e27

File tree

3 files changed

+6
-23
lines changed

3 files changed

+6
-23
lines changed

Diff for: compiler/rustc_middle/src/ty/layout.rs

+3
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ impl<'tcx> SizeSkeleton<'tcx> {
504504
}
505505
}
506506

507+
// Pattern types are always the same size as their base.
508+
ty::Pat(base, _) => SizeSkeleton::compute(base, tcx, typing_env),
509+
507510
_ => Err(err),
508511
}
509512
}

Diff for: tests/ui/type/pattern_types/transmute.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ use std::pat::pattern_type;
66
// ok
77
fn create<const S: u32, const E: u32>(x: u32) -> pattern_type!(u32 is S..=E) {
88
unsafe { std::mem::transmute(x) }
9-
//~^ ERROR types of different sizes
109
}
1110

1211
// ok
1312
fn unwrap<const S: u32, const E: u32>(x: pattern_type!(u32 is S..=E)) -> u32 {
1413
unsafe { std::mem::transmute(x) }
15-
//~^ ERROR types of different sizes
1614
}
1715

1816
// bad, only when S != u32::MIN or E != u32::MAX will this ok

Diff for: tests/ui/type/pattern_types/transmute.stderr

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
2-
--> $DIR/transmute.rs:8:14
3-
|
4-
LL | unsafe { std::mem::transmute(x) }
5-
| ^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: source type: `u32` (32 bits)
8-
= note: target type: `(u32) is S..=E` (size can vary because of u32)
9-
10-
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
11-
--> $DIR/transmute.rs:14:14
12-
|
13-
LL | unsafe { std::mem::transmute(x) }
14-
| ^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: source type: `(u32) is S..=E` (size can vary because of u32)
17-
= note: target type: `u32` (32 bits)
18-
19-
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
20-
--> $DIR/transmute.rs:22:14
2+
--> $DIR/transmute.rs:20:14
213
|
224
LL | unsafe { std::mem::transmute(x) }
235
| ^^^^^^^^^^^^^^^^^^^
@@ -26,14 +8,14 @@ LL | unsafe { std::mem::transmute(x) }
268
= note: target type: `u32` (32 bits)
279

2810
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
29-
--> $DIR/transmute.rs:30:14
11+
--> $DIR/transmute.rs:28:14
3012
|
3113
LL | unsafe { std::mem::transmute(x) }
3214
| ^^^^^^^^^^^^^^^^^^^
3315
|
3416
= note: source type: `Option<(u32) is S..=E>` (size can vary because of u32)
3517
= note: target type: `Option<u32>` (64 bits)
3618

37-
error: aborting due to 4 previous errors
19+
error: aborting due to 2 previous errors
3820

3921
For more information about this error, try `rustc --explain E0512`.

0 commit comments

Comments
 (0)