]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/issue-87046.rs
Rollup merge of #87596 - jesyspa:issue-87318-hidden-whitespace, r=estebank
[rust.git] / src / test / ui / consts / issue-87046.rs
1 // Regression test for the ICE described in #87046.
2
3 #![crate_type="lib"]
4 #![allow(unreachable_patterns)]
5 #![feature(const_fn_union)]
6
7 #[derive(PartialEq, Eq)]
8 #[repr(transparent)]
9 pub struct Username(str);
10
11 pub const ROOT_USER: &Username = Username::from_str("root");
12
13 impl Username {
14     pub const fn from_str(raw: &str) -> &Self {
15         union Transmute<'a> {
16             raw: &'a str,
17             typed: &'a Username,
18         }
19
20         unsafe { Transmute { raw }.typed }
21     }
22
23     pub const fn as_str(&self) -> &str {
24         &self.0
25     }
26
27     pub fn is_root(&self) -> bool {
28         match self {
29             ROOT_USER => true,
30             //~^ ERROR: cannot use unsized non-slice type `Username` in constant patterns
31             _ => false,
32         }
33     }
34 }