Repository navigation
handle extern crate in name resolution #523
Description
Activity
- changed the title
[-]cannot resolve std::sync::Arc[/-][+]handle `extern crate` in name resolution[/+]on Jan 26, 2019 Shouldn't be too hard to fix:
-
we should add
extern crates toLoweredModulehere: https://github.com/rust-analyzer/rust-analyzer/blob/581c97a5c3821e247df372f25cf8c01ed514bdd9/crates/ra_hir/src/nameres/lower.rs -
we should adjust path resolution to take it into account here: https://github.com/rust-analyzer/rust-analyzer/blob/581c97a5c3821e247df372f25cf8c01ed514bdd9/crates/ra_hir/src/nameres.rs
-
- addedE-has-instructionsIssue has some instructions and pointers to code to get startedIssue has some instructions and pointers to code to get started
on Feb 3, 2019 @matklad I've got a branch which does handle
extern crate(by lowering them to imports with absolute paths), but it doesn't fix this problem, because it turns out we also need to fall back to resolving imports in the crate root. In this particular case, it looks like this:
lib.rs:extern crate alloc as alloc_crate; mod sync;
sync.rs:
pub use alloc_crate::sync::Arc;
In general, even in the 2018 edition, plain paths can be resolved either from the current scope or from the crate root.
In general, even in the 2018 edition, plain paths can be resolved either from the current scope or from the crate root.
Just checked locally, and it seems that on 2018
::foooruse foodon't resolve from the crate root. Could it be thatasinextern crateacts as as renamer of the whole crate?Hm, you're right, it just works for
extern crateapparently. Butextern crate foo as bardoesn't just rename the crate in the extern prelude, because 1. it only has an effect if it's in the crate root or the current module, and 2. the original name is still usable. Back to reading rustc, I guess...I think
extern crates in the crate root are special-cased to insert entries in the extern prelude, if I read this correctly:
https://github.com/rust-lang/rust/blob/fc6e9a2845e8bb4560811ed21136483a596505bb/src/librustc_resolve/build_reduced_graph.rs#L390-L408Yup, rust-lang/rust#54658
Though
stdisn't actually a case of this, since it's still edition 2015, but I guess if we implemented it that way we could still avoid implementing 2015 name resolution...- added a commit that references this issue
on Feb 5, 2019
Currently,
std::sync::Arccannot be resolved.In #522 (comment), @flodiebold speculates:
Here's a simple test case: