From 5cb0039cffce1726c08e0c3633e7ee5d7c72c8c0 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 28 Sep 2019 15:07:22 +1200 Subject: [PATCH] Added test for mismatched slices, and byte slices. --- .../slice-const-param-mismatch.rs | 11 +++++++ .../slice-const-param-mismatch.stderr | 29 +++++++++++++++++++ ...tr-const-param.rs => slice-const-param.rs} | 6 ++++ ...-param.stderr => slice-const-param.stderr} | 2 +- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/const-generics/slice-const-param-mismatch.rs create mode 100644 src/test/ui/const-generics/slice-const-param-mismatch.stderr rename src/test/ui/const-generics/{str-const-param.rs => slice-const-param.rs} (54%) rename src/test/ui/const-generics/{str-const-param.stderr => slice-const-param.stderr} (85%) 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 000000000000..edc9a0f09ff2 --- /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; +struct ConstBytes; + +pub fn main() { + let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types + let _: ConstBytes = ConstBytes::<{&[0x41, 0x41, 0x41]}>; + let _: ConstBytes = ConstBytes::; //~ 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 000000000000..1c3afa00b494 --- /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 = ConstBytes::; + | ^^^^^^^^^^^^^^^^^^^^ 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 similarity index 54% rename from src/test/ui/const-generics/str-const-param.rs rename to src/test/ui/const-generics/slice-const-param.rs index a455ca994b8d..ba82a0377bf2 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() -> &'static str { STRING } +pub fn function_with_bytes() -> &'static [u8] { + BYTES +} + pub fn main() { assert_eq!(function_with_str::<"Rust">(), "Rust"); + assert_eq!(function_with_bytes::(), &[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 similarity index 85% rename from src/test/ui/const-generics/str-const-param.stderr rename to src/test/ui/const-generics/slice-const-param.stderr index 9b71b5b586e1..79214a34fdba 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)] | ^^^^^^^^^^^^^^