diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-10-28 07:06:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-28 07:06:42 +0200 |
| commit | 270e0c53574b938af0492b4321984d9a09ef5b47 (patch) | |
| tree | c383aa725ee76bd5f73072fe8c7e408643db3e6a /compiler/rustc_codegen_llvm/src | |
| parent | c404092084c518d126f77c1369ab63e340ce693e (diff) | |
| parent | 770538ef9b9a93038983ee5d82e07754c279df06 (diff) | |
| download | rust-270e0c53574b938af0492b4321984d9a09ef5b47.tar.gz rust-270e0c53574b938af0492b4321984d9a09ef5b47.zip | |
Rollup merge of #103283 - nbarrios1337:unsafe-impl-suggestions, r=cjgillot
Add suggestions for unsafe impl error codes
Adds suggestions for users to add `unsafe` to trait impls that should be `unsafe`, and remove `unsafe` from trait impls that do not require `unsafe`
With the folllowing code:
```rust
struct Foo {}
struct Bar {}
trait Safe {}
unsafe trait Unsafe {}
impl Safe for Foo {} // ok
impl Unsafe for Foo {} // E0200
unsafe impl Safe for Bar {} // E0199
unsafe impl Unsafe for Bar {} // ok
// omitted empty main fn
```
The current rustc output is:
```
error[E0199]: implementing the trait `Safe` is not unsafe
--> e0200.rs:13:1
|
13 | unsafe impl Safe for Bar {} // E0199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0200]: the trait `Unsafe` requires an `unsafe impl` declaration
--> e0200.rs:11:1
|
11 | impl Unsafe for Foo {} // E0200
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0199, E0200.
For more information about an error, try `rustc --explain E0199`.
```
With this PR, the future rustc output would be:
```
error[E0199]: implementing the trait `Safe` is not unsafe
--> ../../temp/e0200.rs:13:1
|
13 | unsafe impl Safe for Bar {} // E0199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove `unsafe` from this trait implementation
|
13 - unsafe impl Safe for Bar {} // E0199
13 + impl Safe for Bar {} // E0199
|
error[E0200]: the trait `Unsafe` requires an `unsafe impl` declaration
--> ../../temp/e0200.rs:11:1
|
11 | impl Unsafe for Foo {} // E0200
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: the trait `Unsafe` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword
help: add `unsafe` to this trait implementation
|
11 | unsafe impl Unsafe for Foo {} // E0200
| ++++++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0199, E0200.
For more information about an error, try `rustc --explain E0199`.
```
``@rustbot`` label +T-compiler +A-diagnostics +A-suggestion-diagnostics
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions
