-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Ergonomics: &String does not implement PartialEq<str> #44695
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
Start with this:
It doesn't compile: "the trait bound
&String: PartialEq<str>is not satisfied".Let's Google this, first hit is StackOverflow, first/accepted answer talks about
.as_ref(), try that.string_ref.as_ref() == &partial[..3]results in "the trait bound&_: PartialEq<str>is not satisfied" [oh, how I hate these underscores in errors].At this point I try adding
*to the LHS or&to the RHS. The latter results in "type annotations required: cannot resolveString: AsRef<_>" [huh?].Here's actually everything I tried (from my actual code instead of simple example):
At this point I'm pretty much out of ideas other than brute-forcing with some
to_string(). I don't really consider myself a beginner at this point, having successfully written a few thousand lines of code over the past 15 months, so here's where I have some empathy for those saying Rust's learning curve is just too steep.I went and read some more on SO and found this, which actually seems to work
(meta_subj as &str) == &db_subj[..998]. The reason I would not have come up with this is that generally the compiler seems to be able to coerce&T where T: Stringto&str, so I find it hard to come up with a reason it cannot do so in this case.