about summary refs log tree commit diff
path: root/src/test/ui/array-slice-vec
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-01 07:46:11 +0000
committerbors <bors@rust-lang.org>2021-01-01 07:46:11 +0000
commite1fc9ff4a794fb069d670dded1a66f05c86f3555 (patch)
tree0f63753eac2e24499b1bec197ccbb5a086e60de9 /src/test/ui/array-slice-vec
parentf8ab56bf3201b0638e44caf5a484041f22e32d65 (diff)
parent9fb9f290b41927ea1533eace0f4c9d295faeba90 (diff)
downloadrust-e1fc9ff4a794fb069d670dded1a66f05c86f3555.tar.gz
rust-e1fc9ff4a794fb069d670dded1a66f05c86f3555.zip
Auto merge of #80539 - JohnTitor:ui-test-root-cleanup, r=petrochenkov
Reduce the entry on `src/test/ui` (UI test root)

CC #73494, similar to #79776.

r? `@petrochenkov`
Diffstat (limited to 'src/test/ui/array-slice-vec')
-rw-r--r--src/test/ui/array-slice-vec/array-break-length.rs9
-rw-r--r--src/test/ui/array-slice-vec/array-break-length.stderr15
-rw-r--r--src/test/ui/array-slice-vec/array-not-vector.rs12
-rw-r--r--src/test/ui/array-slice-vec/array-not-vector.stderr22
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-0.rs8
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-0.stderr12
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-1.rs14
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-1.stderr12
-rw-r--r--src/test/ui/array-slice-vec/array_const_index-2.rs12
-rw-r--r--src/test/ui/array-slice-vec/slice-2.rs11
-rw-r--r--src/test/ui/array-slice-vec/slice-2.stderr27
-rw-r--r--src/test/ui/array-slice-vec/slice-mut-2.rs8
-rw-r--r--src/test/ui/array-slice-vec/slice-mut-2.stderr12
-rw-r--r--src/test/ui/array-slice-vec/slice-mut.rs12
-rw-r--r--src/test/ui/array-slice-vec/slice-mut.stderr14
-rw-r--r--src/test/ui/array-slice-vec/slice-to-vec-comparison.rs6
-rw-r--r--src/test/ui/array-slice-vec/slice-to-vec-comparison.stderr12
-rw-r--r--src/test/ui/array-slice-vec/vec-macro-with-comma-only.rs3
-rw-r--r--src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr8
-rw-r--r--src/test/ui/array-slice-vec/vec-mut-iter-borrow.rs7
-rw-r--r--src/test/ui/array-slice-vec/vec-mut-iter-borrow.stderr14
-rw-r--r--src/test/ui/array-slice-vec/vec-overrun.rs12
-rw-r--r--src/test/ui/array-slice-vec/vec-res-add.rs19
-rw-r--r--src/test/ui/array-slice-vec/vec-res-add.stderr11
-rw-r--r--src/test/ui/array-slice-vec/vector-cast-weirdness.rs24
-rw-r--r--src/test/ui/array-slice-vec/vector-cast-weirdness.stderr9
-rw-r--r--src/test/ui/array-slice-vec/vector-no-ann.rs4
-rw-r--r--src/test/ui/array-slice-vec/vector-no-ann.stderr11
28 files changed, 331 insertions, 9 deletions
diff --git a/src/test/ui/array-slice-vec/array-break-length.rs b/src/test/ui/array-slice-vec/array-break-length.rs
new file mode 100644
index 00000000000..60589f7c264
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array-break-length.rs
@@ -0,0 +1,9 @@
+fn main() {
+    loop {
+        |_: [_; break]| {} //~ ERROR: `break` outside of a loop
+    }
+
+    loop {
+        |_: [_; continue]| {} //~ ERROR: `continue` outside of a loop
+    }
+}
diff --git a/src/test/ui/array-slice-vec/array-break-length.stderr b/src/test/ui/array-slice-vec/array-break-length.stderr
new file mode 100644
index 00000000000..93f1c238bcc
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array-break-length.stderr
@@ -0,0 +1,15 @@
+error[E0268]: `break` outside of a loop
+  --> $DIR/array-break-length.rs:3:17
+   |
+LL |         |_: [_; break]| {}
+   |                 ^^^^^ cannot `break` outside of a loop
+
+error[E0268]: `continue` outside of a loop
+  --> $DIR/array-break-length.rs:7:17
+   |
+LL |         |_: [_; continue]| {}
+   |                 ^^^^^^^^ cannot `continue` outside of a loop
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0268`.
diff --git a/src/test/ui/array-slice-vec/array-not-vector.rs b/src/test/ui/array-slice-vec/array-not-vector.rs
new file mode 100644
index 00000000000..5e46f015baf
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array-not-vector.rs
@@ -0,0 +1,12 @@
+fn main() {
+    let _x: i32 = [1, 2, 3];
+    //~^ ERROR mismatched types
+    //~| expected `i32`, found array
+
+    let x: &[i32] = &[1, 2, 3];
+    let _y: &i32 = x;
+    //~^ ERROR mismatched types
+    //~| expected reference `&i32`
+    //~| found reference `&[i32]`
+    //~| expected `i32`, found slice
+}
diff --git a/src/test/ui/array-slice-vec/array-not-vector.stderr b/src/test/ui/array-slice-vec/array-not-vector.stderr
new file mode 100644
index 00000000000..0e187d9072a
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array-not-vector.stderr
@@ -0,0 +1,22 @@
+error[E0308]: mismatched types
+  --> $DIR/array-not-vector.rs:2:19
+   |
+LL |     let _x: i32 = [1, 2, 3];
+   |             ---   ^^^^^^^^^ expected `i32`, found array `[{integer}; 3]`
+   |             |
+   |             expected due to this
+
+error[E0308]: mismatched types
+  --> $DIR/array-not-vector.rs:7:20
+   |
+LL |     let _y: &i32 = x;
+   |             ----   ^ expected `i32`, found slice `[i32]`
+   |             |
+   |             expected due to this
+   |
+   = note: expected reference `&i32`
+              found reference `&[i32]`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/array-slice-vec/array_const_index-0.rs b/src/test/ui/array-slice-vec/array_const_index-0.rs
new file mode 100644
index 00000000000..4021dfcc6eb
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array_const_index-0.rs
@@ -0,0 +1,8 @@
+const A: &'static [i32] = &[];
+const B: i32 = (&A)[1];
+//~^ index out of bounds: the length is 0 but the index is 1
+//~| ERROR any use of this value will cause an error
+
+fn main() {
+    let _ = B;
+}
diff --git a/src/test/ui/array-slice-vec/array_const_index-0.stderr b/src/test/ui/array-slice-vec/array_const_index-0.stderr
new file mode 100644
index 00000000000..7ccc3aa087e
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array_const_index-0.stderr
@@ -0,0 +1,12 @@
+error: any use of this value will cause an error
+  --> $DIR/array_const_index-0.rs:2:16
+   |
+LL | const B: i32 = (&A)[1];
+   | ---------------^^^^^^^-
+   |                |
+   |                index out of bounds: the length is 0 but the index is 1
+   |
+   = note: `#[deny(const_err)]` on by default
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/array-slice-vec/array_const_index-1.rs b/src/test/ui/array-slice-vec/array_const_index-1.rs
index 8ee225f5cdf..d0ee1796c0f 100644
--- a/src/test/ui/array-slice-vec/array_const_index-1.rs
+++ b/src/test/ui/array-slice-vec/array_const_index-1.rs
@@ -1,12 +1,8 @@
-// run-pass
-#![allow(dead_code)]
-#![allow(stable_features)]
-
-#![feature(const_indexing)]
+const A: [i32; 0] = [];
+const B: i32 = A[1];
+//~^ index out of bounds: the length is 0 but the index is 1
+//~| ERROR any use of this value will cause an error
 
 fn main() {
-    const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
-    const IDX: usize = 3;
-    const VAL: i32 = ARR[IDX];
-    const BLUB: [i32; (ARR[0] - 41) as usize] = [5];
+    let _ = B;
 }
