1
Fork 0
rust/compiler/rustc_mir/src
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
..
borrow_check Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank 2021-02-15 16:06:47 +01:00
const_eval improve error message for disallowed ptr-to-int casts in const eval 2021-02-05 00:52:19 -08:00
dataflow Remove RCs from Borrows 2021-02-08 20:37:16 +01:00
interpret Auto merge of #81350 - tmiasko:instrument-debug, r=lcnr 2021-02-11 13:44:00 +00:00
monomorphize Rollup merge of #80944 - LingMan:map_or, r=nagisa 2021-01-15 18:26:14 +09:00
transform Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebank 2021-02-15 16:06:47 +01:00
util Fix MIR pretty printer for non-local DefIds 2021-02-13 20:23:27 +03:00
lib.rs Prevent query cycles during inlining 2021-01-23 16:51:22 +00:00
shim.rs Replace let Some(..) = with .is_some() 2021-01-17 19:06:12 -05:00