Open
Description
I tried this code:
fn main() {
UnsafeValue::from(foo);
}
fn foo(_: &Context) -> Result<(), Box<dyn core::error::Error>> {
Ok(())
}
struct UnsafeValue;
impl From<fn(&Context) -> Result<(), Box<dyn core::error::Error>>> for UnsafeValue {
fn from(_: fn(&Context) -> Result<(), Box<dyn core::error::Error>>) -> Self {
Self
}
}
struct Context {}
I expected to see this happen: The code compile.
Instead, this happened:
error[E0277]: the trait bound `UnsafeValue: From<for<'a> fn(&'a Context) -> Result<(), Box<(dyn std::error::Error + 'static)>> {foo}>` is not satisfied
--> src/main.rs:2:5
|
2 | UnsafeValue::from(foo);
| ^^^^^^^^^^^ the trait `From<for<'a> fn(&'a Context) -> Result<(), Box<(dyn std::error::Error + 'static)>> {foo}>` is not implemented for `UnsafeValue`
|
= help: the trait `From<for<'a> fn(&'a Context) -> Result<_, _> {foo}>` is not implemented for `UnsafeValue`
but trait `From<for<'a> fn(&'a Context) -> Result<_, _>>` is implemented for it
= help: for that trait implementation, expected `for<'a> fn(&'a Context) -> Result<(), Box<(dyn std::error::Error + 'static)>>`, found `for<'a> fn(&'a Context) -> Result<(), Box<(dyn std::error::Error + 'static)>> {foo}`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustbug` (bin "rustbug") due to 1 previous error
Meta
rustc --version --verbose
:
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-unknown-linux-gnu
release: 1.87.0
LLVM version: 20.1.1