std_instead_of_core
creates an invalid fix on stacked imports
#12468
Labels
C-bug
Category: Clippy is not doing the correct thing
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
Summary
Found while fixing this one #12406.
It has existed probably since this lint was created, but became problematic once the clippy-fix was added.
The problem is that
check_path
will get each path separately, i.e. for:There will be two passes, and to the code, the paths will look like:
But, the code will deduce that they are from the same import because the
std
-span is the same on those two passes, and it keeps the last span saved.There's some nuance here, in the case that the path is a part of a stacked import, each path in that import needs to be known to ensure that the fix will be valid, and at least with
check_path
that's hard to know without looking ahead.Reproducer
I tried this code:
I expected to see this happen:
Warn that
std::fmt::Result
can be imported fromcore
and either:core::io::Write
does not exist.Instead, this happened:
std
is replaced bycore
which doesn't compile.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: