diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index 35e154aeaee..941a974a828 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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 { diff --git a/tests/ui/crashes/ice-4727-aux.rs b/tests/ui/crashes/ice-4727-aux.rs new file mode 100644 index 00000000000..952a322e325 --- /dev/null +++ b/tests/ui/crashes/ice-4727-aux.rs @@ -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] + } +} diff --git a/tests/ui/crashes/ice-4727.rs b/tests/ui/crashes/ice-4727.rs new file mode 100644 index 00000000000..d9438492901 --- /dev/null +++ b/tests/ui/crashes/ice-4727.rs @@ -0,0 +1,8 @@ +// run-pass + +#![warn(clippy::use_self)] + +#[path = "ice-4727-aux.rs"] +mod aux; + +fn main() {} diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 90133788526..84a77581abe 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -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] + } + } +} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index e6900b91534..d937f129ad4 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -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] + } + } +} diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr index d1bfb0e230d..f24bb1dfada 100644 --- a/tests/ui/use_self.stderr +++ b/tests/ui/use_self.stderr @@ -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