]> git.proxmox.com Git - rustc.git/blame - src/test/ui/consts/issue-87046.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / src / test / ui / consts / issue-87046.rs
CommitLineData
136023e0
XL
1// Regression test for the ICE described in #87046.
2
3#![crate_type="lib"]
4#![allow(unreachable_patterns)]
136023e0
XL
5
6#[derive(PartialEq, Eq)]
7#[repr(transparent)]
8pub struct Username(str);
9
10pub const ROOT_USER: &Username = Username::from_str("root");
11
12impl Username {
13 pub const fn from_str(raw: &str) -> &Self {
14 union Transmute<'a> {
15 raw: &'a str,
16 typed: &'a Username,
17 }
18
19 unsafe { Transmute { raw }.typed }
20 }
21
22 pub const fn as_str(&self) -> &str {
23 &self.0
24 }
25
26 pub fn is_root(&self) -> bool {
27 match self {
28 ROOT_USER => true,
29 //~^ ERROR: cannot use unsized non-slice type `Username` in constant patterns
30 _ => false,
31 }
32 }
33}