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

Unnecessary macro expansion in unused_parens lint #55109

Closed
Aaron1011 opened this issue Oct 16, 2018 · 1 comment
Closed

Unnecessary macro expansion in unused_parens lint #55109

Aaron1011 opened this issue Oct 16, 2018 · 1 comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@Aaron1011
Copy link
Member

This code snippet (playground)

fn main() {
    let _ = (format!("Test"));
}

results in the following lint output:

warning: unnecessary parentheses around assigned value
 --> src/main.rs:2:13
  |
2 |     let _ = (format!("Test"));
  |             ^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_parens)] on by default
help: remove these parentheses
  |
2 |     let _ = ::fmt::format(::std::fmt::Arguments::new_v1(&["Test"],
3 |                                              &match () { () => [], }));
  |

    Finished dev [unoptimized + debuginfo] target(s) in 0.56s
     Running `target/debug/playground`

The help: remove these parentheses should contain the literal string format!, not the expanded macro that it repreesnts.

@Aaron1011 Aaron1011 changed the title Unnecessary macro expansion in unused_parens lit Unnecessary macro expansion in unused_parens lint Oct 16, 2018
@Havvy Havvy added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Oct 16, 2018
@zackmdavis
Copy link
Member

Ah, I think this is because we should be using CodeMap::span_to_snippet (to get the code the user actually wrote) rather than pprust::expr_to_string (to render the AST); I could PR this tonight.

zackmdavis added a commit to zackmdavis/rust that referenced this issue Oct 17, 2018
Aaron Hill pointed out that unnecessary parens around a macro call
(paradigmatically, `format!`) yielded a suggestion of hideous
macro-expanded code. (The slightly unusual choice of using the
pretty-printer to compose suggestions was quite recently commented on
in the commit message for 1081bbb ("abolish ICE when pretty-printing
async block"), but without any grounds to condemn it as a 𝘣𝘢𝘥
choice. Hill's report provides the grounds.) `span_to_snippet` is
fallable as far as the type system is concerned (because, who knows,
macros or something), so the pretty-printing can live on in the
oft-neglected `else` branch.

Resolves rust-lang#55109.
kennytm added a commit to kennytm/rust that referenced this issue Oct 24, 2018
in which unused-parens suggestions heed what the user actually wrote

Aaron Hill pointed out that unnecessary parens around a macro call (paradigmatically, `format!`) yielded a suggestion of hideous macro-expanded code. `span_to_snippet` is fallable as far as the type system is concerned, so the pretty-printing can live on in the oft-neglected `else` branch.

Resolves rust-lang#55109.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
in which unused-parens suggestions heed what the user actually wrote

Aaron Hill pointed out that unnecessary parens around a macro call (paradigmatically, `format!`) yielded a suggestion of hideous macro-expanded code. `span_to_snippet` is fallable as far as the type system is concerned, so the pretty-printing can live on in the oft-neglected `else` branch.

Resolves rust-lang#55109.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

3 participants