Skip to content

Point at duplicated dot in method access #65015

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

Closed
estebank opened this issue Oct 2, 2019 · 0 comments · Fixed by #105765
Closed

Point at duplicated dot in method access #65015

estebank opened this issue Oct 2, 2019 · 0 comments · Fixed by #105765
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Oct 2, 2019

The following incorrect code

struct Type {
    option: Option<Vec<u8>>
}

impl Type {
    fn method(&self) -> Option<Vec<u8>> {
        self.option..as_ref().map(|x| x)
    }
}

fn main() {
    let _ = Type { option: None }.method();
}
error[E0425]: cannot find function `as_ref` in this scope
 --> src/main.rs:7:22
  |
7 |         self.option..as_ref().map(|x| x)
  |                      ^^^^^^ not found in this scope

error[E0308]: mismatched types
 --> src/main.rs:7:9
  |
6 |     fn method(&self) -> Option<Vec<u8>> {
  |                         --------------- expected `std::option::Option<std::vec::Vec<u8>>` because of return type
7 |         self.option..as_ref().map(|x| x)
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found struct `std::ops::Range`
  |
  = note: expected type `std::option::Option<_>`
             found type `std::ops::Range<std::option::Option<_>>`

has a typo where two dots where written where one for method access was meant. It is not made clear enough in the output due to complaining about finding Range but not pointing at the two dots that caused the range to be there.

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 2, 2019
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 27, 2022
…rors

Detect likely `.` -> `..` typo in method calls

Fix rust-lang#65015.
@bors bors closed this as completed in c9381fc Dec 28, 2022
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant