-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
crash when crate is not used
but referred inside a module
#94182
Comments
This is hilarious. |
That For the next Rust developer's later debugging reference, note this pair of commits: It also includes the workaround in services/shellchat/src/cmds/net_cmds.rs, line 11 (which still lies there unto this day!), so you will have to remove it to diagnose. |
I just ran it against |
Oh cool! Doing some research, it seems like this was prooobably fixed along with one of these:
So yeah, we can close it! |
thanks!! |
seems to not trigger in the latest rust.
Code
The setup to this is a bit complicated, but I will try to describe it as compactly as possible. We have a multi-crate workspace. In this example, the crate in question is called
dns
. It has a duallib
/bin
construction, e.g. it has interfaces callable by other crates, but also its ownmain
. There is a module calledapi
that defines common structures between the lib/bin halves.The bug happened only when inside the
lib
half of the crate, we split the thelib
into two conditionally compiled sub-modules. This is the fulllib.rs
that causes the problem:It was originally just one file, with the
api
file included, plus the contents ofmod hw
directly inside thelib.rs
(so basically, the goal was to make the library interface different based upon the target machine we were going for; thus, the commonapi
crate, but either ahw
or ahosted
file for the contents oflib
).The compiler crash happens inside
shellchat
, which is another crate in the workspace that pulls in thedns
crate.The thing that triggers the crash is that we don't do this:
Or have any
use
statement. We were referring to all thedns
structures by their full path name (e.g.,dns::Dns::new()
,dns::Dns::lookup()
, etc.). We didn'tuse
it because it's just a couple of lines where we use the DNS crate anddns
is a short enough name that we never got around touse
thedns
crate into the name space.only after we moved the
lib
into subfiles did the crash happen.And, the fix to the crash is to simply add
use dns::Dns
to the top of theshellchat
file where we were calling DNS.Anyways, it's not a big deal -- the workaround is painless and probably most people in practice will
use
a module when they start calling functions in it, we just preferred to use fully-specified names in this one case. From the looks of the bug it looks like the compiler basically expected thatuse
statement and was looking for a path that didn't exist because it wasn't there.Not a show stopper -- mainly just reporting it because the error message requested the bug report. Thanks for all the hard work!
Meta
rustc --version --verbose
:Error output
Backtrace inside the click-expand below:
Backtrace
The text was updated successfully, but these errors were encountered: