Skip to content

Commit

Permalink
Add info about undefined behavior to as_ref suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Jul 15, 2019
1 parent d82fd9e commit c221e93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.note("try using `<*const T>::as_ref()` to get a reference to the \
type behind the pointer: https://doc.rust-lang.org/std/\
primitive.pointer.html#method.as_ref");
err.note("using `<*const T>::as_ref()` on a pointer \
which is unaligned or points to invalid \
or uninitialized memory is undefined behavior");
}
err
}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-21596.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | println!("{}", z.to_string());
| ^^^^^^^^^
|
= note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
= note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior
= note: the method `to_string` exists but the following trait bounds were not satisfied:
`*const u8 : std::string::ToString`

Expand Down

0 comments on commit c221e93

Please sign in to comment.