Skip to content

Commit

Permalink
Added test for mismatched slices, and byte slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinnyBat committed Sep 28, 2019
1 parent c94fea0 commit 5cb0039
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/test/ui/const-generics/slice-const-param-mismatch.rs
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions src/test/ui/const-generics/slice-const-param-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Original file line number Diff line number Diff line change
@@ -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)]
| ^^^^^^^^^^^^^^
Expand Down

0 comments on commit 5cb0039

Please sign in to comment.