Skip to content

Commit ee57446

Browse files
authored
Merge pull request #2711 from phansch/fix_2707
Prevent crash when macro was in different file
2 parents f69dd6a + 5d36edc commit ee57446

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clippy_lints/src/types.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::borrow::Cow;
1212
use syntax::ast::{FloatTy, IntTy, UintTy};
1313
use syntax::codemap::Span;
1414
use syntax::errors::DiagnosticBuilder;
15-
use utils::{comparisons, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
15+
use utils::{comparisons, differing_macro_contexts, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
1616
match_type, multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
1717
span_lint_and_sugg, span_lint_and_then, clip, unsext, sext, int_bits};
1818
use utils::paths;
@@ -1714,6 +1714,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
17141714
vis.visit_ty(ty);
17151715

17161716
for target in &vis.found {
1717+
if differing_macro_contexts(item.span, target.span()) {
1718+
return;
1719+
}
1720+
17171721
let generics_suggestion_span = generics.span.substitute_dummy({
17181722
let pos = snippet_opt(cx, item.span.until(target.span()))
17191723
.and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4)))

tests/auxiliary/test_macro.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub trait A {}
2+
3+
macro_rules! __implicit_hasher_test_macro {
4+
(impl< $($impl_arg:tt),* > for $kind:ty where $($bounds:tt)*) => {
5+
__implicit_hasher_test_macro!( ($($impl_arg),*) ($kind) ($($bounds)*) );
6+
};
7+
8+
(($($impl_arg:tt)*) ($($kind_arg:tt)*) ($($bounds:tt)*)) => {
9+
impl< $($impl_arg)* > test_macro::A for $($kind_arg)* where $($bounds)* { }
10+
};
11+
}

tests/ui/implicit_hasher.rs

+7
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@ macro_rules! gen {
8383
gen!(impl);
8484
gen!(fn bar);
8585

86+
// When the macro is in a different file, the suggestion spans can't be combined properly
87+
// and should not cause an ICE
88+
// See #2707
89+
#[macro_use]
90+
#[path = "../auxiliary/test_macro.rs"] pub mod test_macro;
91+
__implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
92+
8693
fn main() {}

0 commit comments

Comments
 (0)