]> git.lizzy.rs Git - rust.git/commitdiff
Fix ICE #3747
authorMartins Polakovs <martins.polakovs@gmail.com>
Sat, 23 Feb 2019 17:29:30 +0000 (19:29 +0200)
committerMartins Polakovs <martins.polakovs@gmail.com>
Sat, 23 Feb 2019 19:38:16 +0000 (21:38 +0200)
[Martins Polakovs, John Firebaugh]

clippy_lints/src/functions.rs
tests/ui/crashes/ice-3747.rs [new file with mode: 0644]

index b6e0480d986bd493a63e01e4690da7a34fb30ecf..c37f45dd4145f9c52d735e454887188274981be2 100644 (file)
@@ -147,7 +147,7 @@ fn check_fn(
         }
 
         self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
-        self.check_line_number(cx, span);
+        self.check_line_number(cx, span, body);
     }
 
     fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
@@ -178,12 +178,12 @@ fn check_arg_number(self, cx: &LateContext<'_, '_>, decl: &hir::FnDecl, span: Sp
         }
     }
 
-    fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span) {
+    fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span, body: &'tcx hir::Body) {
         if in_external_macro(cx.sess(), span) {
             return;
         }
 
-        let code_snippet = snippet(cx, span, "..");
+        let code_snippet = snippet(cx, body.value.span, "..");
         let mut line_count: u64 = 0;
         let mut in_comment = false;
         let mut code_in_line;
diff --git a/tests/ui/crashes/ice-3747.rs b/tests/ui/crashes/ice-3747.rs
new file mode 100644 (file)
index 0000000..cdf018c
--- /dev/null
@@ -0,0 +1,17 @@
+/// Test for https://github.com/rust-lang/rust-clippy/issues/3747
+
+macro_rules! a {
+    ( $pub:tt $($attr:tt)* ) => {
+        $($attr)* $pub fn say_hello() {}
+    };
+}
+
+macro_rules! b {
+    () => {
+        a! { pub }
+    };
+}
+
+b! {}
+
+fn main() {}