Skip to content

Commit

Permalink
Auto merge of #6833 - daxpedda:use-self, r=Manishearth
Browse files Browse the repository at this point in the history
Fix false-positive in `use_self`

Fixes  #6818.

changelog: Fix false positives for use_self in macros.
  • Loading branch information
bors committed Mar 4, 2021
2 parents d783e3d + 5656510 commit 6680710
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
17 changes: 11 additions & 6 deletions clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,17 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
// FIXME: this span manipulation should not be necessary
// @flip1995 found an ast lowering issue in
// https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/path.rs#l142-l162
match cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_ty.hir_id)) {
Some(Node::Expr(Expr {
kind: ExprKind::Path(QPath::TypeRelative(_, segment)),
..
})) => span_lint_until_last_segment(cx, hir_ty.span, segment),
_ => span_lint(cx, hir_ty.span),
let hir = cx.tcx.hir();
let id = hir.get_parent_node(hir_ty.hir_id);

if !hir.opt_span(id).map(in_macro).unwrap_or(false) {
match hir.find(id) {
Some(Node::Expr(Expr {
kind: ExprKind::Path(QPath::TypeRelative(_, segment)),
..
})) => span_lint_until_last_segment(cx, hir_ty.span, segment),
_ => span_lint(cx, hir_ty.span),
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/use_self.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,10 @@ mod nested_paths {
}
}
}

mod issue6818 {
#[derive(serde::Deserialize)]
struct A {
a: i32,
}
}
7 changes: 7 additions & 0 deletions tests/ui/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,10 @@ mod nested_paths {
}
}
}

mod issue6818 {
#[derive(serde::Deserialize)]
struct A {
a: i32,
}
}

0 comments on commit 6680710

Please sign in to comment.