rust_2024_prelude_collisions fails with glob of underscore import
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![warn(rust_2024_prelude_collisions)]
pub mod prelude {
pub use crate::inner::FExt as _;
}
pub mod inner {
pub trait FExt {
fn into_future(self) -> StreamFuture
where
Self: Sized,
{
StreamFuture
}
}
pub struct StreamFuture;
pub struct F;
impl FExt for F {}
}
use crate::prelude::*;
pub fn f() {
let _ = crate::inner::F.into_future();
}
This generates a suggestion to modify the code like this:
@@ -23,5 +23,5 @@
use crate::prelude::*;
pub fn f() {
- let _ = crate::inner::F.into_future();
+ let _ = FExt::into_future(crate::inner::F);
}
However, this fails to compile with the following error:
error[E0433]: failed to resolve: use of undeclared type `FExt`
--> src/lib.rs:26:13
|
26 | let _ = FExt::into_future(crate::inner::F);
| ^^^^ use of undeclared type `FExt`
|
help: consider importing one of these traits
|
23 + use crate::inner::FExt;
|
23 + use f::FExt;
|
warning: unused import: `crate::prelude::*`
--> src/lib.rs:23:5
|
23 | use crate::prelude::*;
| ^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
For more information about this error, try `rustc --explain E0433`.
Because the _ import does not give the trait a name.
This comes up in real-life with importing use futures::prelude::*.
I'm not sure what the best solution to this would be. Perhaps it could detect a similar scenario, and fully qualify the path to the trait (like futures::StreamExt::into_future). Or just always fully qualify it?
Meta
rustc --version --verbose:
rustc 1.84.0-nightly (59cec72a5 2024-11-08)
binary: rustc
commit-hash: 59cec72a57af178767a7b8e7f624b06cc50f1087
commit-date: 2024-11-08
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimized example with the rust_2024_prelude_collisions lint using the reported nightly compiler, then inspect the lint's suggestion generation. The fix is done when the suggested replacement compiles even when the trait was imported only with as _, such as through futures::prelude::*.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100