Skip to content
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

Documented syntax for core::env is wrong #82117

Closed
lukaslueg opened this issue Feb 14, 2021 · 1 comment · Fixed by #82118
Closed

Documented syntax for core::env is wrong #82117

lukaslueg opened this issue Feb 14, 2021 · 1 comment · Fixed by #82118
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@lukaslueg
Copy link
Contributor

The documentation for the compiler-built-in macro core::env / std::env currently reads:

macro_rules! env {
    ($name:expr $(,)?) => { ... };
}

The text and example state that a second parameter can be given to customize the error message in case the environment variable is not defined. This second parameter is not reflected in the syntax above. The following is valid:

fn main() {
    let x: &'static str = env!("CARGO_MANIFEST_DIR", "oh no!");  // this should not match `$(name:expr $(,)?)`
}

Looking at the implementation, the syntax should most likely be documented as

macro_rules! env {
    ($name:expr) => { ... };
    ($name:expr, $error:expr) => { ... };
}

Am I missing something? I can commit a PR if so desired.

@lukaslueg lukaslueg added the C-bug Category: This is a bug. label Feb 14, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 14, 2021

@lukaslueg I think you're right; probably the compiler should be checking that the declared macro and the built-in macro accept the same syntax, although that could be hard to enforce. Changing the declared macro seems like a good first step :)

@jyn514 jyn514 added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 14, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 15, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 15, 2021
@bors bors closed this as completed in dee5424 Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants