Skip to content

Commit 45088b1

Browse files
committed
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.
2 parents e7f5d48 + ed10a3f commit 45088b1

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

src/libcore/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl<T: ?Sized> !Send for *mut T { }
9292
#[stable(feature = "rust1", since = "1.0.0")]
9393
#[lang = "sized"]
9494
#[rustc_on_unimplemented(
95+
on(parent_trait="std::path::Path", label="borrow the `Path` instead"),
9596
message="the size for values of type `{Self}` cannot be known at compilation time",
9697
label="doesn't have a size known at compile-time",
9798
note="to learn more, visit <https://doc.rust-lang.org/book/second-edition/\

src/librustc/traits/error_reporting.rs

+3
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
378378
flags.push(("from_method".to_owned(), Some(method.to_string())));
379379
}
380380
}
381+
if let Some(t) = self.get_parent_trait_ref(&obligation.cause.code) {
382+
flags.push(("parent_trait".to_owned(), Some(t.to_string())));
383+
}
381384

382385
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
383386
flags.push(("from_desugaring".to_owned(), None));

src/test/ui/error-codes/E0277.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
22
--> $DIR/E0277.rs:23:6
33
|
44
LL | fn f(p: Path) { }
5-
| ^ doesn't have a size known at compile-time
5+
| ^ borrow the `Path` instead
66
|
77
= help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
88
= 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>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use std::path::Path;
2+
3+
fn f(p: Path) { }
4+
//~^ ERROR E0277
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/path-by-value.rs:3:6
3+
|
4+
LL | fn f(p: Path) { }
5+
| ^ borrow the `Path` instead
6+
|
7+
= help: within `std::path::Path`, the trait `std::marker::Sized` is not implemented for `[u8]`
8+
= 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>
9+
= note: required because it appears within the type `std::path::Path`
10+
= note: all local variables must have a statically known size
11+
= help: unsized locals are gated as an unstable feature
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)