Skip to content

Commit 5d91ead

Browse files
committed
use_self - use snippet_opt
1 parent 506608e commit 5d91ead

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

clippy_lints/src/use_self.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use rustc_middle::hir::map::Map;
1212
use rustc_middle::lint::in_external_macro;
1313
use rustc_middle::ty;
1414
use rustc_middle::ty::Ty;
15-
use rustc_middle::ty::TyCtxt;
1615
use rustc_session::{declare_lint_pass, declare_tool_lint};
1716
use rustc_span::{BytePos, Span};
1817
use rustc_typeck::hir_ty_to_ty;
1918

19+
use crate::utils::snippet_opt;
2020
use crate::utils::span_lint_and_sugg;
2121

2222
declare_clippy_lint! {
@@ -72,7 +72,7 @@ fn span_lint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span) {
7272

7373
fn span_lint_ignore_last_segment<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, path: &'tcx Path<'tcx>) {
7474
if path.segments.len() > 1 {
75-
span_lint(cx, truncate_last_segment(cx.tcx, path.span))
75+
span_lint(cx, truncate_last_segment(cx, path.span))
7676
}
7777
}
7878

@@ -89,13 +89,13 @@ fn span_lint_on_qpath_resolved<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, qpath: &'tc
8989
};
9090
}
9191

92-
fn truncate_last_segment<'tcx>(tcx: TyCtxt<'tcx>, sp: Span) -> Span {
93-
match tcx.sess.source_map().span_to_snippet(sp) {
94-
Ok(snippet) => match snippet.rfind("::") {
92+
fn truncate_last_segment<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, sp: Span) -> Span {
93+
match snippet_opt(cx, sp) {
94+
Some(snippet) => match snippet.rfind("::") {
9595
Some(bidx) => sp.with_hi(sp.lo() + BytePos(bidx as u32)),
9696
None => sp,
9797
},
98-
_ => sp,
98+
None => sp,
9999
}
100100
}
101101

@@ -174,7 +174,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplVisitor<'a, 'tcx> {
174174
// @flip1995 found an ast lowering issue in
175175
// https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/path.rs#L142-L162
176176
{
177-
span_lint(self.cx, truncate_last_segment(self.cx.tcx, hir_ty.span))
177+
span_lint(self.cx, truncate_last_segment(self.cx, hir_ty.span))
178178
},
179179
_ => span_lint(self.cx, hir_ty.span),
180180
}

0 commit comments

Comments
 (0)