about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2024-03-02 22:42:13 +0800
committeryukang <moorekang@gmail.com>2024-03-02 23:15:39 +0800
commit5a5c6dfb33ec9f17416ac96ca66554a033ecd387 (patch)
tree78cef499e2ae9fff0c4921b7fb137142a2c6b7e8 /tests
parente612d079a1102803fd2cae5dcd7f7f277e493b8e (diff)
Fix misleading message when using a named constant as a struct alignment/pack
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/attributes/arg-error-issue-121425.rs32
-rw-r--r--tests/ui/attributes/arg-error-issue-121425.stderr40
-rw-r--r--tests/ui/attributes/nonterminal-expansion.rs4
-rw-r--r--tests/ui/attributes/nonterminal-expansion.stderr13
4 files changed, 79 insertions, 10 deletions
diff --git a/tests/ui/attributes/arg-error-issue-121425.rs b/tests/ui/attributes/arg-error-issue-121425.rs
new file mode 100644
index 00000000000..47b85fa1400
--- /dev/null
+++ b/tests/ui/attributes/arg-error-issue-121425.rs
@@ -0,0 +1,32 @@
+//@ compile-flags: -Zdeduplicate-diagnostics=yes
+
+const N: usize = 8;
+#[repr(align(N))]
+//~^ ERROR: incorrect `repr(align)` attribute format
+struct T;
+
+#[repr(align('a'))]
+//~^ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer [E0589]
+struct H;
+
+#[repr(align("str"))]
+//~^ ERROR: invalid `repr(align)` attribute: not an unsuffixed integer [E0589]
+struct L;
+
+#[repr(align())]
+//~^ ERROR: attribute format: `align` takes exactly one argument in parentheses
+struct X;
+
+const P: usize = 8;
+#[repr(packed(P))]
+//~^ ERROR: attribute format: `packed` expect a literal integer as argument
+struct A;
+
+#[repr(packed())]
+//~^ ERROR: attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
+struct B;
+
+#[repr(packed)]
+struct C;
+
+fn main() {}
diff --git a/tests/ui/attributes/arg-error-issue-121425.stderr b/tests/ui/attributes/arg-error-issue-121425.stderr
new file mode 100644
index 00000000000..10f3f3c0b8f
--- /dev/null
+++ b/tests/ui/attributes/arg-error-issue-121425.stderr
@@ -0,0 +1,40 @@
+error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
+  --> $DIR/arg-error-issue-121425.rs:4:14
+   |
+LL | #[repr(align(N))]
+   |              ^
+
+error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
+  --> $DIR/arg-error-issue-121425.rs:8:8
+   |
+LL | #[repr(align('a'))]
+   |        ^^^^^^^^^^
+
+error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
+  --> $DIR/arg-error-issue-121425.rs:12:8
+   |
+LL | #[repr(align("str"))]
+   |        ^^^^^^^^^^^^
+
+error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
+  --> $DIR/arg-error-issue-121425.rs:16:8
+   |
+LL | #[repr(align())]
+   |        ^^^^^^^
+
+error[E0552]: incorrect `repr(packed)` attribute format: `packed` expect a literal integer as argument
+  --> $DIR/arg-error-issue-121425.rs:21:15
+   |
+LL | #[repr(packed(P))]
+   |               ^
+
+error[E0552]: incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
+  --> $DIR/arg-error-issue-121425.rs:25:8
+   |
+LL | #[repr(packed())]
+   |        ^^^^^^^^
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0552, E0589, E0693.
+For more information about an error, try `rustc --explain E0552`.
diff --git a/tests/ui/attributes/nonterminal-expansion.rs b/tests/ui/attributes/nonterminal-expansion.rs
index 97bf225f0cc..decf3ec8185 100644
--- a/tests/ui/attributes/nonterminal-expansion.rs
+++ b/tests/ui/attributes/nonterminal-expansion.rs
@@ -1,10 +1,11 @@
+//@ compile-flags: -Zdeduplicate-diagnostics=yes
+
 // Macros were previously expanded in `Expr` nonterminal tokens, now they are not.
 
 macro_rules! pass_nonterminal {
     ($n:expr) => {
         #[repr(align($n))]
         //~^ ERROR expected unsuffixed literal or identifier, found `n!()`
-        //~| ERROR incorrect `repr(align)` attribute format
         struct S;
     };
 }
@@ -14,5 +15,6 @@ macro_rules! n {
 }
 
 pass_nonterminal!(n!());
+//~^ ERROR incorrect `repr(align)` attribute format: `align` expect a literal integer as argument [E0693]
 
 fn main() {}
diff --git a/tests/ui/attributes/nonterminal-expansion.stderr b/tests/ui/attributes/nonterminal-expansion.stderr
index 52376ac1911..4d995eee5ac 100644
--- a/tests/ui/attributes/nonterminal-expansion.stderr
+++ b/tests/ui/attributes/nonterminal-expansion.stderr
@@ -1,5 +1,5 @@
 error: expected unsuffixed literal or identifier, found `n!()`
-  --> $DIR/nonterminal-expansion.rs:5:22
+  --> $DIR/nonterminal-expansion.rs:7:22
    |
 LL |         #[repr(align($n))]
    |                      ^^
@@ -9,16 +9,11 @@ LL | pass_nonterminal!(n!());
    |
    = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
-  --> $DIR/nonterminal-expansion.rs:5:16
+error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
+  --> $DIR/nonterminal-expansion.rs:17:19
    |
-LL |         #[repr(align($n))]
-   |                ^^^^^^^^^
-...
 LL | pass_nonterminal!(n!());
-   | ----------------------- in this macro invocation
-   |
-   = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
+   |                   ^
 
 error: aborting due to 2 previous errors