mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 06:26:55 +00:00
Fix automatic suggestion on use_self
.
This commit is contained in:
parent
e648adf086
commit
13b5ea4223
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user