about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-10-23 17:32:04 +0000
committerbors <bors@rust-lang.org>2020-10-23 17:32:04 +0000
commit7bade6ef730cff83f3591479a98916920f66decd (patch)
treeffd6635bae41a124e6ddeb89d0c5bb55fbae3513 /src
parent07a63e6d1fabf3560e8e1e17c1d56b10a06152d9 (diff)
parent57e8fc56852e7728d7160242bf13c3ab6e066bd8 (diff)
downloadrust-7bade6ef730cff83f3591479a98916920f66decd.tar.gz
rust-7bade6ef730cff83f3591479a98916920f66decd.zip
Auto merge of #77015 - davidtwco:check-attr-variant-closure-expr, r=lcnr
passes: `check_attr` on more targets

This PR modifies `check_attr` so that:

- Enum variants are now checked (some attributes would not have been prohibited on variants previously).
- `check_expr_attributes` and `check_stmt_attributes` are removed as `check_attributes` can perform the same checks. This means that codegen attribute errors aren't shown if there are other errors first (e.g. from other attributes, as shown in `src/test/ui/macros/issue-68060.rs` changes below).
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/attr-usage-repr.rs8
-rw-r--r--src/test/ui/attr-usage-repr.stderr8
-rw-r--r--src/test/ui/error-codes/E0517.stderr8
-rw-r--r--src/test/ui/inline-disallow-on-variant.rs7
-rw-r--r--src/test/ui/inline-disallow-on-variant.stderr12
-rw-r--r--src/test/ui/issues/issue-31769.rs2
-rw-r--r--src/test/ui/issues/issue-31769.stderr2
-rw-r--r--src/test/ui/issues/issue-43988.rs10
-rw-r--r--src/test/ui/issues/issue-43988.stderr34
-rw-r--r--src/test/ui/issues/issue-74082.rs4
-rw-r--r--src/test/ui/issues/issue-74082.stderr4
-rw-r--r--src/test/ui/macros/issue-68060.rs3
-rw-r--r--src/test/ui/macros/issue-68060.stderr15
-rw-r--r--src/test/ui/repr/repr-disallow-on-variant.rs9
-rw-r--r--src/test/ui/repr/repr-disallow-on-variant.stderr12
-rw-r--r--src/test/ui/repr/repr-no-niche-inapplicable-to-unions.rs4
-rw-r--r--src/test/ui/repr/repr-no-niche-inapplicable-to-unions.stderr4
-rw-r--r--src/test/ui/repr/repr-transparent-other-items.rs4
-rw-r--r--src/test/ui/repr/repr-transparent-other-items.stderr4
19 files changed, 81 insertions, 73 deletions
diff --git a/src/test/ui/attr-usage-repr.rs b/src/test/ui/attr-usage-repr.rs
index a0b82375e77..8965decc379 100644
--- a/src/test/ui/attr-usage-repr.rs
+++ b/src/test/ui/attr-usage-repr.rs
@@ -1,6 +1,6 @@
 #![feature(repr_simd)]
 
-#[repr(C)] //~ ERROR: attribute should be applied to struct, enum, or union
+#[repr(C)] //~ ERROR: attribute should be applied to a struct, enum, or union
 fn f() {}
 
 #[repr(C)]
@@ -12,7 +12,7 @@ struct SPacked(f64, f64);
 #[repr(simd)]
 struct SSimd(f64, f64);
 
-#[repr(i8)] //~ ERROR: attribute should be applied to enum
+#[repr(i8)] //~ ERROR: attribute should be applied to an enum
 struct SInt(f64, f64);
 
 #[repr(C)]
@@ -21,10 +21,10 @@ enum EExtern { A, B }
 #[repr(align(8))]
 enum EAlign { A, B }
 
-#[repr(packed)] //~ ERROR: attribute should be applied to struct
+#[repr(packed)] //~ ERROR: attribute should be applied to a struct
 enum EPacked { A, B }
 
-#[repr(simd)] //~ ERROR: attribute should be applied to struct
+#[repr(simd)] //~ ERROR: attribute should be applied to a struct
 enum ESimd { A, B }
 
 #[repr(i8)]
