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

With over-parenthesized method that isn't called, E0615 suggests adding parentheses in the wrong place #89044

Closed
jruderman opened this issue Sep 17, 2021 · 0 comments · Fixed by #89055
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

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)()
  |                   ++

The fix suggested by the compiler still has the problem, because the parentheses-to-call are added outside of the parentheses in the code.

Ideally the output should look like:

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

This is similar to the recently fixed #88803, but differs in that the input code cannot be fixed solely by removing parentheses.

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 17, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Sep 19, 2021
…ens, r=wesleywiser

Suggest better place to add call parentheses for method expressions wrapped in parentheses

I wanted to improve the suggestion a bit to both remove the wrapping parentheses **and** add call parentheses by both calling `suggest_method_call` and using `multipart_suggestion`. But I very quickly ran into a problem where multiple overlapping machine applicable suggestions cannot be properly applied together. So I applied the suggestion from the issue and only added the call parentheses directly after the expression.

Fixes: rust-lang#89044
@bors bors closed this as completed in 441046a Sep 19, 2021
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
1 participant