Skip to content

Incorrect description of std::prelude name resolution in standard library docs #64686

Closed
@mattheww

Description

@mattheww

The documentation for std::prelude states:

On a technical level, Rust inserts

extern crate std;

into the crate root of every crate, and

use std::prelude::v1::*;

into every module.

But I believe the second part of that is no longer a correct description of how the prelude works, as far as user-visible behaviour is concerned.

In particular, the following code compiles, but doesn't if I remove the use statement:

mod foo {
    use std::prelude::v1::*;
    type Bar = self::String;
}

And the following doesn't compile (saying «String is ambiguous»), but does if I remove the use for the prelude:

mod foo {
    use std::prelude::v1::*;
    use bar::*;

    mod bar {
        pub struct String {}
    }

    type Baz = String;
}

(Looking in libsyntax_ext/standard_library_imports.rs, I think it is still literally true that the compiler inserts a fake use directive, but the resolver treats it entirely differently to a normal one, so this doesn't seem to be something it makes sense to document.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions