How to use prelude_import attribute?

I understand the #[prelude_import] attribute is nightly, but I want to use it anyway. It seems like it works:

#![feature(prelude_import)]

pub mod p {
    pub fn f() {
        println!("Hi!");
    }
}

#[prelude_import]
use p::*;

mod q {
    pub fn q() {
        f();
    }
}

fn main() {
    q::q();
}

It prints Hello!, however the compiler says:

warning: unused import: `p::*`
  --> src/main.rs:10:5
   |
10 | use p::*;
   |     ^^^^

I can probably disable the warning, but why does it happen?

Unstable features are allowed to be a little quirky... but FWIW, both core and std have #[allow(unused)] on their use of this feature.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.