diff --git a/src/test/ui/attr-usage-repr.stderr b/src/test/ui/attr-usage-repr.stderr
index 82d80d8d0b1..42f65625a46 100644
--- a/src/test/ui/attr-usage-repr.stderr
+++ b/src/test/ui/attr-usage-repr.stderr
@@ -1,4 +1,4 @@
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/attr-usage-repr.rs:3:8
    |
 LL | #[repr(C)]
@@ -6,7 +6,7 @@ LL | #[repr(C)]
 LL | fn f() {}
    | --------- not a struct, enum, or union
 
-error[E0517]: attribute should be applied to enum
+error[E0517]: attribute should be applied to an enum
   --> $DIR/attr-usage-repr.rs:15:8
    |
 LL | #[repr(i8)]
@@ -14,7 +14,7 @@ LL | #[repr(i8)]
 LL | struct SInt(f64, f64);
    | ---------------------- not an enum
 
-error[E0517]: attribute should be applied to struct or union
+error[E0517]: attribute should be applied to a struct or union
   --> $DIR/attr-usage-repr.rs:24:8
    |
 LL | #[repr(packed)]
@@ -22,7 +22,7 @@ LL | #[repr(packed)]
 LL | enum EPacked { A, B }
    | --------------------- not a struct or union
 
-error[E0517]: attribute should be applied to struct
+error[E0517]: attribute should be applied to a struct
   --> $DIR/attr-usage-repr.rs:27:8
    |
 LL | #[repr(simd)]
diff --git a/src/test/ui/error-codes/E0517.stderr b/src/test/ui/error-codes/E0517.stderr
index 2cfca1724c8..2f90d4d0baa 100644
--- a/src/test/ui/error-codes/E0517.stderr
+++ b/src/test/ui/error-codes/E0517.stderr
@@ -1,4 +1,4 @@
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/E0517.rs:1:8
    |
 LL | #[repr(C)]
@@ -6,7 +6,7 @@ LL | #[repr(C)]
 LL | type Foo = u8;
    | -------------- not a struct, enum, or union
 
-error[E0517]: attribute should be applied to struct or union
+error[E0517]: attribute should be applied to a struct or union
   --> $DIR/E0517.rs:4:8
    |
 LL | #[repr(packed)]
@@ -14,7 +14,7 @@ LL | #[repr(packed)]
 LL | enum Foo2 {Bar, Baz}
    | -------------------- not a struct or union
 
-error[E0517]: attribute should be applied to enum
+error[E0517]: attribute should be applied to an enum
   --> $DIR/E0517.rs:7:8
    |
 LL | #[repr(u8)]
@@ -22,7 +22,7 @@ LL | #[repr(u8)]
 LL | struct Foo3 {bar: bool, baz: bool}
    | ---------------------------------- not an enum
 
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/E0517.rs:10:8
    |
 LL |   #[repr(C)]
