about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-04-08 16:51:40 -0400
committerJason Newcomb <jsnewcomb@pm.me>2022-04-08 16:51:40 -0400
commit63f6a79bf87cd5960c069bb45c88646519d096f8 (patch)
treeb178330610fe4b5844e7db0d253e881cf5f4822f /tests
parenta63308be0a66fe34aa1ccefef76fa6a0bc50d2a3 (diff)
Don't lint various match lints when expanded by a proc-macro
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/auxiliary/proc_macro_with_span.rs32
-rw-r--r--tests/ui/single_match_else.rs18
-rw-r--r--tests/ui/single_match_else.stderr11
3 files changed, 54 insertions, 7 deletions
diff --git a/tests/ui/auxiliary/proc_macro_with_span.rs b/tests/ui/auxiliary/proc_macro_with_span.rs
new file mode 100644
index 00000000000..8ea631f2bbd
--- /dev/null
+++ b/tests/ui/auxiliary/proc_macro_with_span.rs
@@ -0,0 +1,32 @@
+// compile-flags: --emit=link
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{token_stream::IntoIter, Group, Span, TokenStream, TokenTree};
+
+#[proc_macro]
+pub fn with_span(input: TokenStream) -> TokenStream {
+    let mut iter = input.into_iter();
+    let span = iter.next().unwrap().span();
+    let mut res = TokenStream::new();
+    write_with_span(span, iter, &mut res);
+    res
+}
+
+fn write_with_span(s: Span, input: IntoIter, out: &mut TokenStream) {
+    for mut tt in input {
+        if let TokenTree::Group(g) = tt {
+            let mut stream = TokenStream::new();
+            write_with_span(s, g.stream().into_iter(), &mut stream);
+            let mut group = Group::new(g.delimiter(), stream);
+            group.set_span(s);
+            out.extend([TokenTree::Group(group)]);
+        } else {
+            tt.set_span(s);
+            out.extend([tt]);
+        }
+    }
+}
diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs
index b624a41a29b..82387f3d80b 100644
--- a/tests/ui/single_match_else.rs
+++ b/tests/ui/single_match_else.rs
@@ -1,7 +1,12 @@
+// aux-build: proc_macro_with_span.rs
+
 #![warn(clippy::single_match_else)]
 #![allow(clippy::needless_return)]
 #![allow(clippy::no_effect)]
 
+extern crate proc_macro_with_span;
+use proc_macro_with_span::with_span;
+
 enum ExprNode {
     ExprAddrOf,
     Butterflies,
@@ -11,13 +16,22 @@ enum ExprNode {
 static NODE: ExprNode = ExprNode::Unicorns;
 
 fn unwrap_addr() -> Option<&'static ExprNode> {
-    match ExprNode::Butterflies {
+    let _ = match ExprNode::Butterflies {
         ExprNode::ExprAddrOf => Some(&NODE),
         _ => {
             let x = 5;
             None
         },
-    }
+    };
+
+    // Don't lint
+    with_span!(span match ExprNode::Butterflies {
+        ExprNode::ExprAddrOf => Some(&NODE),
+        _ => {
+            let x = 5;
+            None
+        },
+    })
 }
 
 macro_rules! unwrap_addr {
diff --git a/tests/ui/single_match_else.stderr b/tests/ui/single_match_else.stderr
index 21ea704b62a..7756c6f204e 100644
--- a/tests/ui/single_match_else.stderr
+++ b/tests/ui/single_match_else.stderr
@@ -1,22 +1,23 @@
 error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
-  --> $DIR/single_match_else.rs:14:5
+  --> $DIR/single_match_else.rs:19:13
    |
-LL | /     match ExprNode::Butterflies {
+LL |       let _ = match ExprNode::Butterflies {
+   |  _____________^
 LL | |         ExprNode::ExprAddrOf => Some(&NODE),
 LL | |         _ => {
 LL | |             let x = 5;
 LL | |             None
 LL | |         },
-LL | |     }
+LL | |     };
    | |_____^
    |
    = note: `-D clippy::single-match-else` implied by `-D warnings`
 help: try this
    |
-LL ~     if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else {
+LL ~     let _ = if let ExprNode::ExprAddrOf = ExprNode::Butterflies { Some(&NODE) } else {
 LL +         let x = 5;
 LL +         None
-LL +     }
+LL ~     };
    |
 
 error: aborting due to previous error