mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Fix automatic suggestion on use_self.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
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 @@ fn get_lints(&self) -> LintArray {
|
||||
|
||||
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 @@ fn visit_ty(&mut self, t: &'tcx Ty) {
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user