Fix crash in use-self lint

Fixes #4727
This commit is contained in:
Michael Wright 2019-11-06 07:13:43 +02:00
parent eae7b997dd
commit a952708b6c
6 changed files with 63 additions and 2 deletions

View file

@ -223,7 +223,7 @@ struct UseSelfVisitor<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
if path.segments.len() >= 2 {
if path.segments.len() >= 2 && !path.segments.iter().any(|p| p.ident.span.is_dummy()) {
let last_but_one = &path.segments[path.segments.len() - 2];
if last_but_one.ident.name != kw::SelfUpper {
let enum_def_id = match path.res {

View file

@ -0,0 +1,13 @@
//ignore-test
// This file is used by the ice-4727 test but isn't itself a test.
//
pub trait Trait {
fn fun(par: &str) -> &str;
}
impl Trait for str {
fn fun(par: &str) -> &str {
&par[0..1]
}
}

View file

@ -0,0 +1,8 @@
// run-pass
#![warn(clippy::use_self)]
#[path = "ice-4727-aux.rs"]
mod aux;
fn main() {}

View file

@ -332,3 +332,17 @@ mod issue3567 {
}
}
}
// Test with paths in ranges
mod paths_in_ranges {
struct S {}
impl S {
const A: usize = 0;
const B: usize = 1;
fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
&p[Self::A..Self::B]
}
}
}

View file

@ -332,3 +332,17 @@ mod issue3567 {
}
}
}
// Test with paths in ranges
mod paths_in_ranges {
struct S {}
impl S {
const A: usize = 0;
const B: usize = 1;
fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
&p[S::A..S::B]
}
}
}

View file

@ -222,5 +222,17 @@ error: unnecessary structure name repetition
LL | TestStruct::from_something()
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
error: aborting due to 36 previous errors
error: unnecessary structure name repetition
--> $DIR/use_self.rs:345:16
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:345:22
|
LL | &p[S::A..S::B]
| ^ help: use the applicable keyword: `Self`
error: aborting due to 38 previous errors