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

Fix ICE in use_self lint #4671

Merged
merged 3 commits into from
Oct 15, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
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
Expand Down Expand Up @@ -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());

Expand Down
15 changes: 15 additions & 0 deletions tests/ui/auxiliary/use_self_macro.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
)
}
21 changes: 21 additions & 0 deletions tests/ui/ice-4671.rs
Original file line number Diff line number Diff line change
@@ -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() {}