Skip to content

match_ref_pats: don't emit suggestions inside of a macro #3432

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

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use std::collections::Bound;
use crate::syntax::ast::LitKind;
use crate::syntax::source_map::Span;
use crate::utils::paths;
use crate::utils::{expr_block, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg,
remove_blocks, snippet, span_lint_and_sugg, span_lint_and_then,
span_note_and_lint, walk_ptrs_ty};
use crate::utils::{expr_block, in_macro, is_allowed, is_expn_of, match_qpath, match_type,
multispan_sugg, remove_blocks, snippet, span_lint_and_sugg, span_lint_and_then,
span_note_and_lint, walk_ptrs_ty};
use crate::utils::sugg::Sugg;
use crate::consts::{constant, Constant};
use crate::rustc_errors::Applicability;
Expand Down Expand Up @@ -457,7 +457,9 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr:
}));

span_lint_and_then(cx, MATCH_REF_PATS, expr.span, title, |db| {
multispan_sugg(db, msg.to_owned(), suggs);
if !in_macro(expr.span) {
multispan_sugg(db, msg.to_owned(), suggs);
}
});
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/ui/ice-2636.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(dead_code)]

enum Foo {
A,
B,
C,
}

macro_rules! test_hash {
($foo:expr, $($t:ident => $ord:expr),+ ) => {
use self::Foo::*;
match $foo {
$ ( & $t => $ord,
)*
};
};
}

fn main() {
let a = Foo::A;
test_hash!(&a, A => 0, B => 1, C => 2);
}

16 changes: 16 additions & 0 deletions tests/ui/ice-2636.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: you don't need to add `&` to both the expression and the patterns
--> $DIR/ice-2636.rs:21:9
|
21 | / match $foo {
22 | | $ ( & $t => $ord,
23 | | )*
24 | | };
| |_________^
...
30 | test_hash!(&a, A => 0, B => 1, C => 2);
| --------------------------------------- in this macro invocation
|
= note: `-D clippy::match-ref-pats` implied by `-D warnings`

error: aborting due to previous error