diff --git a/src/test/ui/inline-disallow-on-variant.rs b/src/test/ui/inline-disallow-on-variant.rs
new file mode 100644
index 00000000000..d92a4e8cc8d
--- /dev/null
+++ b/src/test/ui/inline-disallow-on-variant.rs
@@ -0,0 +1,7 @@
+enum Foo {
+    #[inline]
+    //~^ ERROR attribute should be applied
+    Variant,
+}
+
+fn main() {}
diff --git a/src/test/ui/inline-disallow-on-variant.stderr b/src/test/ui/inline-disallow-on-variant.stderr
new file mode 100644
index 00000000000..1b176579bbb
--- /dev/null
+++ b/src/test/ui/inline-disallow-on-variant.stderr
@@ -0,0 +1,12 @@
+error[E0518]: attribute should be applied to function or closure
+  --> $DIR/inline-disallow-on-variant.rs:2:5
+   |
+LL |     #[inline]
+   |     ^^^^^^^^^
+LL |
+LL |     Variant,
+   |     ------- not a function or closure
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0518`.
diff --git a/src/test/ui/issues/issue-31769.rs b/src/test/ui/issues/issue-31769.rs
index 45eb5e40080..f56c6ea5656 100644
--- a/src/test/ui/issues/issue-31769.rs
+++ b/src/test/ui/issues/issue-31769.rs
@@ -1,4 +1,4 @@
 fn main() {
     #[inline] struct Foo;  //~ ERROR attribute should be applied to function or closure
-    #[repr(C)] fn foo() {} //~ ERROR attribute should be applied to struct, enum, or union
+    #[repr(C)] fn foo() {} //~ ERROR attribute should be applied to a struct, enum, or union
 }
diff --git a/src/test/ui/issues/issue-31769.stderr b/src/test/ui/issues/issue-31769.stderr
index 20534e1ae82..03e2f931c84 100644
--- a/src/test/ui/issues/issue-31769.stderr
+++ b/src/test/ui/issues/issue-31769.stderr
@@ -4,7 +4,7 @@ error[E0518]: attribute should be applied to function or closure
 LL |     #[inline] struct Foo;
    |     ^^^^^^^^^ ----------- not a function or closure
 
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/issue-31769.rs:3:12
    |
 LL |     #[repr(C)] fn foo() {}
diff --git a/src/test/ui/issues/issue-43988.rs b/src/test/ui/issues/issue-43988.rs
index b80907560c3..4b3a0269bae 100644
--- a/src/test/ui/issues/issue-43988.rs
+++ b/src/test/ui/issues/issue-43988.rs
@@ -13,18 +13,17 @@ fn main() {
 
     #[repr(nothing)]
     let _x = 0;
-    //~^^ ERROR attribute should not be applied to a statement
+    //~^^ ERROR attribute should be applied to a struct, enum, or union
 
     #[repr(something_not_real)]
     loop {
         ()
     };
-    //~^^^^ ERROR attribute should not be applied to an expression
+    //~^^^^ ERROR attribute should be applied to a struct, enum, or union
 
     #[repr]
     let _y = "123";
-    //~^^ ERROR attribute should not be applied to a statement
-    //~| ERROR malformed `repr` attribute
+    //~^^ ERROR malformed `repr` attribute
 
     fn foo() {}
 
@@ -33,6 +32,5 @@ fn main() {
     //~^^ ERROR attribute should be applied to function or closure
 
     let _z = #[repr] 1;
-    //~^ ERROR attribute should not be applied to an expression
-    //~| ERROR malformed `repr` attribute
+    //~^ ERROR malformed `repr` attribute
 }
diff --git a/src/test/ui/issues/issue-43988.stderr b/src/test/ui/issues/issue-43988.stderr
index 37e56168c1d..f1205d447e4 100644
--- a/src/test/ui/issues/issue-43988.stderr
+++ b/src/test/ui/issues/issue-43988.stderr
@@ -5,7 +5,7 @@ LL |     #[repr]
    |     ^^^^^^^ help: must be of the form: `#[repr(C)]`
 
 error: malformed `repr` attribute input
-  --> $DIR/issue-43988.rs:35:14
+  --> $DIR/issue-43988.rs:34:14
    |
 LL |     let _z = #[repr] 1;
    |              ^^^^^^^ help: must be of the form: `#[repr(C)]`
@@ -26,47 +26,33 @@ LL |     #[inline(XYZ)]
 LL |     let _b = 4;
    |     ----------- not a function or closure
 
-error[E0517]: attribute should not be applied to a statement
-  --> $DIR/issue-43988.rs:14:5
+error[E0517]: attribute should be applied to a struct, enum, or union
+  --> $DIR/issue-43988.rs:14:12
    |
 LL |     #[repr(nothing)]
-   |     ^^^^^^^^^^^^^^^^
+   |            ^^^^^^^
 LL |     let _x = 0;
    |     ----------- not a struct, enum, or union
 
-error[E0517]: attribute should not be applied to an expression
-  --> $DIR/issue-43988.rs:18:5
+error[E0517]: attribute should be applied to a struct, enum, or union
+  --> $DIR/issue-43988.rs:18:12
    |
 LL |       #[repr(something_not_real)]
-   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |              ^^^^^^^^^^^^^^^^^^
 LL | /     loop {
 LL | |         ()
 LL | |     };
-   | |_____- not defining a struct, enum, or union
-
-error[E0517]: attribute should not be applied to a statement
-  --> $DIR/issue-43988.rs:24:5
-   |
-LL |     #[repr]
-   |     ^^^^^^^
-LL |     let _y = "123";
-   |     --------------- not a struct, enum, or union
+   | |_____- not a struct, enum, or union
 
 error[E0518]: attribute should be applied to function or closure
