Skip to content

Commit 6680710

Browse files
committed
Auto merge of #6833 - daxpedda:use-self, r=Manishearth
Fix false-positive in `use_self` Fixes #6818. changelog: Fix false positives for use_self in macros.
2 parents d783e3d + 5656510 commit 6680710

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

clippy_lints/src/use_self.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,17 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
262262
// FIXME: this span manipulation should not be necessary
263263
// @flip1995 found an ast lowering issue in
264264
// https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/path.rs#l142-l162
265-
match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_ty.hir_id)) {
266-
Some(Node::Expr(Expr {
267-
kind: ExprKind::Path(QPath::TypeRelative(_, segment)),
268-
..
269-
})) => span_lint_until_last_segment(cx, hir_ty.span, segment),
270-
_ => span_lint(cx, hir_ty.span),
265+
let hir = cx.tcx.hir();
266+
let id = hir.get_parent_node(hir_ty.hir_id);
267+
268+
if !hir.opt_span(id).map(in_macro).unwrap_or(false) {
269+
match hir.find(id) {
270+
Some(Node::Expr(Expr {
271+
kind: ExprKind::Path(QPath::TypeRelative(_, segment)),
272+
..
273+
})) => span_lint_until_last_segment(cx, hir_ty.span, segment),
274+
_ => span_lint(cx, hir_ty.span),
275+
}
271276
}
272277
}
273278
}

tests/ui/use_self.fixed

+7
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,10 @@ mod nested_paths {
454454
}
455455
}
456456
}
457+
458+
mod issue6818 {
459+
#[derive(serde::Deserialize)]
460+
struct A {
461+
a: i32,
462+
}
463+
}

tests/ui/use_self.rs

+7
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,10 @@ mod nested_paths {
454454
}
455455
}
456456
}
457+
458+
mod issue6818 {
459+
#[derive(serde::Deserialize)]
460+
struct A {
461+
a: i32,
462+
}
463+
}

0 commit comments

Comments
 (0)