]> git.lizzy.rs Git - rust.git/commitdiff
Custom E0277 diagnostic for `Path`
authorEsteban Küber <esteban@kuber.com.ar>
Thu, 11 Oct 2018 00:30:10 +0000 (17:30 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 11 Oct 2018 00:30:10 +0000 (17:30 -0700)
src/libcore/marker.rs
src/librustc/traits/error_reporting.rs
src/test/ui/error-codes/E0277.stderr
src/test/ui/suggestions/path-by-value.rs [new file with mode: 0644]
src/test/ui/suggestions/path-by-value.stderr [new file with mode: 0644]

index 266c6913747f123544e31909c81a06e106b428b4..662a8ddd96862d0e70bca2281b8cccc7e207c568 100644 (file)
@@ -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/\
index da2173fead3707d1e34a5e2b3cb0bf9dffbb1b59..39dc84a6b709098276734c30be2674b2669f35ce 100644 (file)
@@ -379,6 +379,9 @@ fn on_unimplemented_note(
                 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));
index ab9020222ea2b4f7b7e149a1618b5b3f25ca4786..d0c089fa0f37428c7a8cd79b9a5b81ac01cd50fb 100644 (file)
@@ -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 (file)
index 0000000..c875ca6
--- /dev/null
@@ -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 (file)
index 0000000..338cfc9
--- /dev/null
@@ -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`.