Skip to content
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

the trait bound String: Deref is not satisfied #275

Open
mingjunyang opened this issue Oct 28, 2022 · 2 comments
Open

the trait bound String: Deref is not satisfied #275

mingjunyang opened this issue Oct 28, 2022 · 2 comments

Comments

@mingjunyang
Copy link

mingjunyang commented Oct 28, 2022

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
Copy link
Member

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
Copy link
Member

Reported rust-lang/rust#103677

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

2 participants