Skip to content

Comparing String < {number} gives subpar suggestion and comparisons don't point at source of E0308 expectation #104840

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

Open
estebank opened this issue Nov 24, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

When writing string < number, the current output is:

error[E0308]: mismatched types
 --> src/main.rs:2:29
  |
2 |     let _ = String::new() < 42;
  |                             ^^- help: try using a conversion method: `.to_string()`
  |                             |
  |                             expected struct `String`, found integer

but it should be closer to

error[E0308]: mismatched types
 --> src/main.rs:2:29
  |
2 |     let _ = String::new() < 42;
  |             -------------   ^^ expected struct `String`, found integer
  |             |               
  |             expected because of this
  |
help: you might have meant to compare the string's length
2 |     let _ = String::new().len() < 42;
  |                          ++++++
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Nov 24, 2022
@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Nov 24, 2022

Related: #77304

@chenyukang
Copy link
Member

how do we determine should try to convert from RHS to LHS, or from LHS to RHS..
from this case, since the RHS is already a primitive type, so we convert type from LHS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants