@@ -12,11 +12,11 @@ use rustc_middle::hir::map::Map;
12
12
use rustc_middle:: lint:: in_external_macro;
13
13
use rustc_middle:: ty;
14
14
use rustc_middle:: ty:: Ty ;
15
- use rustc_middle:: ty:: TyCtxt ;
16
15
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
17
16
use rustc_span:: { BytePos , Span } ;
18
17
use rustc_typeck:: hir_ty_to_ty;
19
18
19
+ use crate :: utils:: snippet_opt;
20
20
use crate :: utils:: span_lint_and_sugg;
21
21
22
22
declare_clippy_lint ! {
@@ -72,7 +72,7 @@ fn span_lint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span) {
72
72
73
73
fn span_lint_ignore_last_segment < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , path : & ' tcx Path < ' tcx > ) {
74
74
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 ) )
76
76
}
77
77
}
78
78
@@ -89,13 +89,13 @@ fn span_lint_on_qpath_resolved<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, qpath: &'tc
89
89
} ;
90
90
}
91
91
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 ( "::" ) {
95
95
Some ( bidx) => sp. with_hi ( sp. lo ( ) + BytePos ( bidx as u32 ) ) ,
96
96
None => sp,
97
97
} ,
98
- _ => sp,
98
+ None => sp,
99
99
}
100
100
}
101
101
@@ -174,7 +174,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ImplVisitor<'a, 'tcx> {
174
174
// @flip1995 found an ast lowering issue in
175
175
// https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/path.rs#L142-L162
176
176
{
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 ) )
178
178
} ,
179
179
_ => span_lint ( self . cx , hir_ty. span ) ,
180
180
}
0 commit comments