Skip to content

Commit 283b81c

Browse files
committed
Allow transmuting generic pattern types to and from their base
1 parent e1cbd6c commit 283b81c

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

compiler/rustc_middle/src/ty/layout.rs

+3
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ impl<'tcx> SizeSkeleton<'tcx> {
498498
}
499499
}
500500

501+
// Pattern types are always the same size as their base.
502+
ty::Pat(base, _) => SizeSkeleton::compute(base, tcx, typing_env),
503+
501504
_ => Err(err),
502505
}
503506
}
+5-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
//! Ensure we can transmute between pattern types and their base types
2+
//! in generic contexts.
3+
4+
//@ check-pass
5+
16
#![feature(pattern_types)]
27
#![feature(pattern_type_macro)]
38

49
use std::pat::pattern_type;
510

611
fn create<const S: u32, const E: u32>(x: u32) -> pattern_type!(u32 is S..=E) {
712
unsafe { std::mem::transmute(x) }
8-
//~^ ERROR types of different sizes
913
}
1014

1115
fn unwrap<const S: u32, const E: u32>(x: pattern_type!(u32 is S..=E)) -> u32 {
1216
unsafe { std::mem::transmute(x) }
13-
//~^ ERROR types of different sizes
1417
}
1518

1619
fn main() {}

tests/ui/type/pattern_types/transmute.stderr

-21
This file was deleted.

0 commit comments

Comments
 (0)