about summary refs log tree commit diff
path: root/library/std/src/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2021-02-15 16:06:47 +0100
committerGitHub <noreply@github.com>2021-02-15 16:06:47 +0100
commitf02f7b05b24543f0928f34c75aad2465e20094ca (patch)
tree4780cf8493f1d6a3c5f22c2af793a7f54ed8e860 /library/std/src/sys/unix/stack_overflow.rs
parent9503ea19edbf01b9435e80e17d60ce1b88390116 (diff)
parent64fe2c183d722ef3d2e9dee312de4b98aa6af9a0 (diff)
downloadrust-f02f7b05b24543f0928f34c75aad2465e20094ca.tar.gz
rust-f02f7b05b24543f0928f34c75aad2465e20094ca.zip
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
```
Diffstat (limited to 'library/std/src/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions