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

Macros are being expanded when emitting suggestions #1148

Closed
trixnz opened this issue Aug 7, 2016 · 5 comments
Closed

Macros are being expanded when emitting suggestions #1148

trixnz opened this issue Aug 7, 2016 · 5 comments
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion

Comments

@trixnz
Copy link

trixnz commented Aug 7, 2016

When clippy reports a suggestion with a macro in the code, it seems to print the expanded form. Using the example from README.md, you can see it is not behaving as expected:

fn main(){                             
    let x = Some(1u8);                 
    match x {                          
        Some(y) => println!("{:?}", y),
        _ => ()                        
    }                                  
}

results in:

warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`, #[warn(single_match)] on by default
 --> src\main.rs:3:5
  |
3 |     match x {
  |     ^
  |
help: try this
  |     if let Some(y) = x { $ crate :: io :: _print ( format_args ! ( $ ( $ arg ) * ) ) }
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#single_match
@Manishearth
Copy link
Member

This seems to be snippet() misbehaving, cc @jonathandturner

@Manishearth
Copy link
Member

er, span_to_snippet

@trixnz
Copy link
Author

trixnz commented Aug 7, 2016

After doing a bit more research, this only seems to affect match expressions without scope arms. This produces the desired output:

fn main() {
    let x = Some(1u8);
    match x {
        Some(y) => {
            println!("{:?}", y);
        }
        _ => (),
    }
}

results in:

warning: you seem to be trying to use match for destructuring a single pattern. Consider using `if let`, #[warn(single_match)] on by default
 --> src\main.rs:3:5
  |
3 |     match x {
  |     ^
  |
help: try this
  |     if let Some(y) = x {
  |     println!("{:?}", y);
  | }
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#single_match

@sophiajt
Copy link
Contributor

sophiajt commented Aug 7, 2016

Agreed - looks like we're (I'm) not sorting the help with a snippet to be after the ones without snippets. Filed rust-lang/rust#35460

@oli-obk
Copy link
Contributor

oli-obk commented Aug 31, 2017

@jonathandturner the issue here is not the snippet ordering, but the expansion of the println macro

@phansch phansch added C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion labels Oct 6, 2018
bors bot added a commit that referenced this issue Oct 27, 2018
3366: Don't expand macros in some suggestions r=oli-obk a=phansch

Fixes #1148 
Fixes #1628
Fixes #2455
Fixes #3023
Fixes #3333
Fixes #3360

Co-authored-by: Philipp Hansch <dev@phansch.net>
bors bot added a commit that referenced this issue Oct 28, 2018
3217: Fix string_lit_as_bytes lint for macros r=phansch a=yaahallo

Prior to this change, string_lit_as_bytes would trigger for constructs
like `include_str!("filename").as_bytes()` and would recommend fixing it
by rewriting as `binclude_str!("filename")`.

This change updates the lint to act as an EarlyLintPass lint. It then
differentiates between string literals and macros that have bytes
yielding alternatives.

Closes #3205

3366: Don't expand macros in some suggestions r=oli-obk a=phansch

Fixes #1148 
Fixes #1628
Fixes #2455
Fixes #3023
Fixes #3333
Fixes #3360

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
Co-authored-by: Philipp Hansch <dev@phansch.net>
@bors bors bot closed this as completed in #3366 Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants