@@ -7,7 +7,7 @@ use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintC
7
7
use rustc:: ty;
8
8
use rustc:: { declare_tool_lint, lint_array} ;
9
9
use rustc_errors:: Applicability ;
10
- use syntax_pos:: { symbol:: keywords:: SelfUpper , Span } ;
10
+ use syntax_pos:: symbol:: keywords:: SelfUpper ;
11
11
12
12
/// **What it does:** Checks for unnecessary repetition of structure name when a
13
13
/// replacement with `Self` is applicable.
@@ -55,7 +55,13 @@ impl LintPass for UseSelf {
55
55
56
56
const SEGMENTS_MSG : & str = "segments should be composed of at least 1 element" ;
57
57
58
- fn span_use_self_lint ( cx : & LateContext < ' _ , ' _ > , span : Span ) {
58
+ fn span_use_self_lint ( cx : & LateContext < ' _ , ' _ > , path : & Path ) {
59
+ // path segments only include actual path, no methods or fields
60
+ let last_path_span = path. segments . last ( ) . expect ( SEGMENTS_MSG ) . ident . span ;
61
+ // `to()` doesn't shorten span, so we shorten it with `until(..)`
62
+ // and then include it with `to(..)`
63
+ let span = path. span . until ( last_path_span) . to ( last_path_span) ;
64
+
59
65
span_lint_and_sugg (
60
66
cx,
61
67
USE_SELF ,
@@ -92,7 +98,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
92
98
} ;
93
99
94
100
if !is_self_ty {
95
- span_use_self_lint ( self . cx , path. span ) ;
101
+ span_use_self_lint ( self . cx , path) ;
96
102
}
97
103
}
98
104
}
@@ -221,10 +227,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
221
227
fn visit_path ( & mut self , path : & ' tcx Path , _id : HirId ) {
222
228
if path. segments . last ( ) . expect ( SEGMENTS_MSG ) . ident . name != SelfUpper . name ( ) {
223
229
if self . item_path . def == path. def {
224
- span_use_self_lint ( self . cx , path. segments . first ( ) . expect ( SEGMENTS_MSG ) . ident . span ) ;
230
+ span_use_self_lint ( self . cx , path) ;
225
231
} else if let Def :: StructCtor ( ctor_did, CtorKind :: Fn ) = path. def {
226
232
if self . item_path . def . opt_def_id ( ) == self . cx . tcx . parent_def_id ( ctor_did) {
227
- span_use_self_lint ( self . cx , path. span ) ;
233
+ span_use_self_lint ( self . cx , path) ;
228
234
}
229
235
}
230
236
}
0 commit comments