Skip to content

Add note regarding parent module containing use statement. #42283

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
merged 1 commit into from
May 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,32 @@ trait Foo {

fn foo<T>(x: T) {} // ok!
```

Another case that causes this error is when a type is imported into a parent
module. To fix this, you can follow the suggestion and use File directly or
`use super::File;` which will import the types from the parent namespace. An
example that causes this error is below:

```compile_fail,E0412
use std::fs::File;

mod foo {
fn some_function(f: File) {}
}
```

```
use std::fs::File;

mod foo {
// either
use super::File;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently CI failed with

[00:55:49] ---- /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index (line 6486) stdout ----
[00:55:49] 	error[E0432]: unresolved import `super::File`
[00:55:49]  --> <anon>:6:9
[00:55:49]   |
[00:55:49] 6 |     use super::File;
[00:55:49]   |         ^^^^^^^^^^^ no `File` in the root

Dunno why, probably workaround it by adding a hidden # pub above the use std::fs::File?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here was that rustdoc auto-injects fn main surrounding this, so it was correct -- there was no File in root. I inserted an empty commented fn main to workaround this, so we should be fine now.

// or
// use std::fs::File;
fn foo(f: File) {}
}
# fn main() {} // don't insert it for us; that'll break imports
```
"##,

E0415: r##"
Expand Down