Skip to content

Documented syntax for core::env is wrong #82117

Closed
@lukaslueg

Description

@lukaslueg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions