Add info about undefined behavior to as_ref suggestions

This commit is contained in:
nathanwhit 2019-07-14 15:05:25 -04:00
parent d82fd9ecd3
commit c221e93fcd
2 changed files with 4 additions and 0 deletions

View file

@ -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
}

View file

@ -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`