Auto merge of #4671 - flip1995:ice-4671, r=phansch
Fix ICE in `use_self` lint
The ICE is produced by building this span:
55e7818a06/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
This commit is contained in:
commit
778ace37e5
12
.travis.yml
12
.travis.yml
@ -56,14 +56,14 @@ matrix:
|
|||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=rust-lang-nursery/chalk
|
- env: INTEGRATION=rust-lang-nursery/chalk
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
# - env: INTEGRATION=rust-lang/rls
|
- env: INTEGRATION=rust-lang/rls
|
||||||
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=Geal/nom
|
- env: INTEGRATION=Geal/nom
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=rust-lang/rustfmt
|
- env: INTEGRATION=rust-lang/rustfmt
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
# - env: INTEGRATION=hyperium/hyper
|
- env: INTEGRATION=hyperium/hyper
|
||||||
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=bluss/rust-itertools
|
- env: INTEGRATION=bluss/rust-itertools
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=serde-rs/serde
|
- env: INTEGRATION=serde-rs/serde
|
||||||
@ -72,8 +72,8 @@ matrix:
|
|||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=rust-random/rand
|
- env: INTEGRATION=rust-random/rand
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
# - env: INTEGRATION=rust-lang-nursery/futures-rs
|
- env: INTEGRATION=rust-lang-nursery/futures-rs
|
||||||
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=Marwes/combine
|
- env: INTEGRATION=Marwes/combine
|
||||||
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
|
||||||
- env: INTEGRATION=rust-lang-nursery/failure
|
- env: INTEGRATION=rust-lang-nursery/failure
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use syntax_pos::symbol::kw;
|
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! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for unnecessary repetition of structure name when a
|
/// **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.
|
// Path segments only include actual path, no methods or fields.
|
||||||
let last_path_span = last_segment.ident.span;
|
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.
|
// Only take path up to the end of last_path_span.
|
||||||
let span = path.span.with_hi(last_path_span.hi());
|
let span = path.span.with_hi(last_path_span.hi());
|
||||||
|
|
||||||
|
15
tests/ui/auxiliary/use_self_macro.rs
Normal file
15
tests/ui/auxiliary/use_self_macro.rs
Normal file
@ -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
tests/ui/ice-4671.rs
Normal file
21
tests/ui/ice-4671.rs
Normal file
@ -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() {}
|
Loading…
Reference in New Issue
Block a user