-  --> $DIR/issue-43988.rs:31:5
+  --> $DIR/issue-43988.rs:30:5
    |
 LL |     #[inline(ABC)]
    |     ^^^^^^^^^^^^^^
 LL |     foo();
    |     ----- not a function or closure
 
-error[E0517]: attribute should not be applied to an expression
-  --> $DIR/issue-43988.rs:35:14
-   |
-LL |     let _z = #[repr] 1;
-   |              ^^^^^^^ - not defining a struct, enum, or union
-
-error: aborting due to 9 previous errors
+error: aborting due to 7 previous errors
 
 Some errors have detailed explanations: E0517, E0518.
 For more information about an error, try `rustc --explain E0517`.
diff --git a/src/test/ui/issues/issue-74082.rs b/src/test/ui/issues/issue-74082.rs
index 982f8ef0253..e3e400c79d6 100644
--- a/src/test/ui/issues/issue-74082.rs
+++ b/src/test/ui/issues/issue-74082.rs
@@ -1,9 +1,9 @@
 #![allow(dead_code)]
 
-#[repr(i128)] //~ ERROR: attribute should be applied to enum
+#[repr(i128)] //~ ERROR: attribute should be applied to an enum
 struct Foo;
 
-#[repr(u128)] //~ ERROR: attribute should be applied to enum
+#[repr(u128)] //~ ERROR: attribute should be applied to an enum
 struct Bar;
 
 fn main() {}
diff --git a/src/test/ui/issues/issue-74082.stderr b/src/test/ui/issues/issue-74082.stderr
index 08fe415513d..12f5a3b27bb 100644
--- a/src/test/ui/issues/issue-74082.stderr
+++ b/src/test/ui/issues/issue-74082.stderr
@@ -1,4 +1,4 @@
-error[E0517]: attribute should be applied to enum
+error[E0517]: attribute should be applied to an enum
   --> $DIR/issue-74082.rs:3:8
    |
 LL | #[repr(i128)]
@@ -6,7 +6,7 @@ LL | #[repr(i128)]
 LL | struct Foo;
    | ----------- not an enum
 
-error[E0517]: attribute should be applied to enum
+error[E0517]: attribute should be applied to an enum
   --> $DIR/issue-74082.rs:6:8
    |
 LL | #[repr(u128)]
