summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2019-10-26 23:59:24 +0100
committerDavid Wood <david@davidtw.co>2019-10-28 18:37:49 +0000
commit92b151287fcda73db8e95eeca8be97d66905626d (patch)
tree6d5755c6e0e889c27150d38fa9c83ae6d65760fd /src/test
parent03a50ae9b87021d4a166c70d2c932f1cb0aa8f28 (diff)
downloadrust-92b151287fcda73db8e95eeca8be97d66905626d.tar.gz
rust-92b151287fcda73db8e95eeca8be97d66905626d.zip
suggest `const_in_array_repeat_expression` flag
This commit adds a suggestion to add the
`#![feature(const_in_array_repeat_expression)]` attribute to the crate
when a promotable expression is used in a repeat expression.

Signed-off-by: David Wood <david@davidtw.co>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.rs7
-rw-r--r--src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr16
2 files changed, 21 insertions, 2 deletions
diff --git a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.rs b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.rs
index be195271c10..c3c554d7d27 100644
--- a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.rs
+++ b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.rs
@@ -3,9 +3,16 @@
 
 struct Bar;
 
+// This function would compile with the feature gate, and tests that it is suggested.
 fn foo() {
     let arr: [Option<String>; 2] = [None::<String>; 2];
     //~^ ERROR the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied [E0277]
 }
 
+// This function would not compile with the feature gate, and tests that it is not suggested.
+fn bar() {
+    let arr: [Option<String>; 2] = [Some("foo".to_string()); 2];
+    //~^ ERROR the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied [E0277]
+}
+
 fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr
index eed69a0c28d..cd9242de88f 100644
--- a/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr
+++ b/src/test/ui/feature-gates/feature-gate-const_in_array_repeat_expressions.stderr
@@ -1,5 +1,5 @@
 error[E0277]: the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied
-  --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:7:36
+  --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:8:36
    |
 LL |     let arr: [Option<String>; 2] = [None::<String>; 2];
    |                                    ^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<std::string::String>`
@@ -7,7 +7,19 @@ LL |     let arr: [Option<String>; 2] = [None::<String>; 2];
    = help: the following implementations were found:
              <std::option::Option<T> as std::marker::Copy>
    = note: the `Copy` trait is required because the repeated element will be copied
+   = note: this array initializer can be evaluated at compile-time, for more information, see issue https://github.com/rust-lang/rust/issues/49147
+   = help: add `#![feature(const_in_array_repeat_expression)]` to the crate attributes to enable
 
-error: aborting due to previous error
+error[E0277]: the trait bound `std::option::Option<std::string::String>: std::marker::Copy` is not satisfied
+  --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:14:36
+   |
+LL |     let arr: [Option<String>; 2] = [Some("foo".to_string()); 2];
+   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<std::string::String>`
+   |
+   = help: the following implementations were found:
+             <std::option::Option<T> as std::marker::Copy>
+   = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0277`.