Skip to content

rust_2024_prelude_collisions fails with glob of underscore import #132864

Open
@ehuss

Description

@ehuss

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions