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

'unresolved import' after adding '#![feature(proc_macro)]' #50187

Closed
CodeSandwich opened this issue Apr 23, 2018 · 4 comments
Closed

'unresolved import' after adding '#![feature(proc_macro)]' #50187

CodeSandwich opened this issue Apr 23, 2018 · 4 comments
Assignees
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) A-resolve Area: Path resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CodeSandwich
Copy link

I've found a strange bug related to proc macros, which I have hard time reproducing. The simplest steps are:

  1. Clone futures_rs (https://github.com/rust-lang-nursery/futures-rs)
  2. Check out version tagged as 0.1.18 (it does not fail on the newest version)
  3. Run cargo check - it passes
  4. Add #![feature(proc_macro)] on the beginning of src/lib.rs
  5. Run cargo check - it fails:
error[E0432]: unresolved import
  --> src/future/mod.rs:34:16
   |
34 | pub use self::{result as done, FutureResult as Done};
   |                ^^^^^^^^^^^^^^

error: aborting due to previous error

I'm sorry for convoluted instructions, I could not reproduce the issue from the scratch or by reducing futures-rs to a failing bare minimum.

The failing code looks really casual, just reexports of a simple function. If anybody could find the root cause, that would probably help a lot.

I'm using rustc 1.27.0-nightly (ac3c2288f 2018-04-18) on Ubuntu 17.10.

@pietroalbini pietroalbini added A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. A-resolve Area: Path resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 24, 2018
@CodeSandwich
Copy link
Author

New discovery: changing the offending line 34 in src/future/mod.rs from
pub use self::{result as done, ...
to
pub use self::{result_::result as done, ...
fixes the error

@CodeSandwich
Copy link
Author

I've extracted the root cause (Playground):

#![feature(proc_macro)]
use std::result;
mod module {
    pub fn result() {}
}
pub use self::module::result;
pub use self::result as rename;

@petrochenkov
Copy link
Contributor

It's rather caused by use_extern_macros (#35896) that's enabled by proc_macro implicitly.
I can't promise, but I'll try to investigate this issue this weekend.

@petrochenkov petrochenkov self-assigned this Apr 24, 2018
@petrochenkov
Copy link
Contributor

petrochenkov commented Apr 30, 2018

Intermediate results:

Further minimized reproduction (only local items used, no self, separate modules):

#![feature(use_extern_macros)]

mod type_ns {
    pub type A = u8;
}
mod value_ns {
    pub const A: u8 = 0;
}
mod merge {
    pub use type_ns::A;
    pub use value_ns::A;
}

use merge::A; //~ ERROR unresolved import

Without use_extern_macros imports do not consider macro namespace and fixed-point import resolution runs in two namespaces (type and value).
With use_extern_macros fixed-point import resolution runs in three namespaces (type, value and macro) and for some reason merge::A ends up as indeterminate in macro namespace (instead of supposedly correct "determinate, no resolution"), i.e. the algorithm gets stuck before resolving all imports.

I haven't yet figured out why exactly this happens and this particular case is likely a bug, but it's quite possible that import resolution in 2+1 namespaces can legitimately lead to more errors due to indeterminacy, so it'll certainly need to go through crater before stabilization.

bors added a commit that referenced this issue May 2, 2018
Fix an unresolved import issue with enabled `use_extern_macros`

This is a kinda ugly special-purpose solution that will break if we suddenly add a fourth namespace, but I hope to come up with something more general if I get to import resolution refactoring this summer.

Fixes #50187 thus removing a blocker for stabilization of `use_extern_macros`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) A-resolve Area: Path resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants