Skip to content

Commit

Permalink
Rollup merge of rust-lang#62685 - nathanwhit:as_ref_suggest_fix, r=es…
Browse files Browse the repository at this point in the history
…tebank

Add info about undefined behavior to as_ref suggestions

Fixes rust-lang#61786. A very small fix, but suggestions on wording/content are welcomed.
  • Loading branch information
Mark-Simulacrum committed Jul 15, 2019
2 parents 83ead58 + c221e93 commit 40a7443
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 40a7443

Please sign in to comment.