diff options
| author | ben <benlewisj@gmail.com> | 2019-09-28 15:07:22 +1200 |
|---|---|---|
| committer | ben <benlewisj@gmail.com> | 2019-09-28 15:07:22 +1200 |
| commit | 5cb0039cffce1726c08e0c3633e7ee5d7c72c8c0 (patch) | |
| tree | d8b8321c740c48ab6b73f13edeca905fc58162f1 | |
| parent | c94fea092e0a8f38855e2ed9a57704cd4ca85a38 (diff) | |
| download | rust-5cb0039cffce1726c08e0c3633e7ee5d7c72c8c0.tar.gz rust-5cb0039cffce1726c08e0c3633e7ee5d7c72c8c0.zip | |
Added test for mismatched slices, and byte slices.
| -rw-r--r-- | src/test/ui/const-generics/slice-const-param-mismatch.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/const-generics/slice-const-param-mismatch.stderr | 29 | ||||
| -rw-r--r-- | src/test/ui/const-generics/slice-const-param.rs (renamed from src/test/ui/const-generics/str-const-param.rs) | 6 | ||||
| -rw-r--r-- | src/test/ui/const-generics/slice-const-param.stderr (renamed from src/test/ui/const-generics/str-const-param.stderr) | 2 |
4 files changed, 47 insertions, 1 deletions
diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.rs b/src/test/ui/const-generics/slice-const-param-mismatch.rs new file mode 100644 index 00000000000..edc9a0f09ff --- /dev/null +++ b/src/test/ui/const-generics/slice-const-param-mismatch.rs @@ -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 +} diff --git a/src/test/ui/const-generics/slice-const-param-mismatch.stderr b/src/test/ui/const-generics/slice-const-param-mismatch.stderr new file mode 100644 index 00000000000..1c3afa00b49 --- /dev/null +++ b/src/test/ui/const-generics/slice-const-param-mismatch.stderr @@ -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`. diff --git a/src/test/ui/const-generics/str-const-param.rs b/src/test/ui/const-generics/slice-const-param.rs index a455ca994b8..ba82a0377bf 100644 --- a/src/test/ui/const-generics/str-const-param.rs +++ b/src/test/ui/const-generics/slice-const-param.rs @@ -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"); } diff --git a/src/test/ui/const-generics/str-const-param.stderr b/src/test/ui/const-generics/slice-const-param.stderr index 9b71b5b586e..79214a34fdb 100644 --- a/src/test/ui/const-generics/str-const-param.stderr +++ b/src/test/ui/const-generics/slice-const-param.stderr @@ -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)] | ^^^^^^^^^^^^^^ |
