summaryrefslogtreecommitdiffstats
path: root/src/test/ui/repeat-expr
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/repeat-expr
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/repeat-expr')
-rw-r--r--src/test/ui/repeat-expr/infer.rs16
-rw-r--r--src/test/ui/repeat-expr/repeat-expr-in-static.rs8
-rw-r--r--src/test/ui/repeat-expr/repeat-to-run-dtor-twice.rs19
-rw-r--r--src/test/ui/repeat-expr/repeat-to-run-dtor-twice.stderr15
-rw-r--r--src/test/ui/repeat-expr/repeat_count.rs34
-rw-r--r--src/test/ui/repeat-expr/repeat_count.stderr69
6 files changed, 161 insertions, 0 deletions
diff --git a/src/test/ui/repeat-expr/infer.rs b/src/test/ui/repeat-expr/infer.rs
new file mode 100644
index 000000000..8197713b9
--- /dev/null
+++ b/src/test/ui/repeat-expr/infer.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+#[derive(Clone, Default)]
+struct MaybeCopy<T>(T);
+
+impl Copy for MaybeCopy<u8> {}
+
+fn is_copy<T: Copy>(x: T) {
+ println!("{}", std::any::type_name::<T>());
+}
+
+fn main() {
+ is_copy(MaybeCopy::default());
+ [MaybeCopy::default(); 13];
+ // didn't work, because `Copy` was only checked in the mir
+}
diff --git a/src/test/ui/repeat-expr/repeat-expr-in-static.rs b/src/test/ui/repeat-expr/repeat-expr-in-static.rs
new file mode 100644
index 000000000..0b8953793
--- /dev/null
+++ b/src/test/ui/repeat-expr/repeat-expr-in-static.rs
@@ -0,0 +1,8 @@
+// run-pass
+
+static FOO: [isize; 4] = [32; 4];
+static BAR: [isize; 4] = [32, 32, 32, 32];
+
+pub fn main() {
+ assert_eq!(FOO, BAR);
+}
diff --git a/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.rs b/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.rs
new file mode 100644
index 000000000..0cd8eceef
--- /dev/null
+++ b/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.rs
@@ -0,0 +1,19 @@
+// Tests that one can't run a destructor twice with the repeated vector
+// literal syntax.
+
+struct Foo {
+ x: isize,
+
+}
+
+impl Drop for Foo {
+ fn drop(&mut self) {
+ println!("Goodbye!");
+ }
+}
+
+fn main() {
+ let a = Foo { x: 3 };
+ let _ = [ a; 5 ];
+ //~^ ERROR the trait bound `Foo: Copy` is not satisfied [E0277]
+}
diff --git a/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.stderr b/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.stderr
new file mode 100644
index 000000000..36b936163
--- /dev/null
+++ b/src/test/ui/repeat-expr/repeat-to-run-dtor-twice.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the trait bound `Foo: Copy` is not satisfied
+ --> $DIR/repeat-to-run-dtor-twice.rs:17:15
+ |
+LL | let _ = [ a; 5 ];
+ | ^ the trait `Copy` is not implemented for `Foo`
+ |
+ = note: the `Copy` trait is required because this value will be copied for each element of the array
+help: consider annotating `Foo` with `#[derive(Copy)]`
+ |
+LL | #[derive(Copy)]
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/repeat-expr/repeat_count.rs b/src/test/ui/repeat-expr/repeat_count.rs
new file mode 100644
index 000000000..96abff4ab
--- /dev/null
+++ b/src/test/ui/repeat-expr/repeat_count.rs
@@ -0,0 +1,34 @@
+// Regression test for issue #3645
+
+fn main() {
+ let n = 1;
+ let a = [0; n];
+ //~^ ERROR attempt to use a non-constant value in a constant [E0435]
+ let b = [0; ()];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `()`
+ let c = [0; true];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `bool`
+ let d = [0; 0.5];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found floating-point number
+ let e = [0; "foo"];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `&str`
+ let f = [0; -4_isize];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `isize`
+ let f = [0_usize; -1_isize];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `isize`
+ let f = [0; 4u8];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found `u8`
+ struct G {
+ g: (),
+ }
+ let g = [0; G { g: () }];
+ //~^ ERROR mismatched types
+ //~| expected `usize`, found struct `G`
+}
diff --git a/src/test/ui/repeat-expr/repeat_count.stderr b/src/test/ui/repeat-expr/repeat_count.stderr
new file mode 100644
index 000000000..e222c141f
--- /dev/null
+++ b/src/test/ui/repeat-expr/repeat_count.stderr
@@ -0,0 +1,69 @@
+error[E0435]: attempt to use a non-constant value in a constant
+ --> $DIR/repeat_count.rs:5:17
+ |
+LL | let n = 1;
+ | ----- help: consider using `const` instead of `let`: `const n`
+LL | let a = [0; n];
+ | ^ non-constant value
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:7:17
+ |
+LL | let b = [0; ()];
+ | ^^ expected `usize`, found `()`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:10:17
+ |
+LL | let c = [0; true];
+ | ^^^^ expected `usize`, found `bool`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:13:17
+ |
+LL | let d = [0; 0.5];
+ | ^^^ expected `usize`, found floating-point number
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:16:17
+ |
+LL | let e = [0; "foo"];
+ | ^^^^^ expected `usize`, found `&str`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:31:17
+ |
+LL | let g = [0; G { g: () }];
+ | ^^^^^^^^^^^ expected `usize`, found struct `G`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:19:17
+ |
+LL | let f = [0; -4_isize];
+ | ^^^^^^^^ expected `usize`, found `isize`
+ |
+ = note: `-4_isize` cannot fit into type `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:22:23
+ |
+LL | let f = [0_usize; -1_isize];
+ | ^^^^^^^^ expected `usize`, found `isize`
+ |
+ = note: `-1_isize` cannot fit into type `usize`
+
+error[E0308]: mismatched types
+ --> $DIR/repeat_count.rs:25:17
+ |
+LL | let f = [0; 4u8];
+ | ^^^ expected `usize`, found `u8`
+ |
+help: change the type of the numeric literal from `u8` to `usize`
+ |
+LL | let f = [0; 4usize];
+ | ~~~~~
+
+error: aborting due to 9 previous errors
+
+Some errors have detailed explanations: E0308, E0435.
+For more information about an error, try `rustc --explain E0308`.