about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-10-10 17:30:10 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-10-10 17:30:10 -0700
commited10a3faae1fd1176b2edf4a61438e0542c103b9 (patch)
tree534e54fe4797809c901c165e2cd7009a9040b8a8 /src
parente1041c6cd1a027ab3ada3e8538620d2e1d7067fe (diff)
downloadrust-ed10a3faae1fd1176b2edf4a61438e0542c103b9.tar.gz
rust-ed10a3faae1fd1176b2edf4a61438e0542c103b9.zip
Custom E0277 diagnostic for `Path`
Diffstat (limited to 'src')
-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 da2173fead3..39dc84a6b70 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -379,6 +379,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`.