|
1 | 1 | use rustc::lint::{LintArray, LateLintPass, LateContext, LintPass}; |
2 | 2 | use rustc::hir::*; |
3 | 3 | use rustc::hir::intravisit::{Visitor, walk_path, NestedVisitorMap}; |
4 | | -use utils::span_lint; |
| 4 | +use utils::span_lint_and_then; |
5 | 5 | use syntax::ast::NodeId; |
| 6 | +use syntax_pos::symbol::keywords::SelfType; |
6 | 7 |
|
7 | 8 | /// **What it does:** Checks for unnecessary repetition of structure name when a |
8 | 9 | /// replacement with `Self` is applicable. |
@@ -33,7 +34,7 @@ use syntax::ast::NodeId; |
33 | 34 | declare_lint! { |
34 | 35 | pub USE_SELF, |
35 | 36 | Allow, |
36 | | - "Repetitive struct name usage whereas `Self` is applicable" |
| 37 | + "Unnecessary structure name repetition whereas `Self` is applicable" |
37 | 38 | } |
38 | 39 |
|
39 | 40 | #[derive(Copy, Clone, Default)] |
@@ -72,13 +73,13 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> { |
72 | 73 | if self.item_path.def == path.def && |
73 | 74 | path.segments |
74 | 75 | .last() |
75 | | - .expect("segments should be composed of at least 1 elemnt") |
76 | | - .name |
77 | | - .as_str() != "Self" { |
78 | | - span_lint(self.cx, |
79 | | - USE_SELF, |
80 | | - path.span, |
81 | | - "repetitive struct name usage. Use `Self` instead."); |
| 76 | + .expect("segments should be composed of at least 1 element") |
| 77 | + .name != SelfType.name() { |
| 78 | + span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| { |
| 79 | + db.span_suggestion(path.span, |
| 80 | + "use the applicable keyword", |
| 81 | + "Self".to_owned()); |
| 82 | + }); |
82 | 83 | } |
83 | 84 |
|
84 | 85 | walk_path(self, path); |
|
0 commit comments