@@ -7,7 +7,7 @@ use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintC
77use rustc:: ty;
88use rustc:: { declare_tool_lint, lint_array} ;
99use rustc_errors:: Applicability ;
10- use syntax_pos:: { symbol:: keywords:: SelfUpper , Span } ;
10+ use syntax_pos:: symbol:: keywords:: SelfUpper ;
1111
1212/// **What it does:** Checks for unnecessary repetition of structure name when a
1313/// replacement with `Self` is applicable.
@@ -55,7 +55,13 @@ impl LintPass for UseSelf {
5555
5656const SEGMENTS_MSG : & str = "segments should be composed of at least 1 element" ;
5757
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+
5965 span_lint_and_sugg (
6066 cx,
6167 USE_SELF ,
@@ -92,7 +98,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
9298 } ;
9399
94100 if !is_self_ty {
95- span_use_self_lint ( self . cx , path. span ) ;
101+ span_use_self_lint ( self . cx , path) ;
96102 }
97103 }
98104 }
@@ -221,10 +227,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
221227 fn visit_path ( & mut self , path : & ' tcx Path , _id : HirId ) {
222228 if path. segments . last ( ) . expect ( SEGMENTS_MSG ) . ident . name != SelfUpper . name ( ) {
223229 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) ;
225231 } else if let Def :: StructCtor ( ctor_did, CtorKind :: Fn ) = path. def {
226232 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) ;
228234 }
229235 }
230236 }
0 commit comments