about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/inconsistent_struct_constructor.rs2
-rw-r--r--tests/ui/inconsistent_struct_constructor.fixed13
-rw-r--r--tests/ui/inconsistent_struct_constructor.rs13
-rw-r--r--tests/ui/inconsistent_struct_constructor.stderr4
4 files changed, 30 insertions, 2 deletions
diff --git a/clippy_lints/src/inconsistent_struct_constructor.rs b/clippy_lints/src/inconsistent_struct_constructor.rs
index d7ca24487a8..d138c3a8acf 100644
--- a/clippy_lints/src/inconsistent_struct_constructor.rs
+++ b/clippy_lints/src/inconsistent_struct_constructor.rs
@@ -1,4 +1,5 @@
 use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::in_macro;
 use clippy_utils::source::snippet;
 use if_chain::if_chain;
 use rustc_data_structures::fx::FxHashMap;
@@ -66,6 +67,7 @@ declare_lint_pass!(InconsistentStructConstructor => [INCONSISTENT_STRUCT_CONSTRU
 impl LateLintPass<'_> for InconsistentStructConstructor {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
         if_chain! {
+            if !in_macro(expr.span);
             if let ExprKind::Struct(qpath, fields, base) = expr.kind;
             let ty = cx.typeck_results().expr_ty(expr);
             if let Some(adt_def) = ty.ty_adt_def();
diff --git a/tests/ui/inconsistent_struct_constructor.fixed b/tests/ui/inconsistent_struct_constructor.fixed
index 8d9c3110035..d1025743790 100644
--- a/tests/ui/inconsistent_struct_constructor.fixed
+++ b/tests/ui/inconsistent_struct_constructor.fixed
@@ -13,6 +13,15 @@ struct Foo {
     z: i32,
 }
 
+macro_rules! new_foo {
+    () => {
+        let x = 1;
+        let y = 1;
+        let z = 1;
+        Foo { y, x, z }
+    };
+}
+
 mod without_base {
     use super::Foo;
 
@@ -24,6 +33,10 @@ mod without_base {
         // Should lint.
         Foo { x, y, z };
 
+        // Should NOT lint.
+        // issue #7069.
+        new_foo!();
+
         // Shoule NOT lint because the order is the same as in the definition.
         Foo { x, y, z };
 
diff --git a/tests/ui/inconsistent_struct_constructor.rs b/tests/ui/inconsistent_struct_constructor.rs
index 63fac910501..b095aa64a21 100644
--- a/tests/ui/inconsistent_struct_constructor.rs
+++ b/tests/ui/inconsistent_struct_constructor.rs
@@ -13,6 +13,15 @@ struct Foo {
     z: i32,
 }
 
+macro_rules! new_foo {
+    () => {
+        let x = 1;
+        let y = 1;
+        let z = 1;
+        Foo { y, x, z }
+    };
+}
+
 mod without_base {
     use super::Foo;
 
@@ -24,6 +33,10 @@ mod without_base {
         // Should lint.
         Foo { y, x, z };
 
+        // Should NOT lint.
+        // issue #7069.
+        new_foo!();
+
         // Shoule NOT lint because the order is the same as in the definition.
         Foo { x, y, z };
 
diff --git a/tests/ui/inconsistent_struct_constructor.stderr b/tests/ui/inconsistent_struct_constructor.stderr
index d021bb19579..ef308dedb16 100644
--- a/tests/ui/inconsistent_struct_constructor.stderr
+++ b/tests/ui/inconsistent_struct_constructor.stderr
@@ -1,5 +1,5 @@
 error: struct constructor field order is inconsistent with struct definition field order
-  --> $DIR/inconsistent_struct_constructor.rs:25:9
+  --> $DIR/inconsistent_struct_constructor.rs:34:9
    |
 LL |         Foo { y, x, z };
    |         ^^^^^^^^^^^^^^^ help: try: `Foo { x, y, z }`
@@ -7,7 +7,7 @@ LL |         Foo { y, x, z };
    = note: `-D clippy::inconsistent-struct-constructor` implied by `-D warnings`
 
 error: struct constructor field order is inconsistent with struct definition field order
-  --> $DIR/inconsistent_struct_constructor.rs:43:9
+  --> $DIR/inconsistent_struct_constructor.rs:56:9
    |
 LL | /         Foo {
 LL | |             z,