+ 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);
+ }
+ }
+}
+
+fn ty_from_hir_id<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Ty<'tcx> {
+ if let Some(Node::Ty(hir_ty)) = cx.tcx.hir().find(hir_id) {
+ hir_ty_to_ty(cx.tcx, hir_ty)
+ } else {
+ unreachable!("This function should only be called with `HirId`s that are for sure `Node::Ty`")
+ }
+}
+
+fn in_impl(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> bool {
+ let map = cx.tcx.hir();
+ let parent = map.get_parent_node(hir_ty.hir_id);
+ if_chain! {
+ if let Some(Node::Item(item)) = map.find(parent);
+ if let ItemKind::Impl { .. } = item.kind;
+ then {
+ true
+ } else {
+ false