rust/compiler/rustc_mir/src/transform
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
..
check_consts Auto merge of #81350 - tmiasko:instrument-debug, r=lcnr 2021-02-11 13:44:00 +00:00
coverage Fix typo in counters.rs 2021-01-19 23:42:18 +09:00
inline Use debug log level for developer oriented logs 2021-02-13 00:00:00 +00:00
add_call_guards.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
add_moves_for_packed_drops.rs Replace (Body, DefId) with Body where possible 2020-10-04 16:07:03 -07:00
add_retag.rs Retagging: do not retag 'raw reborrows' 2020-10-31 15:31:27 +01:00
check_const_item_mutation.rs Suppress CONST_ITEM_MUTATION lint if a dereference occurs anywhere 2020-12-17 15:25:55 -05:00
check_packed_ref.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
check_unsafety.rs Auto merge of #81110 - LeSeulArtichaut:fix-unused-unsafe-label, r=RalfJung 2021-01-19 08:59:37 +00:00
cleanup_post_borrowck.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
const_debuginfo.rs Disable the constant debuginfo promotion pass by default 2020-12-14 19:56:10 -05:00
const_prop.rs Make sure that const prop does not produce unsilenceable lints after inlining 2021-01-23 16:51:23 +00:00
deaggregator.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
dest_prop.rs Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
dump_mir.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
early_otherwise_branch.rs Rollup merge of #79882 - wecing:master, r=oli-obk 2020-12-17 11:43:59 +09:00
elaborate_drops.rs Replace (Body, DefId) with Body where possible 2020-10-04 16:07:03 -07:00
function_item_references.rs Review changes 2021-01-16 18:56:37 -05:00
generator.rs compiler: fold by value 2020-11-16 22:34:57 +01:00
inline.rs Use debug log level for developer oriented logs 2021-02-13 00:00:00 +00:00
instcombine.rs Combine instructions immediately 2021-01-18 13:15:27 +01:00
lower_intrinsics.rs Lower discriminant_value intrinsic 2020-12-11 03:25:40 +01:00
match_branches.rs Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
mod.rs Leave some notes for future changes to the MIR opt level of mir inlining 2021-01-23 16:51:23 +00:00
multiple_return_terminators.rs Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
no_landing_pads.rs Visit only terminators when removing landing pads 2021-01-18 00:00:00 +00:00
nrvo.rs Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
promote_consts.rs added a suggestion to create a const item if the fn in the array repeat expression is a const fn 2021-02-03 10:18:08 +05:30
remove_noop_landing_pads.rs Recognize discriminant reads as no-ops in RemoveNoopLandingPads 2020-10-10 00:00:00 +00:00
remove_unneeded_drops.rs Visit only terminators when removing unneeded drops 2021-01-17 00:00:00 +00:00
required_consts.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
rustc_peek.rs Remove compile-fail test suite 2020-12-29 23:39:56 +03:00
simplify.rs Avoid memory allocation when removing dead blocks 2021-01-28 00:00:00 +00:00
simplify_branches.rs Simplify assert terminator only if condition evaluates to expected value 2020-10-21 00:00:00 +00:00
simplify_comparison_integral.rs s/Scalar::Raw/Scalar::Int 2020-11-04 10:11:31 +00:00
simplify_try.rs Use Option::map_or instead of .map(..).unwrap_or(..) 2021-01-14 19:23:59 +01:00
uninhabited_enum_branching.rs Refactor how SwitchInt stores jump targets 2020-10-10 17:46:11 +02:00
unreachable_prop.rs Convenience funcs for some_option.unwrap_or(...) 2020-12-14 17:27:27 -08:00
validate.rs Rollup merge of #79080 - camelid:mir-visit-debuginfo-project, r=jonas-schievink 2020-11-23 15:25:40 +01:00