2021-08-27 16:04:57 +00:00
|
|
|
//@ run-pass
|
2019-09-27 07:43:46 +00:00
|
|
|
|
2021-08-30 08:59:53 +00:00
|
|
|
#![feature(adt_const_params)]
|
2021-08-27 16:04:57 +00:00
|
|
|
#![allow(incomplete_features)]
|
2019-09-27 07:43:46 +00:00
|
|
|
|
|
|
|
pub fn function_with_str<const STRING: &'static str>() -> &'static str {
|
|
|
|
STRING
|
|
|
|
}
|
|
|
|
|
2019-09-28 03:07:22 +00:00
|
|
|
pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
|
|
|
|
BYTES
|
|
|
|
}
|
|
|
|
|
2023-08-05 11:23:12 +00:00
|
|
|
// Also check the codepaths for custom DST
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
struct MyStr(str);
|
|
|
|
impl std::marker::ConstParamTy for MyStr {}
|
|
|
|
|
|
|
|
fn function_with_my_str<const S: &'static MyStr>() -> &'static MyStr {
|
|
|
|
S
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MyStr {
|
|
|
|
const fn new(s: &'static str) -> &'static MyStr {
|
|
|
|
unsafe { std::mem::transmute(s) }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 07:43:46 +00:00
|
|
|
pub fn main() {
|
|
|
|
assert_eq!(function_with_str::<"Rust">(), "Rust");
|
2019-09-28 19:39:48 +00:00
|
|
|
assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦");
|
2019-09-28 03:07:22 +00:00
|
|
|
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
|
|
|
|
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
|
2023-08-05 11:23:12 +00:00
|
|
|
|
|
|
|
assert_eq!(function_with_my_str::<{ MyStr::new("hello") }>().as_str(), "hello");
|
2019-09-27 07:43:46 +00:00
|
|
|
}
|