Skip to content

Commit 5cb0039

Browse files
committed
Added test for mismatched slices, and byte slices.
1 parent c94fea0 commit 5cb0039

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
struct ConstString<const T: &'static str>;
5+
struct ConstBytes<const T: &'static [u8]>;
6+
7+
pub fn main() {
8+
let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types
9+
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>;
10+
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/slice-const-param-mismatch.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/slice-const-param-mismatch.rs:8:35
11+
|
12+
LL | let _: ConstString<"Hello"> = ConstString::<"World">;
13+
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"`
14+
|
15+
= note: expected type `ConstString<>`
16+
found type `ConstString<>`
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/slice-const-param-mismatch.rs:10:33
20+
|
21+
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
22+
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"`
23+
|
24+
= note: expected type `ConstBytes<>`
25+
found type `ConstBytes<>`
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/const-generics/str-const-param.rs renamed to src/test/ui/const-generics/slice-const-param.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ pub fn function_with_str<const STRING: &'static str>() -> &'static str {
77
STRING
88
}
99

10+
pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] {
11+
BYTES
12+
}
13+
1014
pub fn main() {
1115
assert_eq!(function_with_str::<"Rust">(), "Rust");
16+
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
17+
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
1218
}

src/test/ui/const-generics/str-const-param.stderr renamed to src/test/ui/const-generics/slice-const-param.stderr

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

0 commit comments

Comments
 (0)