Skip to content

Commit 5d7c24f

Browse files
martinspManishearth
authored andcommitted
Fix ICE #3747
[Martins Polakovs, John Firebaugh]
1 parent 1fac380 commit 5d7c24f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clippy_lints/src/functions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
150150

151151
let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
152152
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
153-
self.check_line_number(cx, span);
153+
self.check_line_number(cx, span, body);
154154
}
155155

156156
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
@@ -181,12 +181,12 @@ impl<'a, 'tcx> Functions {
181181
}
182182
}
183183

184-
fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span) {
184+
fn check_line_number(self, cx: &LateContext<'_, '_>, span: Span, body: &'tcx hir::Body) {
185185
if in_external_macro(cx.sess(), span) {
186186
return;
187187
}
188188

189-
let code_snippet = snippet(cx, span, "..");
189+
let code_snippet = snippet(cx, body.value.span, "..");
190190
let mut line_count: u64 = 0;
191191
let mut in_comment = false;
192192
let mut code_in_line;

tests/ui/crashes/ice-3747.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// Test for https://github.com/rust-lang/rust-clippy/issues/3747
2+
3+
macro_rules! a {
4+
( $pub:tt $($attr:tt)* ) => {
5+
$($attr)* $pub fn say_hello() {}
6+
};
7+
}
8+
9+
macro_rules! b {
10+
() => {
11+
a! { pub }
12+
};
13+
}
14+
15+
b! {}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)