Internal compiler error caused if statements involving an iterator adapter function use an undeclared type or module. #49544
Labels
A-iterators
Area: Iterators
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
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.
Description
Expressions involving an adaptor function like
skip
can cause an internalcompiler error. If a line of code in a submodule uses an undeclared type
or module in an expression using an adaptor, the compiler panics at
\'Box<Any>\', librustc_errors/lib.rs:543:9
.Code in a submodule needs to specify a path relative to the crate root, which
means prefixing
::
to a call likestd::env::args()
.Example
We will use the following two files to demonstrate the issue:
main.rs:
lib.rs:
Code in a submodule needs to specify a path relative to the crate root, which
means prefixing
::
to a call likestd::env::args()
. If we use::std::env::args()
the program compiles and runs successfully.As written however, the files above cause this internal compiler error:
This panic will occur for other adapters, like
take(n)
. After commenting outthe
skip(1)
line, the compiler does not panic. and only this output is seenafter trying to compile:
Potential UX Fixes
I ran into this error because the
::
error is not required for code in thecrate root. If
foo
is moved fromlib.rc
tomain.rs
, then the internalcompiler error no longer occurs.
If code outside of the crate root causes an error due to the use of an
undeclared type or module, it would be nice if the compiler warning would
mention the possibility of a missing
::
prefix, if the name that could notbe resolved was a type or module in the standard library.
When I reviewed the information given by running
rustc --explain E0433
, itmostly mentions the possibility of typos being the cause of this error.
Mentioning some other common situations that lead to symbols failing to
resolve might be helpful.
Meta
rustc --version --verbose
:Backtrace:
P.S. I am still somewhat new to Rust, but I would love to help out with this however I can!
The text was updated successfully, but these errors were encountered: