about summary refs log tree commit diff
diff options
context:
space:
mode:
authornathanwhit <nathan.whitaker01@gmail.com>2019-07-14 15:05:25 -0400
committernathanwhit <nathan.whitaker01@gmail.com>2019-07-14 23:05:03 -0400
commitc221e93fcd967fc93323e7efe094a7471a043a7d (patch)
treea60ae5e2fbe11deef86a0a49143ef05ca7f3704c
parentd82fd9ecd3e65a313b0e0bdd24de127d4b566156 (diff)
downloadrust-c221e93fcd967fc93323e7efe094a7471a043a7d.tar.gz
rust-c221e93fcd967fc93323e7efe094a7471a043a7d.zip
Add info about undefined behavior to as_ref suggestions
-rw-r--r--src/librustc_typeck/check/method/suggest.rs3
-rw-r--r--src/test/ui/issues/issue-21596.stderr1
2 files changed, 4 insertions, 0 deletions
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 8dcfa184d7d..5febc694def 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -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
                     }
diff --git a/src/test/ui/issues/issue-21596.stderr b/src/test/ui/issues/issue-21596.stderr
index 07d29f30e98..8e4e09b13a9 100644
--- a/src/test/ui/issues/issue-21596.stderr
+++ b/src/test/ui/issues/issue-21596.stderr
@@ -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`