-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ICE with unsized type in const pattern
- Loading branch information
1 parent
81053b9
commit 79f0743
Showing
3 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Regression test for the ICE described in #87046. | ||
|
||
#![crate_type="lib"] | ||
#![allow(unreachable_patterns)] | ||
#![feature(const_fn_union)] | ||
|
||
#[derive(PartialEq, Eq)] | ||
#[repr(transparent)] | ||
pub struct Username(str); | ||
|
||
pub const ROOT_USER: &Username = Username::from_str("root"); | ||
|
||
impl Username { | ||
pub const fn from_str(raw: &str) -> &Self { | ||
union Transmute<'a> { | ||
raw: &'a str, | ||
typed: &'a Username, | ||
} | ||
|
||
unsafe { Transmute { raw }.typed } | ||
} | ||
|
||
pub const fn as_str(&self) -> &str { | ||
&self.0 | ||
} | ||
|
||
pub fn is_root(&self) -> bool { | ||
match self { | ||
ROOT_USER => true, | ||
//~^ ERROR: cannot use unsized non-slice type `Username` in constant patterns | ||
_ => false, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: cannot use unsized non-slice type `Username` in constant patterns | ||
--> $DIR/issue-87046.rs:29:13 | ||
| | ||
LL | ROOT_USER => true, | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|