about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-10-18 21:42:21 +0000
committerbors <bors@rust-lang.org>2018-10-18 21:42:21 +0000
commit45088b11f55e57a65fa1ebcf6e3b6014152eb516 (patch)
treee3b30d5b617dbbe7166549db8d8ba962d6a8b32c
parente7f5d48059aa14cc2808473564deadd72d1e818d (diff)
parented10a3faae1fd1176b2edf4a61438e0542c103b9 (diff)
downloadrust-45088b11f55e57a65fa1ebcf6e3b6014152eb516.tar.gz
rust-45088b11f55e57a65fa1ebcf6e3b6014152eb516.zip
Auto merge of #54979 - estebank:path-unsized, r=nikomatsakis
Custom E0277 diagnostic for `Path`

r? @nikomatsakis we have a way to target `Path` exclusively, we need to identify the correct text to show to consider #23286 fixed.
-rw-r--r--src/libcore/marker.rs1
-rw-r--r--src/librustc/traits/error_reporting.rs3
-rw-r--r--src/test/ui/error-codes/E0277.stderr2
-rw-r--r--src/test/ui/suggestions/path-by-value.rs6
-rw-r--r--src/test/ui/suggestions/path-by-value.stderr15
5 files changed, 26 insertions, 1 deletions
diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs
index 266c6913747..662a8ddd968 100644
--- a/src/libcore/marker.rs
+++ b/src/libcore/marker.rs
@@ -92,6 +92,7 @@ impl<T: ?Sized> !Send for *mut T { }
 #[stable(feature = "rust1", since = "1.0.0")]
 #[lang = "sized"]
 #[rustc_on_unimplemented(
+    on(parent_trait="std::path::Path", label="borrow the `Path` instead"),
     message="the size for values of type `{Self}` cannot be known at compilation time",
     label="doesn't have a size known at compile-time",
     note="to learn more, visit <https://doc.rust-lang.org/book/second-edition/\
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index fc34a71f392..db775beae4f 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -378,6 +378,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
                 flags.push(("from_method".to_owned(), Some(method.to_string())));
             }
         }
+        if let Some(t) = self.get_parent_trait_ref(&obligation.cause.code) {
+            flags.push(("parent_trait".to_owned(), Some(t.to_string())));
+        }
 
         if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
             flags.push(("from_desugaring".to_owned(), None));
diff --git a/src/test/ui/error-codes/E0277.stderr b/src/test/ui/error-codes/E0277.stderr
index ab9020222ea..d0c089fa0f3 100644
--- a/src/test/ui/error-codes/E0277.stderr
+++ b/src/test/ui/error-codes/E0277.stderr
@@ -2,7 +2,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
   --> $DIR/E0277.rs:23:6
    |
 LL | fn f(p: Path) { }
-   |      ^ doesn't have a size known at compile-time
+   |      ^ borrow the `Path` instead
    |
    = help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
    = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
diff --git a/src/test/ui/suggestions/path-by-value.rs b/src/test/ui/suggestions/path-by-value.rs
new file mode 100644
index 00000000000..c875ca674ae
--- /dev/null
+++ b/src/test/ui/suggestions/path-by-value.rs
@@ -0,0 +1,6 @@
+use std::path::Path;
+
+fn f(p: Path) { }
+//~^ ERROR E0277
+
+fn main() {}
diff --git a/src/test/ui/suggestions/path-by-value.stderr b/src/test/ui/suggestions/path-by-value.stderr
new file mode 100644
index 00000000000..338cfc990dc
--- /dev/null
+++ b/src/test/ui/suggestions/path-by-value.stderr
@@ -0,0 +1,15 @@
+error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
+  --> $DIR/path-by-value.rs:3:6
+   |
+LL | fn f(p: Path) { }
+   |      ^ borrow the `Path` instead
+   |
+   = help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: required because it appears within the type `std::path::Path`
+   = note: all local variables must have a statically known size
+   = help: unsized locals are gated as an unstable feature
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.