-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #121833 - kornelski:parent_include, r=estebank
Suggest correct path in include_bytes! `include_bytes!` paths are relative, and I'm often not sure how nested is the `.rs` file that I'm editing, so I have to guess the number of `"../.."`. This change searches `..` and `../..` for the given file and offers corrected path as a suggestion. I wasn't sure how to get the right span, and how to properly escape it. ```text error: couldn't read src/file.txt: No such file or directory (os error 2) --> src/main.rs:2:13 | 2 | let x = include_bytes!("file.txt"); | ^^^^^^^^^^^^^^^----------^ | | | help: it's in a parent directory: `"../../file.txt"` ```
- Loading branch information
Showing
7 changed files
with
229 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//@ normalize-stderr-test: "`: .*" -> "`: $$FILE_NOT_FOUND_MSG" | ||
|
||
fn main() { | ||
let _ = include_str!("include-macros/file.txt"); //~ ERROR couldn't read | ||
//~^HELP different directory | ||
let _ = include_str!("hello.rs"); //~ ERROR couldn't read | ||
//~^HELP different directory | ||
let _ = include_bytes!("../../data.bin"); //~ ERROR couldn't read | ||
//~^HELP different directory | ||
let _ = include_str!("tests/ui/include-macros/file.txt"); //~ ERROR couldn't read | ||
//~^HELP different directory | ||
} |
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,50 @@ | ||
error: couldn't read `$DIR/include-macros/file.txt`: $FILE_NOT_FOUND_MSG | ||
--> $DIR/parent_dir.rs:4:13 | ||
| | ||
LL | let _ = include_str!("include-macros/file.txt"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: there is a file with the same name in a different directory | ||
| | ||
LL | let _ = include_str!("file.txt"); | ||
| ~~~~~~~~~~ | ||
|
||
error: couldn't read `$DIR/hello.rs`: $FILE_NOT_FOUND_MSG | ||
--> $DIR/parent_dir.rs:6:13 | ||
| | ||
LL | let _ = include_str!("hello.rs"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: there is a file with the same name in a different directory | ||
| | ||
LL | let _ = include_str!("../hello.rs"); | ||
| ~~~~~~~~~~~~~ | ||
|
||
error: couldn't read `$DIR/../../data.bin`: $FILE_NOT_FOUND_MSG | ||
--> $DIR/parent_dir.rs:8:13 | ||
| | ||
LL | let _ = include_bytes!("../../data.bin"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: there is a file with the same name in a different directory | ||
| | ||
LL | let _ = include_bytes!("data.bin"); | ||
| ~~~~~~~~~~ | ||
|
||
error: couldn't read `$DIR/tests/ui/include-macros/file.txt`: $FILE_NOT_FOUND_MSG | ||
--> $DIR/parent_dir.rs:10:13 | ||
| | ||
LL | let _ = include_str!("tests/ui/include-macros/file.txt"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: there is a file with the same name in a different directory | ||
| | ||
LL | let _ = include_str!("file.txt"); | ||
| ~~~~~~~~~~ | ||
|
||
error: aborting due to 4 previous errors | ||
|
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