From ed10a3faae1fd1176b2edf4a61438e0542c103b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 10 Oct 2018 17:30:10 -0700 Subject: [PATCH] Custom E0277 diagnostic for `Path` --- src/libcore/marker.rs | 1 + src/librustc/traits/error_reporting.rs | 3 +++ src/test/ui/error-codes/E0277.stderr | 2 +- src/test/ui/suggestions/path-by-value.rs | 6 ++++++ src/test/ui/suggestions/path-by-value.stderr | 15 +++++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/suggestions/path-by-value.rs create mode 100644 src/test/ui/suggestions/path-by-value.stderr diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 266c6913747f1..662a8ddd96862 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -92,6 +92,7 @@ impl !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 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 ab9020222ea2b..d0c089fa0f374 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 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 0000000000000..c875ca674aeb0 --- /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 0000000000000..338cfc990dcda --- /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 + = 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`.