Fix automatic suggestion on `use_self`.

This commit is contained in:
daxpedda 2019-01-20 14:50:26 +01:00
parent e648adf086
commit 13b5ea4223
No known key found for this signature in database
GPG Key ID: C722DCB6A191EEAB
2 changed files with 9 additions and 9 deletions

View File

@ -7,7 +7,7 @@ use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintC
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax_pos::symbol::keywords::SelfUpper;
use syntax_pos::{symbol::keywords::SelfUpper, Span};
/// **What it does:** Checks for unnecessary repetition of structure name when a
/// replacement with `Self` is applicable.
@ -55,11 +55,11 @@ impl LintPass for UseSelf {
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path) {
fn span_use_self_lint(cx: &LateContext<'_, '_>, span: Span) {
span_lint_and_sugg(
cx,
USE_SELF,
path.span,
span,
"unnecessary structure name repetition",
"use the applicable keyword",
"Self".to_owned(),
@ -92,7 +92,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
};
if !is_self_ty {
span_use_self_lint(self.cx, path);
span_use_self_lint(self.cx, path.span);
}
}
}
@ -221,10 +221,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
if path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfUpper.name() {
if self.item_path.def == path.def {
span_use_self_lint(self.cx, path);
span_use_self_lint(self.cx, path.segments.first().expect(SEGMENTS_MSG).ident.span);
} else if let Def::StructCtor(ctor_did, CtorKind::Fn) = path.def {
if self.item_path.def.opt_def_id() == self.cx.tcx.parent_def_id(ctor_did) {
span_use_self_lint(self.cx, path);
span_use_self_lint(self.cx, path.span);
}
}
}

View File

@ -22,7 +22,7 @@ error: unnecessary structure name repetition
--> $DIR/use_self.rs:15:13
|
LL | Foo::new()
| ^^^^^^^^ help: use the applicable keyword: `Self`
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:20:25
@ -34,7 +34,7 @@ error: unnecessary structure name repetition
--> $DIR/use_self.rs:21:13
|
LL | Foo::new()
| ^^^^^^^^ help: use the applicable keyword: `Self`
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:86:22
@ -100,7 +100,7 @@ error: unnecessary structure name repetition
--> $DIR/use_self.rs:101:13
|
LL | Bad::default()
| ^^^^^^^^^^^^ help: use the applicable keyword: `Self`
| ^^^ help: use the applicable keyword: `Self`
error: unnecessary structure name repetition
--> $DIR/use_self.rs:106:23