diff options
| author | Boxy <rust@boxyuwu.dev> | 2025-05-26 16:35:36 +0100 |
|---|---|---|
| committer | Boxy <rust@boxyuwu.dev> | 2025-05-26 16:35:36 +0100 |
| commit | c27aff35caad45093b52988994c2bc9b5631b544 (patch) | |
| tree | efb75af8ebaed2ca411e8b150e0aa16806224f08 | |
| parent | b5eb9893f42a469d330046089539f908d4728384 (diff) | |
| download | rust-c27aff35caad45093b52988994c2bc9b5631b544.tar.gz rust-c27aff35caad45093b52988994c2bc9b5631b544.zip | |
Add test
| -rw-r--r-- | tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs | 11 | ||||
| -rw-r--r-- | tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs new file mode 100644 index 00000000000..b9d123cbefa --- /dev/null +++ b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs @@ -0,0 +1,11 @@ +#![feature(generic_arg_infer)] + +// Test that we enforce repeat expr element types are `Copy` even +// when the repeat count is only inferred at a later point in type +// checking. + +fn main() { + let a = [String::new(); _]; + //~^ ERROR: the trait bound `String: Copy` is not satisfied + let b: [_; 2] = a; +} diff --git a/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr new file mode 100644 index 00000000000..d974f5add50 --- /dev/null +++ b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/copy-check-when-count-inferred-later.rs:8:14 + | +LL | let a = [String::new(); _]; + | ^^^^^^^^^^^^^ + | | + | the trait `Copy` is not implemented for `String` + | help: create an inline `const` block: `const { String::new() }` + | + = note: the `Copy` trait is required because this value will be copied for each element of the array + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. |
