Add a couple more test cases, including non-ascii strings.

This commit is contained in:
ben 2019-09-29 08:39:48 +13:00
parent 5cb0039cff
commit 54bad93030
3 changed files with 16 additions and 3 deletions

View file

@ -5,7 +5,10 @@ struct ConstString<const T: &'static str>;
struct ConstBytes<const T: &'static [u8]>;
pub fn main() {
let _: ConstString<"Hello"> = ConstString::<"Hello">;
let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">;
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types
}

View file

@ -7,7 +7,7 @@ LL | #![feature(const_generics)]
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:8:35
--> $DIR/slice-const-param-mismatch.rs:9:35
|
LL | let _: ConstString<"Hello"> = ConstString::<"World">;
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"`
@ -16,7 +16,16 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">;
found type `ConstString<>`
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:10:33
--> $DIR/slice-const-param-mismatch.rs:11:33
|
LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">;
| ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"`
|
= note: expected type `ConstString<>`
found type `ConstString<>`
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:13:33
|
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"`
@ -24,6 +33,6 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
= note: expected type `ConstBytes<>`
found type `ConstBytes<>`
error: aborting due to 2 previous errors
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -13,6 +13,7 @@ pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
pub fn main() {
assert_eq!(function_with_str::<"Rust">(), "Rust");
assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦");
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
}