Cannot do use cratename
at top-level; only in sub-mods. Error message unclear.
#13968
Labels
A-resolve
Area: Name/path resolution done by `rustc_resolve` specifically
Someone on IRC asked how to reference a
pub static
in an external crate, noting thatcratename::value
was not resolving (it turned out they were writing this reference in a sub-module, not the top-level library).While making sample code to illustrate the ways to get such code to work, I found an oddity.
(Note: It is probably just something where our error messages need to be improved. Though there may be a reasonable argument that
use cratename
should just work anywhere, to ease cut-and-pasting code from sub-modules into the top-level lib.)It is valid to say
use cratename::value
and it is valid to sayuse local_name = cratename;
, but it is not valid to sayuse cratename;
in the top-most level of the library/program. (It is valid to sayuse cratename
in an inner module within the lib; just not the lib itself.)From my tests, it appears that the reason for this is that an
extern crate cratename
declaration implicitly importscratename
into the relative-path roots for the top-level of the library.Test code:
Here's what currently happens:
This is a hint that the problem is probably that we end up with some sort of resolve collision when we do
use n
at the top-level. It is possible that the fix here would simply be a better error message explaining the problem.The text was updated successfully, but these errors were encountered: