-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trait object reborrow suggestion
- Loading branch information
1 parent
611e7b9
commit a336686
Showing
6 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::ffi::{OsStr, OsString}; | ||
use std::path::Path; | ||
|
||
fn check(p: &dyn AsRef<Path>) { | ||
let m = std::fs::metadata(&p); | ||
println!("{:?}", &m); | ||
} | ||
|
||
fn main() { | ||
let s: OsString = ".".into(); | ||
let s: &OsStr = &s; | ||
check(s); | ||
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time | ||
//~| HELP within `OsStr`, the trait `Sized` is not implemented for `[u8]` | ||
//~| HELP consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef<Path>` | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/suggestions/suggest-borrow-to-dyn-object.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
--> $DIR/suggest-borrow-to-dyn-object.rs:12:11 | ||
| | ||
LL | check(s); | ||
| ----- ^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: within `OsStr`, the trait `Sized` is not implemented for `[u8]` | ||
= note: required because it appears within the type `OsStr` | ||
= note: required for the cast to the object type `dyn AsRef<Path>` | ||
help: consider borrowing the value, since `&OsStr` can be coerced into `dyn AsRef<Path>` | ||
| | ||
LL | check(&s); | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |