the trait bound `String: Deref` is not satisfied
mingjunyang opened this issue · 2 comments
mingjunyang commented
my rustc version:
rustc 1.66.0-nightly (0da281b60 2022-10-27)
error[E0277]: the trait bound `String: Deref` is not satisfied
--> qmetaobject/src/qmetatype.rs:438:87
|
438 | const CONVERSION_TO_STRING: Option<fn(&Self) -> QString> = Some(|s| QString::from(&*s as &str));
| ^^^ the trait `~const Deref` is not implemented for `String`
|
note: the trait `Deref` is implemented for `String`, but that implementation is not `const`
--> qmetaobject/src/qmetatype.rs:438:87
|
438 | const CONVERSION_TO_STRING: Option<fn(&Self) -> QString> = Some(|s| QString::from(&*s as &str));
| ^^^
For more information about this error, try `rustc --explain E0277`.
I try to fix the issuse, it's work.
diff --git a/qmetaobject/src/qmetatype.rs b/qmetaobject/src/qmetatype.rs
index 1d06100..f9bf9ce 100644
--- a/qmetaobject/src/qmetatype.rs
+++ b/qmetaobject/src/qmetatype.rs
@@ -435,7 +435,7 @@ where
}
impl QMetaType for String {
- const CONVERSION_TO_STRING: Option<fn(&Self) -> QString> = Some(|s| QString::from(&*s as &str));
+ const CONVERSION_TO_STRING: Option<fn(&Self) -> QString> = Some(|s| QString::from(s.as_str()));
const CONVERSION_FROM_STRING: Option<fn(&QString) -> Self> = Some(|s| s.to_string());
}
ogoffart commented
Thanks for the report.
Your code looks better than the original.
But this looks like a bug in the const engine of the nightly compiler. Why would this needs to be const?
ogoffart commented
Reported rust-lang/rust#103677