diff options
| author | daxpedda <daxpedda@gmail.com> | 2021-03-03 17:32:49 +0100 |
|---|---|---|
| committer | daxpedda <daxpedda@gmail.com> | 2021-03-03 17:32:49 +0100 |
| commit | 5656510eed663b5d5be6b6df3d033b836da5f759 (patch) | |
| tree | 9432952ac9168e9d1fb34516f3636ac7c7bb62c8 | |
| parent | 43d19f63f7c6007284387e76cfe0fe8b74e98a59 (diff) | |
| download | rust-5656510eed663b5d5be6b6df3d033b836da5f759.tar.gz rust-5656510eed663b5d5be6b6df3d033b836da5f759.zip | |
Fix false-positive in `use_self`
| -rw-r--r-- | clippy_lints/src/use_self.rs | 17 | ||||
| -rw-r--r-- | tests/ui/use_self.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/use_self.rs | 7 |
3 files changed, 25 insertions, 6 deletions
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index be7b9e9ff2d..c262ec993b1 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -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), + } } } } diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed index 2b22a2ed2d5..a630936e3b1 100644 --- a/tests/ui/use_self.fixed +++ b/tests/ui/use_self.fixed @@ -454,3 +454,10 @@ mod nested_paths { } } } + +mod issue6818 { + #[derive(serde::Deserialize)] + struct A { + a: i32, + } +} diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs index 609625abdec..f3e081dd203 100644 --- a/tests/ui/use_self.rs +++ b/tests/ui/use_self.rs @@ -454,3 +454,10 @@ mod nested_paths { } } } + +mod issue6818 { + #[derive(serde::Deserialize)] + struct A { + a: i32, + } +} |
