]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/issue-87046.rs
Rollup merge of #106962 - compiler-errors:use-sugg-span, r=oli-obk
[rust.git] / tests / ui / consts / issue-87046.rs
1 // Regression test for the ICE described in #87046.
2
3 #![crate_type="lib"]
4 #![allow(unreachable_patterns)]
5
6 #[derive(PartialEq, Eq)]
7 #[repr(transparent)]
8 pub struct Username(str);
9
10 pub const ROOT_USER: &Username = Username::from_str("root");
11
12 impl 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 }