diff --git a/src/test/ui/array-slice-vec/array_const_index-1.stderr b/src/test/ui/array-slice-vec/array_const_index-1.stderr
new file mode 100644
index 00000000000..37de61b9df0
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array_const_index-1.stderr
@@ -0,0 +1,12 @@
+error: any use of this value will cause an error
+  --> $DIR/array_const_index-1.rs:2:16
+   |
+LL | const B: i32 = A[1];
+   | ---------------^^^^-
+   |                |
+   |                index out of bounds: the length is 0 but the index is 1
+   |
+   = note: `#[deny(const_err)]` on by default
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/array-slice-vec/array_const_index-2.rs b/src/test/ui/array-slice-vec/array_const_index-2.rs
new file mode 100644
index 00000000000..8ee225f5cdf
--- /dev/null
+++ b/src/test/ui/array-slice-vec/array_const_index-2.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(stable_features)]
+
+#![feature(const_indexing)]
+
+fn main() {
+    const ARR: [i32; 6] = [42, 43, 44, 45, 46, 47];
+    const IDX: usize = 3;
+    const VAL: i32 = ARR[IDX];
+    const BLUB: [i32; (ARR[0] - 41) as usize] = [5];
+}
diff --git a/src/test/ui/array-slice-vec/slice-2.rs b/src/test/ui/array-slice-vec/slice-2.rs
new file mode 100644
index 00000000000..5423e295a87
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-2.rs
@@ -0,0 +1,11 @@
+// Test that slicing syntax gives errors if we have not implemented the trait.
+
+struct Foo;
+
+fn main() {
+    let x = Foo;
+    &x[..]; //~ ERROR cannot index into a value of type `Foo`
+    &x[Foo..]; //~ ERROR cannot index into a value of type `Foo`
+    &x[..Foo]; //~ ERROR cannot index into a value of type `Foo`
+    &x[Foo..Foo]; //~ ERROR cannot index into a value of type `Foo`
+}
diff --git a/src/test/ui/array-slice-vec/slice-2.stderr b/src/test/ui/array-slice-vec/slice-2.stderr
new file mode 100644
index 00000000000..561feb90f0a
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-2.stderr
@@ -0,0 +1,27 @@
+error[E0608]: cannot index into a value of type `Foo`
+  --> $DIR/slice-2.rs:7:6
+   |
+LL |     &x[..];
+   |      ^^^^^
+
+error[E0608]: cannot index into a value of type `Foo`
+  --> $DIR/slice-2.rs:8:6
+   |
+LL |     &x[Foo..];
+   |      ^^^^^^^^
+
+error[E0608]: cannot index into a value of type `Foo`
+  --> $DIR/slice-2.rs:9:6
+   |
+LL |     &x[..Foo];
+   |      ^^^^^^^^
+
+error[E0608]: cannot index into a value of type `Foo`
+  --> $DIR/slice-2.rs:10:6
+   |
+LL |     &x[Foo..Foo];
+   |      ^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0608`.
diff --git a/src/test/ui/array-slice-vec/slice-mut-2.rs b/src/test/ui/array-slice-vec/slice-mut-2.rs
new file mode 100644
index 00000000000..216edbb7808
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-mut-2.rs
@@ -0,0 +1,8 @@
+// Test mutability and slicing syntax.
+
+fn main() {
+    let x: &[isize] = &[1, 2, 3, 4, 5];
+    // Can't mutably slice an immutable slice
+    let slice: &mut [isize] = &mut [0, 1];
+    let _ = &mut x[2..4]; //~ERROR cannot borrow `*x` as mutable, as it is behind a `&` reference
+}
diff --git a/src/test/ui/array-slice-vec/slice-mut-2.stderr b/src/test/ui/array-slice-vec/slice-mut-2.stderr
new file mode 100644
index 00000000000..bad0268772b
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-mut-2.stderr
@@ -0,0 +1,12 @@
+error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
+  --> $DIR/slice-mut-2.rs:7:18
+   |
+LL |     let x: &[isize] = &[1, 2, 3, 4, 5];
+   |                       ---------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4, 5]`
+...
+LL |     let _ = &mut x[2..4];
+   |                  ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0596`.
diff --git a/src/test/ui/array-slice-vec/slice-mut.rs b/src/test/ui/array-slice-vec/slice-mut.rs
new file mode 100644
index 00000000000..e9989f0f481
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-mut.rs
@@ -0,0 +1,12 @@
+// Test mutability and slicing syntax.
+
+fn main() {
+    let x: &[isize] = &[1, 2, 3, 4, 5];
+    // Immutable slices are not mutable.
+
+    let y: &mut[_] = &x[2..4];
+    //~^ ERROR mismatched types
+    //~| expected mutable reference `&mut [_]`
+    //~| found reference `&[isize]`
+    //~| types differ in mutability
+}
diff --git a/src/test/ui/array-slice-vec/slice-mut.stderr b/src/test/ui/array-slice-vec/slice-mut.stderr
new file mode 100644
index 00000000000..7d34defc1d5
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-mut.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+  --> $DIR/slice-mut.rs:7:22
+   |
+LL |     let y: &mut[_] = &x[2..4];
+   |            -------   ^^^^^^^^ types differ in mutability
+   |            |
+   |            expected due to this
+   |
+   = note: expected mutable reference `&mut [_]`
+                      found reference `&[isize]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/array-slice-vec/slice-to-vec-comparison.rs b/src/test/ui/array-slice-vec/slice-to-vec-comparison.rs
new file mode 100644
index 00000000000..7026a49000c
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-to-vec-comparison.rs
@@ -0,0 +1,6 @@
+fn main() {
+    let a = &[];
+    let b: &Vec<u8> = &vec![];
+    a > b;
+    //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/array-slice-vec/slice-to-vec-comparison.stderr b/src/test/ui/array-slice-vec/slice-to-vec-comparison.stderr
new file mode 100644
index 00000000000..e3b3b040f66
--- /dev/null
+++ b/src/test/ui/array-slice-vec/slice-to-vec-comparison.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/slice-to-vec-comparison.rs:4:9
+   |
+LL |     a > b;
+   |         ^ expected array of 0 elements, found struct `Vec`
+   |
+   = note: expected reference `&[_; 0]`
+              found reference `&Vec<u8>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/array-slice-vec/vec-macro-with-comma-only.rs b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.rs
new file mode 100644
index 00000000000..574a53c58fe
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+    vec![,]; //~ ERROR no rules expected the token `,`
+}
diff --git a/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr
new file mode 100644
index 00000000000..abbee347c00
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr
@@ -0,0 +1,8 @@
+error: no rules expected the token `,`
+  --> $DIR/vec-macro-with-comma-only.rs:2:10
+   |
+LL |     vec![,];
+   |          ^ no rules expected this token in macro call
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/array-slice-vec/vec-mut-iter-borrow.rs b/src/test/ui/array-slice-vec/vec-mut-iter-borrow.rs
new file mode 100644
index 00000000000..4aa737446b5
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-mut-iter-borrow.rs
@@ -0,0 +1,7 @@
+fn main() {
+    let mut xs: Vec<isize> = vec![];
+
+    for x in &mut xs {
+        xs.push(1) //~ ERROR cannot borrow `xs`
+    }
+}
diff --git a/src/test/ui/array-slice-vec/vec-mut-iter-borrow.stderr b/src/test/ui/array-slice-vec/vec-mut-iter-borrow.stderr
new file mode 100644
index 00000000000..679fd899773
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-mut-iter-borrow.stderr
@@ -0,0 +1,14 @@
+error[E0499]: cannot borrow `xs` as mutable more than once at a time
+  --> $DIR/vec-mut-iter-borrow.rs:5:9
+   |
+LL |     for x in &mut xs {
+   |              -------
+   |              |
+   |              first mutable borrow occurs here
+   |              first borrow later used here
+LL |         xs.push(1)
+   |         ^^ second mutable borrow occurs here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0499`.
diff --git a/src/test/ui/array-slice-vec/vec-overrun.rs b/src/test/ui/array-slice-vec/vec-overrun.rs
new file mode 100644
index 00000000000..bdc7d507d53
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-overrun.rs
@@ -0,0 +1,12 @@
+// run-fail
+// error-pattern:index out of bounds: the len is 1 but the index is 2
+// ignore-emscripten no processes
+
+fn main() {
+    let v: Vec<isize> = vec![10];
+    let x: usize = 0;
+    assert_eq!(v[x], 10);
+    // Bounds-check panic.
+
+    assert_eq!(v[x + 2], 20);
+}
diff --git a/src/test/ui/array-slice-vec/vec-res-add.rs b/src/test/ui/array-slice-vec/vec-res-add.rs
new file mode 100644
index 00000000000..57b552ee558
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-res-add.rs
@@ -0,0 +1,19 @@
+#[derive(Debug)]
+struct R {
+  i:isize
+}
+
+fn r(i:isize) -> R { R { i: i } }
+
+impl Drop for R {
+    fn drop(&mut self) {}
+}
+
+fn main() {
+    // This can't make sense as it would copy the classes
+    let i = vec![r(0)];
+    let j = vec![r(1)];
+    let k = i + j;
+    //~^ ERROR cannot add `Vec<R>` to `Vec<R>`
+    println!("{:?}", j);
+}
diff --git a/src/test/ui/array-slice-vec/vec-res-add.stderr b/src/test/ui/array-slice-vec/vec-res-add.stderr
new file mode 100644
index 00000000000..7511271361d
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vec-res-add.stderr
@@ -0,0 +1,11 @@
+error[E0369]: cannot add `Vec<R>` to `Vec<R>`
+  --> $DIR/vec-res-add.rs:16:15
+   |
+LL |     let k = i + j;
+   |             - ^ - Vec<R>
+   |             |
+   |             Vec<R>
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.
diff --git a/src/test/ui/array-slice-vec/vector-cast-weirdness.rs b/src/test/ui/array-slice-vec/vector-cast-weirdness.rs
new file mode 100644
index 00000000000..79b9243765b
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vector-cast-weirdness.rs
@@ -0,0 +1,24 @@
+// Issue #14893. Tests that casts from vectors don't behave strangely in the
+// presence of the `_` type shorthand notation.
+// Update: after a change to the way casts are done, we have more type information
+// around and so the errors here are no longer exactly the same.
+
+struct X {
+    y: [u8; 2],
+}
+
+fn main() {
+    let x1 = X { y: [0, 0] };
+
+    // No longer a type mismatch - the `_` can be fully resolved by type inference.
+    let p1: *const u8 = &x1.y as *const _;
+    let t1: *const [u8; 2] = &x1.y as *const _;
+    let h1: *const [u8; 2] = &x1.y as *const [u8; 2];
+
+    let mut x1 = X { y: [0, 0] };
+
+    // This is still an error since we don't allow casts from &mut [T; n] to *mut T.
+    let p1: *mut u8 = &mut x1.y as *mut _;  //~ ERROR casting
+    let t1: *mut [u8; 2] = &mut x1.y as *mut _;
+    let h1: *mut [u8; 2] = &mut x1.y as *mut [u8; 2];
+}
diff --git a/src/test/ui/array-slice-vec/vector-cast-weirdness.stderr b/src/test/ui/array-slice-vec/vector-cast-weirdness.stderr
new file mode 100644
index 00000000000..37055bb75f5
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vector-cast-weirdness.stderr
@@ -0,0 +1,9 @@
+error[E0606]: casting `&mut [u8; 2]` as `*mut u8` is invalid
+  --> $DIR/vector-cast-weirdness.rs:21:23
+   |
+LL |     let p1: *mut u8 = &mut x1.y as *mut _;
+   |                       ^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0606`.
diff --git a/src/test/ui/array-slice-vec/vector-no-ann.rs b/src/test/ui/array-slice-vec/vector-no-ann.rs
new file mode 100644
index 00000000000..1f11d9c8dff
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vector-no-ann.rs
@@ -0,0 +1,4 @@
+fn main() {
+    let _foo = Vec::new();
+    //~^ ERROR type annotations needed
+}
diff --git a/src/test/ui/array-slice-vec/vector-no-ann.stderr b/src/test/ui/array-slice-vec/vector-no-ann.stderr
new file mode 100644
index 00000000000..8a7b8d22760
--- /dev/null
+++ b/src/test/ui/array-slice-vec/vector-no-ann.stderr
@@ -0,0 +1,11 @@
+error[E0282]: type annotations needed for `Vec<T>`
+  --> $DIR/vector-no-ann.rs:2:16
+   |
+LL |     let _foo = Vec::new();
+   |         ----   ^^^^^^^^ cannot infer type for type parameter `T`
+   |         |
+   |         consider giving `_foo` the explicit type `Vec<T>`, where the type parameter `T` is specified
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.