about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-02-25 12:08:43 +0000
committerbors <bors@rust-lang.org>2019-02-25 12:08:43 +0000
commitcd29740e6ece9bc5a99a72b987e8e6e39e67fc72 (patch)
treee8b579400e9a3df123db8efc134b2ec603841a82
parent1233b39ca915c65131c6e404c24e69ab80bf5e0c (diff)
parent391ee7987dca6c5ca9ea32a4d8dfd28586d4c89a (diff)
downloadrust-cd29740e6ece9bc5a99a72b987e8e6e39e67fc72.tar.gz
rust-cd29740e6ece9bc5a99a72b987e8e6e39e67fc72.zip
Auto merge of #3805 - martinsp:ice-3747, r=Manishearth
Fix ICE #3747

I'm not sure if this was the correct approach.

I don't know if I put tests/ui/crashses/ice-3747.rs in correct place because the test always passed when I ran it with `cargo test`, even without the fix applied.

If I run that test with `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug tests/ui/crashes/ice-3747.rs` then the test correctly fails without the fix applied

fixes #3747
-rw-r--r--clippy_lints/src/functions.rs6
-rw-r--r--tests/ui/crashes/ice-3747.rs17
2 files changed, 20 insertions, 3 deletions
diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs
index 53703ef9bce..3b15f2760c1 100644
--- a/clippy_lints/src/functions.rs
+++ b/clippy_lints/src/functions.rs
@@ -152,7 +152,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
 
         let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
         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) {
@@ -183,12 +183,12 @@ impl<'a, 'tcx> Functions {
         }
     }
 
-    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
index 00000000000..cdf018cbc88
--- /dev/null
+++ b/tests/ui/crashes/ice-3747.rs
@@ -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() {}