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

Suggest == to wrong assign expr #102708

Merged
merged 2 commits into from
Oct 6, 2022
Merged

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Oct 5, 2022

Given the following code:

fn main() {
    let x = 3;
    let y = 3;
    if x == x && y = y {
        println!("{}", x);
    }
}

Current output is:

error[E0308]: mismatched types
 --> src/main.rs:4:18
  |
4 |     if x == x && y = y {
  |                  ^ expected `bool`, found integer

error[E0308]: mismatched types
 --> src/main.rs:4:8
  |
4 |     if x == x && y = y {
  |        ^^^^^^^^^^^^^^^ expected `bool`, found `()`

This adds a suggestion:

error[E0308]: mismatched types
 --> src/main.rs:6:18
  |
6 |     if x == x && y = y {
  |                  ^ expected `bool`, found integer

error[E0308]: mismatched types
 --> src/main.rs:6:8
  |
6 |     if x == x && y = y {
  |        ^^^^^^^^^^^^^^^ expected `bool`, found `()`
  |
+ help: you might have meant to compare for equality
+   |
+ 6 |     if x == x && y == y {
+   |                     +

And this fixes a part of #97469

@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented Oct 5, 2022

r? compiler

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 5, 2022
@TaKO8Ki TaKO8Ki added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 5, 2022
@estebank
Copy link
Contributor

estebank commented Oct 5, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Oct 5, 2022

📌 Commit b7c42c5 has been approved by estebank

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 5, 2022
@TaKO8Ki TaKO8Ki changed the title Suggest == to the rest of assign expr Suggest == to wrong assign expr Oct 5, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 6, 2022
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#102672 (rustdoc: remove unused CSS class `in-band`)
 - rust-lang#102693 (Revert "Use getentropy when possible on all Apple platforms")
 - rust-lang#102694 (Suggest calling method if fn does not exist)
 - rust-lang#102708 (Suggest `==` to wrong assign expr)
 - rust-lang#102710 (Add test for issue 82633)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0512a06 into rust-lang:master Oct 6, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 6, 2022
@TaKO8Ki TaKO8Ki deleted the improve-eqeq-suggestion branch October 6, 2022 08:58
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants