Added test for mismatched slices, and byte slices.

This commit is contained in:
ben 2019-09-28 15:07:22 +12:00
parent c94fea092e
commit 5cb0039cff
4 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,11 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
struct ConstString<const T: &'static str>;
struct ConstBytes<const T: &'static [u8]>;
pub fn main() {
let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types
}

View file

@ -0,0 +1,29 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/slice-const-param-mismatch.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:8:35
|
LL | let _: ConstString<"Hello"> = ConstString::<"World">;
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"`
|
= note: expected type `ConstString<>`
found type `ConstString<>`
error[E0308]: mismatched types
--> $DIR/slice-const-param-mismatch.rs:10:33
|
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"`
|
= note: expected type `ConstBytes<>`
found type `ConstBytes<>`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

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

View file

@ -1,5 +1,5 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/str-const-param.rs:3:12
--> $DIR/slice-const-param.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^