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

add hint for =< as <= #111230

Merged
merged 1 commit into from
May 6, 2023
Merged

add hint for =< as <= #111230

merged 1 commit into from
May 6, 2023

Conversation

zacklukem
Copy link
Contributor

Adds a compiler hint for when =< is typed instead of <=

Example hint:

fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`

This PR only emits the suggestion if there is no space between the = and <. This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:

error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes #111128

@rustbot
Copy link
Collaborator

rustbot commented May 5, 2023

r? @oli-obk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2023
@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2023

I am wondering if the current logic could end up with weird spans in case of x =thing!() where thing!() expands to something starting with <. I can't come up with anything as a test, but maybe we should still guard against it by requiring that the spans' expansion info is the same?

@compiler-errors
Copy link
Member

This happens before macro expansion though. I don't think we need that extra commit on top.

@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2023

😆 too many reviewers. Seems fine to me to leave out the last commit since this can't happen. We don't re-parse the macro expansion in its context, but instead parse it as an expression.

@compiler-errors
Copy link
Member

Drop that commit, squash the rest of the commits into one then r=me

@zacklukem zacklukem force-pushed the eq-less-to-less-eq branch from c59e887 to a183ac6 Compare May 5, 2023 15:17
@oli-obk
Copy link
Contributor

oli-obk commented May 5, 2023

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented May 5, 2023

📌 Commit a183ac6 has been approved by compiler-errors

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 May 5, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 5, 2023
…mpiler-errors

add hint for =< as <=

Adds a compiler hint for when `=<` is typed instead of `<=`

Example hint:
```rust
fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
```
```
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`
```

This PR only emits the suggestion if there is no space between the `=` and `<`.  This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:
```
error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`
```

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes rust-lang#111128
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request May 6, 2023
…mpiler-errors

add hint for =< as <=

Adds a compiler hint for when `=<` is typed instead of `<=`

Example hint:
```rust
fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
```
```
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`
```

This PR only emits the suggestion if there is no space between the `=` and `<`.  This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:
```
error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`
```

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes rust-lang#111128
bors added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#110577 (Use fulfillment to check `Drop` impl compatibility)
 - rust-lang#110610 (Add Terminator conversion from MIR to SMIR, part #1)
 - rust-lang#110985 (Fix spans in LLVM-generated inline asm errors)
 - rust-lang#110989 (Make the BUG_REPORT_URL configurable by tools )
 - rust-lang#111167 (debuginfo: split method declaration and definition)
 - rust-lang#111230 (add hint for =< as <=)
 - rust-lang#111279 (More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 83b29ec into rust-lang:master May 6, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 6, 2023
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.

Writing =< instead of <= gives an error about types
5 participants