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

Detect likely . -> .. typo in method calls #105765

Merged
merged 3 commits into from
Dec 28, 2022
Merged

Conversation

estebank
Copy link
Contributor

Fix #65015.

@rustbot
Copy link
Collaborator

rustbot commented Dec 16, 2022

r? @lcnr

(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 Dec 16, 2022
@estebank
Copy link
Contributor Author

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned lcnr Dec 16, 2022
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/coercion.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
let suggestion =
if res.is_none() { this.report_missing_type_error(path) } else { None };
let suggestion = if let Some((start, end)) = this.diagnostic_metadata.in_range
&& path[0].ident.span.lo() == end.span.lo()
Copy link
Member

@compiler-errors compiler-errors Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look too much into this, but does this check that this is a method?

We should also probably double check this is a path with one segment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't, but during resolve we don't have enough data to do that (although now that I'm tracking start I might be able to cobble something together).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comfortable with the weasel wording on this one suggestion: it is a guess, and we'd have to perform more extensive surgery on resolve to track more state, and it is already quite a beast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is that this triggers when we have any resolution error on the RHS of a range, e.g.

fn foo() {
  a..b;
}

Results in:

error[E0425]: cannot find value `a` in this scope
 --> /home/ubuntu/test.rs:2:5
  |
2 |     a..b;
  |     ^ not found in this scope

error[E0425]: cannot find value `b` in this scope
 --> /home/ubuntu/test.rs:2:8
  |
2 |     a..b;
  |        ^ not found in this scope
  |
help: you might have meant to write a method call instead of a range
  |
2 -     a..b;
2 +     a.b;

I'd much prefer if the wording was made to not mention methods in specific, but focus on the . itself -- something like "you might've meant to write the . operator instead of a range"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of "you might have meant to write . instead of .."

Copy link
Member

@compiler-errors compiler-errors Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that works fine.

Just would prefer it to not mention "method" unless we can verify it's actually a method, but since this code is in resolve, I totally understand how that's hard, haha.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 16, 2022

r? @compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned oli-obk Dec 16, 2022
@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2022
@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 27, 2022
@compiler-errors
Copy link
Member

r=me -- preferably with the resolve diagnostic's wording made more generic, but I guess I won't hold you to it

@estebank
Copy link
Contributor Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Dec 27, 2022

📌 Commit 7e84273 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 Dec 27, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 27, 2022
…mpiler-errors

Rollup of 9 pull requests

Successful merges:

 - rust-lang#103718 (More inference-friendly API for lazy)
 - rust-lang#105765 (Detect likely `.` -> `..` typo in method calls)
 - rust-lang#105852 (Suggest rewriting a malformed hex literal if we expect a float)
 - rust-lang#105965 (Provide local extern function arg names)
 - rust-lang#106064 (Partially fix `explicit_outlives_requirements` lint in macros)
 - rust-lang#106179 (Fix a formatting error in Iterator::for_each docs)
 - rust-lang#106181 (Fix doc comment parsing description in book)
 - rust-lang#106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`)
 - rust-lang#106189 (Fix UnsafeCell Documentation Spelling Error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a9fdedd into rust-lang:master Dec 28, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 28, 2022
@estebank estebank deleted the range-typo branch November 9, 2023 05:14
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.

Point at duplicated dot in method access
6 participants