Skip to content

Point at duplicated dot in method access #65015

Closed
@estebank

Description

@estebank

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions