Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash when macro was in different file #2711

Merged
merged 1 commit into from May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion clippy_lints/src/types.rs
Expand Up @@ -12,7 +12,7 @@ use std::borrow::Cow;
use syntax::ast::{FloatTy, IntTy, UintTy};
use syntax::codemap::Span;
use syntax::errors::DiagnosticBuilder;
use utils::{comparisons, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
use utils::{comparisons, differing_macro_contexts, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
match_type, multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
span_lint_and_sugg, span_lint_and_then, clip, unsext, sext, int_bits};
use utils::paths;
Expand Down Expand Up @@ -1714,6 +1714,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
vis.visit_ty(ty);

for target in &vis.found {
if differing_macro_contexts(item.span, target.span()) {
return;
}

let generics_suggestion_span = generics.span.substitute_dummy({
let pos = snippet_opt(cx, item.span.until(target.span()))
.and_then(|snip| Some(item.span.lo() + BytePos(snip.find("impl")? as u32 + 4)))
Expand Down
11 changes: 11 additions & 0 deletions tests/auxiliary/test_macro.rs
@@ -0,0 +1,11 @@
pub trait A {}

macro_rules! __implicit_hasher_test_macro {
(impl< $($impl_arg:tt),* > for $kind:ty where $($bounds:tt)*) => {
__implicit_hasher_test_macro!( ($($impl_arg),*) ($kind) ($($bounds)*) );
};

(($($impl_arg:tt)*) ($($kind_arg:tt)*) ($($bounds:tt)*)) => {
impl< $($impl_arg)* > test_macro::A for $($kind_arg)* where $($bounds)* { }
};
}
7 changes: 7 additions & 0 deletions tests/ui/implicit_hasher.rs
Expand Up @@ -83,4 +83,11 @@ macro_rules! gen {
gen!(impl);
gen!(fn bar);

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

fn main() {}