-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler marks import as unnecessary when it isn't (panic_handler) #127852
Comments
You can use |
I don't actually need to suppress the lint, I noticed it while I was refactoring and realised that the resulting fix would break the program. |
Alternatively use |
Or #[allow(unused_imports)]. I'm not looking for a solution for an annoying lint, I'm reporting a compiler bug. |
Similar example: // lib.rs
#![no_std]
use num_traits;
pub fn f(x: f64) -> f64 {
x.powf(3.14)
} # Cargo.toml
[package]
name = "num-traits-std-powf"
version = "0.1.0"
edition = "2021"
[dependencies]
num-traits = { version = "0.2.19" } This gives an (Should this be a separate issue? It seemed related) |
I checked and this also happens with using a custom allocator: #![no_std]
use core::alloc::GlobalAlloc;
extern crate alloc;
pub struct Allocator;
unsafe impl GlobalAlloc for Allocator {
unsafe fn alloc(&self, _layout: core::alloc::Layout) -> *mut u8 {
unimplemented!()
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: core::alloc::Layout) {
unimplemented!()
}
}
#[global_allocator]
pub static ALLOCATOR: Allocator = Allocator; main.rs: #![no_std]
#![no_main]
extern crate alloc;
use core::panic::PanicInfo;
use playground;
#[cfg_attr(not(test), panic_handler)]
fn panic_handler(_info: &PanicInfo) -> ! {
loop {}
} cargo check:
cargo check after removing import:
|
I tried this code:
lib.rs
:main.rs
:Cargo.toml
:Upon running
cargo check
it gives this output:This is incorrect, as the import provides panic_handler for main, even though it is not directly imported.
To get a minimal reproduction you can run:
git clone --branch panic_handler_import_bug https://github.com/mysteriouslyseeing/playground.git
Note that
cargo build
will fail at linkage with that minimal reproduction due to the#![no_main]
present. An alternate entry point would have to be specified based on the binaries' target to allowcargo build
to work.Meta
rustc --version --verbose
: (stable)rustc --version --verbose
: (nightly)cargo fix
:The text was updated successfully, but these errors were encountered: