use rustc::lint::{LintArray, LateLintPass, LateContext, LintPass};
use rustc::hir::*;
use rustc::hir::intravisit::{Visitor, walk_path, NestedVisitorMap};
-use utils::span_lint;
+use utils::span_lint_and_then;
use syntax::ast::NodeId;
+use syntax_pos::symbol::keywords::SelfType;
/// **What it does:** Checks for unnecessary repetition of structure name when a
/// replacement with `Self` is applicable.
declare_lint! {
pub USE_SELF,
Allow,
- "Repetitive struct name usage whereas `Self` is applicable"
+ "Unnecessary structure name repetition whereas `Self` is applicable"
}
#[derive(Copy, Clone, Default)]
if self.item_path.def == path.def &&
path.segments
.last()
- .expect("segments should be composed of at least 1 elemnt")
- .name
- .as_str() != "Self" {
- span_lint(self.cx,
- USE_SELF,
- path.span,
- "repetitive struct name usage. Use `Self` instead.");
+ .expect("segments should be composed of at least 1 element")
+ .name != SelfType.name() {
+ span_lint_and_then(self.cx, USE_SELF, path.span, "unnecessary structure name repetition", |db| {
+ db.span_suggestion(path.span,
+ "use the applicable keyword",
+ "Self".to_owned());
+ });
}
walk_path(self, path);
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:13:21
|
13 | fn new() -> Foo {
- | ^^^
+ | ^^^ help: use the applicable keyword: `Self`
|
= note: `-D use-self` implied by `-D warnings`
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:14:13
|
14 | Foo {}
- | ^^^
+ | ^^^ help: use the applicable keyword: `Self`
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:16:22
|
16 | fn test() -> Foo {
- | ^^^
+ | ^^^ help: use the applicable keyword: `Self`
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:17:13
|
17 | Foo::new()
- | ^^^^^^^^
+ | ^^^^^^^^ help: use the applicable keyword: `Self`
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:22:25
|
22 | fn default() -> Foo {
- | ^^^
+ | ^^^ help: use the applicable keyword: `Self`
-error: repetitive struct name usage. Use `Self` instead.
+error: unnecessary structure name repetition
--> $DIR/use_self.rs:23:13
|
23 | Foo::new()
- | ^^^^^^^^
+ | ^^^^^^^^ help: use the applicable keyword: `Self`
error: aborting due to 6 previous errors