Skip to content

Commit 778ace3

Browse files
committed
Auto merge of #4671 - flip1995:ice-4671, r=phansch
Fix ICE in `use_self` lint The ICE is produced by building this span: https://github.com/rust-lang/rust-clippy/blob/55e7818a06c8d83bead9c81e10e73ba33fb20890/clippy_lints/src/use_self.rs#L55-L60 `span` can start in the file the macro is defined in and end where the macro is called. changelog: Fix ICE in `use_self` lint
2 parents 55e7818 + 2f10807 commit 778ace3

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

.travis.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ matrix:
5656
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
5757
- env: INTEGRATION=rust-lang-nursery/chalk
5858
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
59-
# - env: INTEGRATION=rust-lang/rls
60-
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
59+
- env: INTEGRATION=rust-lang/rls
60+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6161
- env: INTEGRATION=Geal/nom
6262
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6363
- env: INTEGRATION=rust-lang/rustfmt
6464
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
65-
# - env: INTEGRATION=hyperium/hyper
66-
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
65+
- env: INTEGRATION=hyperium/hyper
66+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6767
- env: INTEGRATION=bluss/rust-itertools
6868
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6969
- env: INTEGRATION=serde-rs/serde
@@ -72,8 +72,8 @@ matrix:
7272
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7373
- env: INTEGRATION=rust-random/rand
7474
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75-
# - env: INTEGRATION=rust-lang-nursery/futures-rs
76-
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
75+
- env: INTEGRATION=rust-lang-nursery/futures-rs
76+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7777
- env: INTEGRATION=Marwes/combine
7878
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7979
- env: INTEGRATION=rust-lang-nursery/failure

clippy_lints/src/use_self.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1010
use rustc_errors::Applicability;
1111
use syntax_pos::symbol::kw;
1212

13-
use crate::utils::span_lint_and_sugg;
13+
use crate::utils::{differing_macro_contexts, span_lint_and_sugg};
1414

1515
declare_clippy_lint! {
1616
/// **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
5656

5757
// Path segments only include actual path, no methods or fields.
5858
let last_path_span = last_segment.ident.span;
59+
60+
if differing_macro_contexts(path.span, last_path_span) {
61+
return;
62+
}
63+
5964
// Only take path up to the end of last_path_span.
6065
let span = path.span.with_hi(last_path_span.hi());
6166

tests/ui/auxiliary/use_self_macro.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
macro_rules! use_self {
2+
(
3+
impl $ty:ident {
4+
fn func(&$this:ident) {
5+
[fields($($field:ident)*)]
6+
}
7+
}
8+
) => (
9+
impl $ty {
10+
fn func(&$this) {
11+
let $ty { $($field),* } = $this;
12+
}
13+
}
14+
)
15+
}

tests/ui/ice-4671.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![warn(clippy::use_self)]
2+
3+
#[macro_use]
4+
#[path = "auxiliary/use_self_macro.rs"]
5+
mod use_self_macro;
6+
7+
struct Foo {
8+
a: u32,
9+
}
10+
11+
use_self! {
12+
impl Foo {
13+
fn func(&self) {
14+
[fields(
15+
a
16+
)]
17+
}
18+
}
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)