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

Suggested fix does not account for operator precedence #64919

Closed
DomantasJ opened this issue Sep 30, 2019 · 2 comments · Fixed by #64933 or #64972
Closed

Suggested fix does not account for operator precedence #64919

DomantasJ opened this issue Sep 30, 2019 · 2 comments · Fixed by #64933 or #64972
Assignees
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DomantasJ
Copy link

DomantasJ commented Sep 30, 2019

This fails (as expected):

fn foo() -> String {
    1 + 2
}

However, the help message is wrong:

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn foo() -> String {
  |             ------ expected `std::string::String` because of return type
2 |     1 + 2
  |     ^^^^^
  |     |
  |     expected struct `std::string::String`, found integer
  |     help: try using a conversion method: `1 + 2.to_string()`
  |
  = note: expected type `std::string::String`
             found type `{integer}`

It should suggest (1 + 2).to_string() instead.

Rust version: 1.38.0 (stable)

@varkor varkor added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Sep 30, 2019
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 30, 2019
@sam09
Copy link
Contributor

sam09 commented Sep 30, 2019

I would like to pick this up, in case nobody is working on it

@varkor
Copy link
Member

varkor commented Sep 30, 2019

@sam09: go ahead!

tmandry added a commit to tmandry/rust that referenced this issue Oct 1, 2019
Fixes rust-lang#64919. Suggest fix based on operator precendence.

Fixes rust-lang#64919
tmandry added a commit to tmandry/rust that referenced this issue Oct 1, 2019
Fixes rust-lang#64919. Suggest fix based on operator precendence.

Fixes rust-lang#64919
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
Fixes rust-lang#64919. Suggest fix based on operator precendence.

Fixes rust-lang#64919
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
Fixes rust-lang#64919. Suggest fix based on operator precendence.

Fixes rust-lang#64919
bors added a commit that referenced this issue Oct 1, 2019
Rollup of 7 pull requests

Successful merges:

 - #63416 (apfloat: improve doc comments)
 - #64820 (BTreeSet intersection, is_subset & difference optimizations)
 - #64910 (syntax: cleanup param, method, and misc parsing)
 - #64912 (Remove unneeded `fn main` blocks from docs)
 - #64933 (Fixes #64919. Suggest fix based on operator precendence.)
 - #64943 (Add lower bound doctests for `saturating_{add,sub}` signed ints)
 - #64950 (Simplify interners)

Failed merges:

r? @ghost
@bors bors closed this as completed in c9baaa7 Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants