-
Notifications
You must be signed in to change notification settings - Fork 14k
Add typo suggestion for a misspelt Cargo environment variable #148559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+170
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
chenyukang marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 @@ | ||
| //@ edition: 2021 | ||
|
|
||
| // Regression test for issue #148439 | ||
| // Ensure that when using misspelled Cargo environment variables in env!(), | ||
|
|
||
| fn test_cargo_package_version() { | ||
| let _ = env!("CARGO_PACKAGE_VERSION"); | ||
| //~^ ERROR environment variable `CARGO_PACKAGE_VERSION` not defined at compile time | ||
| //~| HELP there is a similar Cargo environment variable: `CARGO_PKG_VERSION` | ||
| } | ||
|
|
||
| fn test_cargo_package_name() { | ||
| let _ = env!("CARGO_PACKAGE_NAME"); | ||
| //~^ ERROR environment variable `CARGO_PACKAGE_NAME` not defined at compile time | ||
| //~| HELP there is a similar Cargo environment variable: `CARGO_PKG_NAME` | ||
| } | ||
|
|
||
| fn test_cargo_package_authors() { | ||
| let _ = env!("CARGO_PACKAGE_AUTHORS"); | ||
| //~^ ERROR environment variable `CARGO_PACKAGE_AUTHORS` not defined at compile time | ||
| //~| HELP there is a similar Cargo environment variable: `CARGO_PKG_AUTHORS` | ||
| } | ||
|
|
||
| fn test_cargo_manifest_directory() { | ||
| let _ = env!("CARGO_MANIFEST_DIRECTORY"); | ||
| //~^ ERROR environment variable `CARGO_MANIFEST_DIRECTORY` not defined at compile time | ||
| //~| HELP there is a similar Cargo environment variable: `CARGO_MANIFEST_DIR` | ||
| } | ||
|
|
||
| fn test_cargo_pkg_version_typo() { | ||
| let _ = env!("CARGO_PKG_VERSIO"); | ||
| //~^ ERROR environment variable `CARGO_PKG_VERSIO` not defined at compile time | ||
| //~| HELP there is a similar Cargo environment variable: `CARGO_PKG_VERSION` | ||
| } | ||
|
|
||
| fn test_non_cargo_var() { | ||
| // Non-Cargo variable should get different help message | ||
| let _ = env!("MY_CUSTOM_VAR"); | ||
| //~^ ERROR environment variable `MY_CUSTOM_VAR` not defined at compile time | ||
| //~| HELP use `std::env::var("MY_CUSTOM_VAR")` to read the variable at run time | ||
| } | ||
|
|
||
| fn test_cargo_unknown_var() { | ||
| // Cargo-prefixed but not similar to any known variable | ||
| let _ = env!("CARGO_SOMETHING_TOTALLY_UNKNOWN"); | ||
| //~^ ERROR environment variable `CARGO_SOMETHING_TOTALLY_UNKNOWN` not defined at compile time | ||
| //~| HELP Cargo sets build script variables at run time. Use `std::env::var("CARGO_SOMETHING_TOTALLY_UNKNOWN")` instead | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or 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,58 @@ | ||
| error: environment variable `CARGO_PACKAGE_VERSION` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:7:13 | ||
| | | ||
| LL | let _ = env!("CARGO_PACKAGE_VERSION"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: there is a similar Cargo environment variable: `CARGO_PKG_VERSION` | ||
|
|
||
| error: environment variable `CARGO_PACKAGE_NAME` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:13:13 | ||
| | | ||
| LL | let _ = env!("CARGO_PACKAGE_NAME"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: there is a similar Cargo environment variable: `CARGO_PKG_NAME` | ||
|
|
||
| error: environment variable `CARGO_PACKAGE_AUTHORS` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:19:13 | ||
| | | ||
| LL | let _ = env!("CARGO_PACKAGE_AUTHORS"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: there is a similar Cargo environment variable: `CARGO_PKG_AUTHORS` | ||
|
|
||
| error: environment variable `CARGO_MANIFEST_DIRECTORY` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:25:13 | ||
| | | ||
| LL | let _ = env!("CARGO_MANIFEST_DIRECTORY"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: there is a similar Cargo environment variable: `CARGO_MANIFEST_DIR` | ||
|
|
||
| error: environment variable `CARGO_PKG_VERSIO` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:31:13 | ||
| | | ||
| LL | let _ = env!("CARGO_PKG_VERSIO"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: there is a similar Cargo environment variable: `CARGO_PKG_VERSION` | ||
|
|
||
| error: environment variable `MY_CUSTOM_VAR` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:38:13 | ||
| | | ||
| LL | let _ = env!("MY_CUSTOM_VAR"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: use `std::env::var("MY_CUSTOM_VAR")` to read the variable at run time | ||
|
|
||
| error: environment variable `CARGO_SOMETHING_TOTALLY_UNKNOWN` not defined at compile time | ||
| --> $DIR/env-cargo-var-typo-issue-148439.rs:45:13 | ||
| | | ||
| LL | let _ = env!("CARGO_SOMETHING_TOTALLY_UNKNOWN"); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: Cargo sets build script variables at run time. Use `std::env::var("CARGO_SOMETHING_TOTALLY_UNKNOWN")` instead | ||
|
|
||
| error: aborting due to 7 previous errors | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion (non-blocking): I have two reservations about making this suggestion:
rustcshould not make assumptions aboutcargo(that is,rustcshould not "know" aboutcargo's existence), becausecargoisn't the only way to invokerustc.I guess I could be convinced by "well, most users do build with
cargo", so don't consider this a hard-blocking concern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-analyzer: https://github.com/chenyukang/rust/blob/702bf000a0b5062d8b5ced717a26d70919df6ba0/src/tools/rust-analyzer/crates/project-model/src/env.rs#L9-L49 , I guess there is a better and general way to keep it synced.rustcshould not knowing details about cargo, I think it's ok since we need to check the prefix withCARGO_of env:https://github.com/rust-lang/rust/pull/148559/files#diff-0eaa1095d59f2f3d9c015005d15fd8f7cda13121a8404d77b2955fc5fcd40449R213, and it's a note but not code suggestions, it's maybe incorrect for rare scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems alright, was just curious to hear what you think.