Skip to content

Code is inactive hint on #[cfg(not(test))] #7529

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

Closed
OleStrohm opened this issue Feb 3, 2021 · 2 comments
Closed

Code is inactive hint on #[cfg(not(test))] #7529

OleStrohm opened this issue Feb 3, 2021 · 2 comments

Comments

@OleStrohm
Copy link
Contributor

I have been following the OS tutorial from https://os.phil-opp.com/, and after turning of the standard library and setting up my own panic_handler I ended up with the following code:

#[cfg(not(test))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    println!("{}", info);
    loop {}
}

#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    serial_println!("[FAILED]\n");
    serial_println!("Error: {}\n", info);
    exit_qemu(QemuExitCode::Failed);
    loop {}
}

the intent is that the first one is active for normal use and the bottom one is only active when running something like cargo test. However rust-analyzer is giving me a hint that the first function is inactive code since: code is inactive due to #[cfg] directives: test is enabled.

I've checked, and it's definitely running the right panic handler for each version, so I think rust-analyzer is giving me a hint for no reason here.

@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2021

Rust-analyzer always enables #[cfg(test)] and thus disables #[cfg(not(test))] to ensure that ide functions work inside tests.

@lnicola
Copy link
Member

lnicola commented Feb 3, 2021

Duplicate of #7225 and maybe others.

@lnicola lnicola closed this as completed Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants