Rollup merge of #52207 - RalfJung:unsafety-errors, r=estebank

improve error message shown for unsafe operations

Add a short explanation saying why undefined behavior could arise. In particular, the error many people got for "creating a pointer to a packed field requires unsafe block" was not worded great -- it lead to people just adding the unsafe block without considering if what they are doing follows the rules.

I am not sure if a "note" is the right thing, but that was the easiest thing to add...

Inspired by @gnzlbg at https://github.com/rust-lang/rust/issues/46043#issuecomment-381544673
This commit is contained in:
Mark Rousskov 2018-07-11 12:38:36 -06:00 committed by GitHub
commit 7897ee4d42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 114 additions and 50 deletions

View file

@ -1,8 +1,10 @@
error[E0133]: call to unsafe function requires unsafe function or block
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/E0133.rs:14:5
|
LL | f();
| ^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to previous error