Skip to content

With over-parenthesized method call, E0615 suggests adding parentheses in the wrong place #88803

Closed
@jruderman

Description

@jruderman

Given the following code:

fn main() {
    let a = Some(42);
    println!(
        "The value is {}.",
        (a.unwrap)()
    );
}

The current output is:

error[E0615]: attempted to take value of method `unwrap` on type `Option<{integer}>`
 --> src/main.rs:5:12
  |
5 |         (a.unwrap)()
  |            ^^^^^^ method, not a field
  |
help: use parentheses to call the method
  |
5 |         (a.unwrap)()()
  |                   ++

Ideally the output should look like:

help: remove these parentheses

(a.unwrap)()
^^^^^^^^^^ 

But at least adding parentheses right next to the method name would be an improvement:

help: use parentheses to call the method
  |
5 |         (a.unwrap())()
  |                  ++

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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