- if path.segments.last().expect(SEGMENTS_MSG).ident.name != kw::SelfUpper {
- if self.item_path.res == path.res {
- span_use_self_lint(self.cx, path, None);
- } else if let Res::Def(DefKind::Ctor(def::CtorOf::Struct, _), ctor_def_id) = path.res {
- if self.item_path.res.opt_def_id() == self.cx.tcx.parent(ctor_def_id) {
- span_use_self_lint(self.cx, path, None);
- }
- }
- }
+ walk_ty(self, hir_ty)
+ }
+
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
+ NestedVisitorMap::None
+ }
+}
+
+fn span_lint(cx: &LateContext<'_>, span: Span) {
+ span_lint_and_sugg(
+ cx,
+ USE_SELF,
+ span,
+ "unnecessary structure name repetition",
+ "use the applicable keyword",
+ "Self".to_owned(),
+ Applicability::MachineApplicable,
+ );
+}
+
+#[allow(clippy::cast_possible_truncation)]
+fn span_lint_until_last_segment(cx: &LateContext<'_>, span: Span, segment: &PathSegment<'_>) {
+ let sp = span.with_hi(segment.ident.span.lo());
+ // remove the trailing ::
+ let span_without_last_segment = match snippet_opt(cx, sp) {
+ Some(snippet) => match snippet.rfind("::") {
+ Some(bidx) => sp.with_hi(sp.lo() + BytePos(bidx as u32)),
+ None => sp,
+ },
+ None => sp,
+ };
+ span_lint(cx, span_without_last_segment);
+}
+
+fn span_lint_on_path_until_last_segment(cx: &LateContext<'_>, path: &Path<'_>) {
+ if path.segments.len() > 1 {
+ span_lint_until_last_segment(cx, path.span, path.segments.last().unwrap());
+ }
+}
+
+fn span_lint_on_qpath_resolved(cx: &LateContext<'_>, qpath: &QPath<'_>, until_last_segment: bool) {
+ if let QPath::Resolved(_, path) = qpath {
+ if until_last_segment {
+ span_lint_on_path_until_last_segment(cx, path);
+ } else {
+ span_lint(cx, path.span);