Skip to content

Commit 54bad93

Browse files
committed
Add a couple more test cases, including non-ascii strings.
1 parent 5cb0039 commit 54bad93

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/test/ui/const-generics/slice-const-param-mismatch.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ struct ConstString<const T: &'static str>;
55
struct ConstBytes<const T: &'static [u8]>;
66

77
pub fn main() {
8+
let _: ConstString<"Hello"> = ConstString::<"Hello">;
89
let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types
10+
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">;
11+
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types
912
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
1013
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types
1114
}

src/test/ui/const-generics/slice-const-param-mismatch.stderr

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #![feature(const_generics)]
77
= note: `#[warn(incomplete_features)]` on by default
88

99
error[E0308]: mismatched types
10-
--> $DIR/slice-const-param-mismatch.rs:8:35
10+
--> $DIR/slice-const-param-mismatch.rs:9:35
1111
|
1212
LL | let _: ConstString<"Hello"> = ConstString::<"World">;
1313
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"`
@@ -16,14 +16,23 @@ LL | let _: ConstString<"Hello"> = ConstString::<"World">;
1616
found type `ConstString<>`
1717

1818
error[E0308]: mismatched types
19-
--> $DIR/slice-const-param-mismatch.rs:10:33
19+
--> $DIR/slice-const-param-mismatch.rs:11:33
20+
|
21+
LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">;
22+
| ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"`
23+
|
24+
= note: expected type `ConstString<>`
25+
found type `ConstString<>`
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/slice-const-param-mismatch.rs:13:33
2029
|
2130
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
2231
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"`
2332
|
2433
= note: expected type `ConstBytes<>`
2534
found type `ConstBytes<>`
2635

27-
error: aborting due to 2 previous errors
36+
error: aborting due to 3 previous errors
2837

2938
For more information about this error, try `rustc --explain E0308`.

src/test/ui/const-generics/slice-const-param.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
1313

1414
pub fn main() {
1515
assert_eq!(function_with_str::<"Rust">(), "Rust");
16+
assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦");
1617
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
1718
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
1819
}

0 commit comments

Comments
 (0)