Skip to content

Commit b66b322

Browse files
committed
add testcase that hits valtree_into_mplace with a custom DST
1 parent bc720ad commit b66b322

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/ui/const-generics/slice-const-param.rs

+21
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,30 @@ pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
1111
BYTES
1212
}
1313

14+
// Also check the codepaths for custom DST
15+
#[derive(PartialEq, Eq)]
16+
struct MyStr(str);
17+
impl std::marker::ConstParamTy for MyStr {}
18+
19+
fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr {
20+
S
21+
}
22+
23+
impl MyStr {
24+
const fn new(s: &'static str) -> &'static MyStr {
25+
unsafe { std::mem::transmute(s) }
26+
}
27+
28+
fn as_str(&self) -> &str {
29+
&self.0
30+
}
31+
}
32+
1433
pub fn main() {
1534
assert_eq!(function_with_str::<"Rust">(), "Rust");
1635
assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦");
1736
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
1837
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
38+
39+
assert_eq!(function_with_my_str::<{ MyStr::new("hello") }>().as_str(), "hello");
1940
}

0 commit comments

Comments
 (0)