-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed as not planned
Closed as not planned
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.
Milestone
Description
Code
I tried this code:
#![no_std]
// Yes, this is `no_std` + `extern crate std`, which happens a lot in
// crates that are `cfg(not(something), no_std)`
extern crate std;
extern crate alloc;
use alloc::boxed::Box;
fn main() {
std::panic::set_hook(Box::new(panic_handler));
}
fn panic_handler(info: &core::panic::PanicInfo) {
}
I expected to see this happen: It compiles just fine
Instead, this happened: I get the following error:
error[E0631]: type mismatch in function arguments
--> src/main.rs:9:26
|
9 | std::panic::set_hook(Box::new(panic_handler));
| ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
...
12 | fn panic_handler(info: &core::panic::PanicInfo) {
| ----------------------------------------------- found signature defined here
|
= note: expected function signature `for<'a, 'b> fn(&'a PanicHookInfo<'b>) -> _`
found function signature `fn(&PanicInfo<'_>) -> _`
= note: required for the cast from `Box<for<'a, 'b> fn(&'a PanicInfo<'b>) {panic_handler}>` to `Box<(dyn for<'a, 'b> Fn(&'a PanicHookInfo<'b>) + Send + Sync + 'static)>`
On nightly PanicInfo
is a type alias for PanicHookInfo
, however the alias only exists in the std
crate. If you reference PanicInfo
from core
, that is now a different type that does not unify with PanicHookInfo
.
It is relatively common in crates that support no_std
to always use the lowest possible crate to reference for any reexported type, which is why our code was referencing core::panic
even though this particular snippet of code needs std
to work overall.
Version it worked on
It most recently worked on: Rust 1.79, Rust 1.80-beta3
Version with regression
rustc --version --verbose
:
1.81.0-nightly (2024-06-19 d8a38b00024cd7156dea)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.