crash when crate is not used
but referred inside a module
#94182
Labels
A-resolve
Area: Name resolution
C-bug
Category: This is a bug.
I-ICE
Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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: