From 2d6adb94244829ba8612211ba2936bf909538d6d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 15 Oct 2019 14:57:54 +0200 Subject: [PATCH 1/3] Add regression test for ICE in use-self lint --- tests/ui/auxiliary/use_self_macro.rs | 15 +++++++++++++++ tests/ui/ice-4671.rs | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/auxiliary/use_self_macro.rs create mode 100644 tests/ui/ice-4671.rs diff --git a/tests/ui/auxiliary/use_self_macro.rs b/tests/ui/auxiliary/use_self_macro.rs new file mode 100644 index 00000000000..a8a85b4baef --- /dev/null +++ b/tests/ui/auxiliary/use_self_macro.rs @@ -0,0 +1,15 @@ +macro_rules! use_self { + ( + impl $ty:ident { + fn func(&$this:ident) { + [fields($($field:ident)*)] + } + } + ) => ( + impl $ty { + fn func(&$this) { + let $ty { $($field),* } = $this; + } + } + ) +} diff --git a/tests/ui/ice-4671.rs b/tests/ui/ice-4671.rs new file mode 100644 index 00000000000..64e8e776941 --- /dev/null +++ b/tests/ui/ice-4671.rs @@ -0,0 +1,21 @@ +#![warn(clippy::use_self)] + +#[macro_use] +#[path = "auxiliary/use_self_macro.rs"] +mod use_self_macro; + +struct Foo { + a: u32, +} + +use_self! { + impl Foo { + fn func(&self) { + [fields( + a + )] + } + } +} + +fn main() {} From c9dc2b5f6e6e327bb5dbc98e94dc02ad39a6ff29 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 15 Oct 2019 15:11:29 +0200 Subject: [PATCH 2/3] Fix ICE in use_self lint --- clippy_lints/src/use_self.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index b0925737702..35e154aeaee 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -10,7 +10,7 @@ use rustc_errors::Applicability; use syntax_pos::symbol::kw; -use crate::utils::span_lint_and_sugg; +use crate::utils::{differing_macro_contexts, span_lint_and_sugg}; declare_clippy_lint! { /// **What it does:** Checks for unnecessary repetition of structure name when a @@ -56,6 +56,11 @@ fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path, last_segment: Optio // Path segments only include actual path, no methods or fields. let last_path_span = last_segment.ident.span; + + if differing_macro_contexts(path.span, last_path_span) { + return; + } + // Only take path up to the end of last_path_span. let span = path.span.with_hi(last_path_span.hi()); From 2f108079da42364273dc288aca6eee2d4cf98c4e Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 15 Oct 2019 15:13:09 +0200 Subject: [PATCH 3/3] Enable integration tests again futures-rs, hyper, rls --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8f9c5e8f636..13ffb09a686 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,14 +56,14 @@ matrix: if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang-nursery/chalk if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # - env: INTEGRATION=rust-lang/rls - # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) + - env: INTEGRATION=rust-lang/rls + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=Geal/nom if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang/rustfmt if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # - env: INTEGRATION=hyperium/hyper - # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) + - env: INTEGRATION=hyperium/hyper + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=bluss/rust-itertools if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=serde-rs/serde @@ -72,8 +72,8 @@ matrix: if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-random/rand if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # - env: INTEGRATION=rust-lang-nursery/futures-rs - # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) + - env: INTEGRATION=rust-lang-nursery/futures-rs + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=Marwes/combine if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang-nursery/failure