Skip to content

Commit

Permalink
Custom E0277 diagnostic for Path
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 11, 2018
1 parent e1041c6 commit ed10a3f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/\
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0277.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/suggestions/path-by-value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::path::Path;

fn f(p: Path) { }
//~^ ERROR E0277

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/suggestions/path-by-value.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit ed10a3f

Please sign in to comment.