Skip to content

Commit 13b5ea4

Browse files
committed
Fix automatic suggestion on use_self.
1 parent e648adf commit 13b5ea4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

clippy_lints/src/use_self.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintC
77
use rustc::ty;
88
use rustc::{declare_tool_lint, lint_array};
99
use rustc_errors::Applicability;
10-
use syntax_pos::symbol::keywords::SelfUpper;
10+
use syntax_pos::{symbol::keywords::SelfUpper, Span};
1111

1212
/// **What it does:** Checks for unnecessary repetition of structure name when a
1313
/// replacement with `Self` is applicable.
@@ -55,11 +55,11 @@ impl LintPass for UseSelf {
5555

5656
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
5757

58-
fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path) {
58+
fn span_use_self_lint(cx: &LateContext<'_, '_>, span: Span) {
5959
span_lint_and_sugg(
6060
cx,
6161
USE_SELF,
62-
path.span,
62+
span,
6363
"unnecessary structure name repetition",
6464
"use the applicable keyword",
6565
"Self".to_owned(),
@@ -92,7 +92,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
9292
};
9393

9494
if !is_self_ty {
95-
span_use_self_lint(self.cx, path);
95+
span_use_self_lint(self.cx, path.span);
9696
}
9797
}
9898
}
@@ -221,10 +221,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
221221
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
222222
if path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfUpper.name() {
223223
if self.item_path.def == path.def {
224-
span_use_self_lint(self.cx, path);
224+
span_use_self_lint(self.cx, path.segments.first().expect(SEGMENTS_MSG).ident.span);
225225
} else if let Def::StructCtor(ctor_did, CtorKind::Fn) = path.def {
226226
if self.item_path.def.opt_def_id() == self.cx.tcx.parent_def_id(ctor_did) {
227-
span_use_self_lint(self.cx, path);
227+
span_use_self_lint(self.cx, path.span);
228228
}
229229
}
230230
}

tests/ui/use_self.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error: unnecessary structure name repetition
2222
--> $DIR/use_self.rs:15:13
2323
|
2424
LL | Foo::new()
25-
| ^^^^^^^^ help: use the applicable keyword: `Self`
25+
| ^^^ help: use the applicable keyword: `Self`
2626

2727
error: unnecessary structure name repetition
2828
--> $DIR/use_self.rs:20:25
@@ -34,7 +34,7 @@ error: unnecessary structure name repetition
3434
--> $DIR/use_self.rs:21:13
3535
|
3636
LL | Foo::new()
37-
| ^^^^^^^^ help: use the applicable keyword: `Self`
37+
| ^^^ help: use the applicable keyword: `Self`
3838

3939
error: unnecessary structure name repetition
4040
--> $DIR/use_self.rs:86:22
@@ -100,7 +100,7 @@ error: unnecessary structure name repetition
100100
--> $DIR/use_self.rs:101:13
101101
|
102102
LL | Bad::default()
103-
| ^^^^^^^^^^^^ help: use the applicable keyword: `Self`
103+
| ^^^ help: use the applicable keyword: `Self`
104104

105105
error: unnecessary structure name repetition
106106
--> $DIR/use_self.rs:106:23

0 commit comments

Comments
 (0)