diff --git a/src/test/ui/macros/issue-68060.rs b/src/test/ui/macros/issue-68060.rs
index f82eb338f4c..aa8f578adf6 100644
--- a/src/test/ui/macros/issue-68060.rs
+++ b/src/test/ui/macros/issue-68060.rs
@@ -3,10 +3,7 @@ fn main() {
         .map(
             #[target_feature(enable = "")]
             //~^ ERROR: attribute should be applied to a function
-            //~| ERROR: the feature named `` is not valid for this target
-            //~| NOTE: `` is not valid for this target
             #[track_caller]
-            //~^ ERROR: `#[track_caller]` requires Rust ABI [E0737]
             |_| (),
             //~^ NOTE: not a function
         )
diff --git a/src/test/ui/macros/issue-68060.stderr b/src/test/ui/macros/issue-68060.stderr
index a01c3827bb5..1b58cf9c4ed 100644
--- a/src/test/ui/macros/issue-68060.stderr
+++ b/src/test/ui/macros/issue-68060.stderr
@@ -7,18 +7,5 @@ LL |             #[target_feature(enable = "")]
 LL |             |_| (),
    |             ------ not a function
 
-error: the feature named `` is not valid for this target
-  --> $DIR/issue-68060.rs:4:30
-   |
-LL |             #[target_feature(enable = "")]
-   |                              ^^^^^^^^^^^ `` is not valid for this target
-
-error[E0737]: `#[track_caller]` requires Rust ABI
-  --> $DIR/issue-68060.rs:8:13
-   |
-LL |             #[track_caller]
-   |             ^^^^^^^^^^^^^^^
-
-error: aborting due to 3 previous errors
+error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0737`.
diff --git a/src/test/ui/repr/repr-disallow-on-variant.rs b/src/test/ui/repr/repr-disallow-on-variant.rs
new file mode 100644
index 00000000000..90cad7e647b
--- /dev/null
+++ b/src/test/ui/repr/repr-disallow-on-variant.rs
@@ -0,0 +1,9 @@
+struct Test;
+
+enum Foo {
+    #[repr(u8)]
+    //~^ ERROR attribute should be applied to a struct, enum, or union
+    Variant,
+}
+
+fn main() {}
diff --git a/src/test/ui/repr/repr-disallow-on-variant.stderr b/src/test/ui/repr/repr-disallow-on-variant.stderr
new file mode 100644
index 00000000000..70b45e393fc
--- /dev/null
+++ b/src/test/ui/repr/repr-disallow-on-variant.stderr
@@ -0,0 +1,12 @@
+error[E0517]: attribute should be applied to a struct, enum, or union
+  --> $DIR/repr-disallow-on-variant.rs:4:12
+   |
+LL |     #[repr(u8)]
+   |            ^^
+LL |
+LL |     Variant,
+   |     ------- not a struct, enum, or union
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0517`.
diff --git a/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.rs b/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.rs
index 308634651a3..870eda89c20 100644
--- a/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.rs
+++ b/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.rs
@@ -5,10 +5,10 @@ use std::num::NonZeroU16 as N16;
 
 #[repr(no_niche)]
 pub union Cloaked1 { _A: N16 }
-//~^^ ERROR attribute should be applied to struct or enum [E0517]
+//~^^ ERROR attribute should be applied to a struct or enum [E0517]
 
 #[repr(no_niche)]
 pub union Cloaked2 { _A: N16, _B: (u8, N8) }
-//~^^ ERROR attribute should be applied to struct or enum [E0517]
+//~^^ ERROR attribute should be applied to a struct or enum [E0517]
 
 fn main() { }
diff --git a/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.stderr b/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.stderr
index 4c542c5f0da..9af929d4094 100644
--- a/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.stderr
+++ b/src/test/ui/repr/repr-no-niche-inapplicable-to-unions.stderr
@@ -1,4 +1,4 @@
-error[E0517]: attribute should be applied to struct or enum
+error[E0517]: attribute should be applied to a struct or enum
   --> $DIR/repr-no-niche-inapplicable-to-unions.rs:6:8
    |
 LL | #[repr(no_niche)]
@@ -6,7 +6,7 @@ LL | #[repr(no_niche)]
 LL | pub union Cloaked1 { _A: N16 }
    | ------------------------------ not a struct or enum
 
-error[E0517]: attribute should be applied to struct or enum
+error[E0517]: attribute should be applied to a struct or enum
   --> $DIR/repr-no-niche-inapplicable-to-unions.rs:10:8
    |
 LL | #[repr(no_niche)]
diff --git a/src/test/ui/repr/repr-transparent-other-items.rs b/src/test/ui/repr/repr-transparent-other-items.rs
index c3d772f6266..e537e3e1a63 100644
--- a/src/test/ui/repr/repr-transparent-other-items.rs
+++ b/src/test/ui/repr/repr-transparent-other-items.rs
@@ -1,9 +1,9 @@
 // See also repr-transparent.rs
 
-#[repr(transparent)] //~ ERROR should be applied to struct
+#[repr(transparent)] //~ ERROR should be applied to a struct
 fn cant_repr_this() {}
 
-#[repr(transparent)] //~ ERROR should be applied to struct
+#[repr(transparent)] //~ ERROR should be applied to a struct
 static CANT_REPR_THIS: u32 = 0;
 
 fn main() {}
diff --git a/src/test/ui/repr/repr-transparent-other-items.stderr b/src/test/ui/repr/repr-transparent-other-items.stderr
index 03df3569b42..14e6f13e1ae 100644
--- a/src/test/ui/repr/repr-transparent-other-items.stderr
+++ b/src/test/ui/repr/repr-transparent-other-items.stderr
@@ -1,4 +1,4 @@
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/repr-transparent-other-items.rs:3:8
    |
 LL | #[repr(transparent)]
@@ -6,7 +6,7 @@ LL | #[repr(transparent)]
 LL | fn cant_repr_this() {}
    | ---------------------- not a struct, enum, or union
 
-error[E0517]: attribute should be applied to struct, enum, or union
+error[E0517]: attribute should be applied to a struct, enum, or union
   --> $DIR/repr-transparent-other-items.rs:6:8
    |
 LL | #[repr(transparent)]