rust/compiler
Jonas Schievink f02f7b05b2
Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank
Suggest to create a new `const` item if the `fn` in the array is a `const fn`

Fixes #73734. If the `fn` in the array repeat expression is a `const fn`, suggest creating a new `const` item. On nightly, suggest creating an inline `const` block. This PR also removes the `suggest_const_in_array_repeat_expressions` as it is no longer necessary.

Example:

```rust
fn main() {
    // Should not compile but hint to create a new const item (stable) or an inline const block (nightly)
    let strings: [String; 5] = [String::new(); 5];
    println!("{:?}", strings);
}

```

Gives this error:

```
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
 --> $DIR/const-fn-in-vec.rs:3:32
  |
2 |     let strings: [String; 5] = [String::new(); 5];
  |                             ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `String`
  |
  = note: the `Copy` trait is required because the repeated element will be copied
```

With this change, this is the error message:

```
error[E0277]: the trait bound `String: Copy` is not satisfied
  --> $DIR/const-fn-in-vec.rs:3:32
   |
LL |     let strings: [String; 5] = [String::new(); 5];
   |                                ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
   |
   = help: moving the function call to a new `const` item will resolve the error
```
2021-02-15 16:06:47 +01:00
..
rustc
rustc_apfloat bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_arena bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_ast Auto merge of #82103 - Dylan-DPC:rollup-5wv8rid, r=Dylan-DPC 2021-02-14 22:26:21 +00:00
rustc_ast_lowering bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_ast_passes Auto merge of #81346 - hug-dev:nonsecure-call-abi, r=jonas-schievink 2021-02-03 06:00:43 +00:00
rustc_ast_pretty Fix pretty printer macro_rules with semicolon. 2021-02-08 12:08:27 -08:00
rustc_attr Never MIR inline functions with a different instruction set 2021-02-05 00:00:00 +00:00
rustc_builtin_macros bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_codegen_cranelift Add a new ABI to support cmse_nonsecure_call 2021-02-02 13:04:31 +00:00
rustc_codegen_llvm bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_codegen_ssa HWASan support 2021-02-07 23:48:58 -08:00
rustc_data_structures bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_driver
rustc_error_codes Improve long explanation for E0542 and E0546 2021-02-11 16:26:07 +01:00
rustc_errors Make sure all fields are accounted for in encode_fields! 2021-02-07 14:54:22 -08:00
rustc_expand bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_feature Feature gate macro attributes in #[derive] output 2021-02-07 20:08:45 +03:00
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #81720 - klensy:smallvec-update, r=Mark-Simulacrum 2021-02-14 16:54:44 +01:00
rustc_hir_pretty hir pretty printing 2021-02-04 16:20:57 +01:00
rustc_incremental
rustc_index Auto merge of #81498 - thomaseizinger:ice-workaround-56935-rustc-index, r=matthewjasper 2021-02-07 08:09:58 +00:00
rustc_infer bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_interface bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_lexer
rustc_lint Auto merge of #79804 - tmiasko:improper-ctypes-no-niche, r=pnkfelix 2021-02-10 12:56:09 +00:00
rustc_lint_defs Add --extern-loc to augment unused crate dependency diagnostics 2021-02-07 14:54:20 -08:00
rustc_llvm HWASan support 2021-02-07 23:48:58 -08:00
rustc_macros Switch query descriptions to just String 2021-02-08 17:20:41 -05:00
rustc_metadata bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_middle Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank 2021-02-15 16:06:47 +01:00
rustc_mir Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank 2021-02-15 16:06:47 +01:00
rustc_mir_build Rollup merge of #82029 - tmiasko:debug, r=matthewjasper 2021-02-14 16:54:52 +01:00
rustc_parse Auto merge of #82103 - Dylan-DPC:rollup-5wv8rid, r=Dylan-DPC 2021-02-14 22:26:21 +00:00
rustc_parse_format parse_format: treat r" as a literal 2021-02-06 15:01:07 +00:00
rustc_passes Rollup merge of #80920 - rylev:check_attr-refactor, r=davidtwco 2021-02-14 16:54:42 +01:00
rustc_plugin_impl
rustc_privacy more things are const evaluatable *sparkles* 2021-02-01 20:05:50 +00:00
rustc_query_system bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_resolve bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_save_analysis
rustc_serialize bumped smallvec deps 2021-02-14 18:03:11 +03:00
rustc_session HWASan support 2021-02-07 23:48:58 -08:00
rustc_span Rollup merge of #82029 - tmiasko:debug, r=matthewjasper 2021-02-14 16:54:52 +01:00
rustc_symbol_mangling
rustc_target Stack probes: fix error message 2021-02-11 20:33:16 +01:00
rustc_trait_selection Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank 2021-02-15 16:06:47 +01:00
rustc_traits Rollup merge of #82029 - tmiasko:debug, r=matthewjasper 2021-02-14 16:54:52 +01:00
rustc_ty_utils
rustc_type_ir
rustc_typeck Rollup merge of #81914 - kper:fixing-81885, r=estebank 2021-02-14 16:54:47 +01:00