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

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

Closed
mattheww opened this issue Sep 22, 2019 · 1 comment · Fixed by #73484
Closed

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

mattheww opened this issue Sep 22, 2019 · 1 comment · Fixed by #73484
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools A-resolve Area: Name resolution C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@mattheww
Copy link
Contributor

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.)

@jonas-schievink jonas-schievink added A-resolve Area: Name resolution C-bug Category: This is a bug. A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Sep 22, 2019
@poliorcetics
Copy link
Contributor

If I understand correctly (and from what your tests indicates), use std::prelude::v1::* is effectively added only at the top of every file ?

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 A-resolve Area: Name resolution C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants