blob: 43a2e43190433b042ed96fafc7d3d8b0b66b9e2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//@ check-pass
#![deny(dead_code)]
#[repr(u8)]
#[derive(Copy, Clone, Debug)]
pub enum RecordField {
Target = 1,
Level,
Module,
File,
Line,
NumArgs,
}
unsafe trait Pod {}
#[repr(transparent)]
struct RecordFieldWrapper(RecordField);
unsafe impl Pod for RecordFieldWrapper {}
fn try_read<T: Pod>(buf: &[u8]) -> T {
unsafe { std::ptr::read_unaligned(buf.as_ptr() as *const T) }
}
pub fn foo(buf: &[u8]) -> RecordField {
let RecordFieldWrapper(tag) = try_read(buf);
tag
}
fn main() {}
|