Skip to content

Commit

Permalink
Add a couple more test cases, including non-ascii strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinnyBat committed Sep 28, 2019
1 parent 5cb0039 commit 54bad93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/test/ui/const-generics/slice-const-param-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions src/test/ui/const-generics/slice-const-param-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -16,14 +16,23 @@ 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"`
|
= 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`.
1 change: 1 addition & 0 deletions src/test/ui/const-generics/slice-const-param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit 54bad93

Please sign in to comment.