about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2020-08-12 12:43:14 -0400
committerCaleb Zulawski <caleb.zulawski@gmail.com>2020-09-05 20:46:38 -0400
commit0c62ef08bd1a1860c4d6d1c22489d287a9359129 (patch)
treefacb3edd865afed01009480d785eaa2c6fc305f8
parentf745b34960b2146dbaa7337856e7c5461cca29d5 (diff)
downloadrust-0c62ef08bd1a1860c4d6d1c22489d287a9359129.tar.gz
rust-0c62ef08bd1a1860c4d6d1c22489d287a9359129.zip
Allow #[cold], #[track_caller] on closures. Fix whitespace in error messages.
-rw-r--r--compiler/rustc_passes/src/check_attr.rs26
-rw-r--r--src/test/ui/macros/issue-68060.rs4
-rw-r--r--src/test/ui/macros/issue-68060.stderr14
3 files changed, 16 insertions, 28 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index fdb1f24de26..5fb59012fb7 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -121,12 +121,12 @@ impl CheckAttrVisitor<'tcx> {
                     lint.build("`#[inline]` is ignored on constants")
                         .warn(
                             "this was previously accepted by the compiler but is \
-                               being phased out; it will become a hard error in \
-                               a future release!",
+                             being phased out; it will become a hard error in \
+                             a future release!",
                         )
                         .note(
                             "see issue #65833 <https://github.com/rust-lang/rust/issues/65833> \
-                                 for more information",
+                             for more information",
                         )
                         .emit();
                 });
@@ -165,7 +165,7 @@ impl CheckAttrVisitor<'tcx> {
                 .emit();
                 false
             }
-            Target::Fn | Target::Method(..) | Target::ForeignFn => true,
+            Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
             _ => {
                 struct_span_err!(
                     self.tcx.sess,
@@ -231,8 +231,8 @@ impl CheckAttrVisitor<'tcx> {
                     lint.build("attribute should be applied to a function")
                         .warn(
                             "this was previously accepted by the compiler but is \
-                               being phased out; it will become a hard error in \
-                               a future release!",
+                             being phased out; it will become a hard error in \
+                             a future release!",
                         )
                         .span_label(*span, "not a function")
                         .emit();
@@ -313,7 +313,7 @@ impl CheckAttrVisitor<'tcx> {
     /// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
     fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
         match target {
-            Target::Fn | Target::Method(..) | Target::ForeignFn => {}
+            Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {}
             _ => {
                 // FIXME: #[cold] was previously allowed on non-functions and some crates used
                 // this, so only emit a warning.
@@ -321,8 +321,8 @@ impl CheckAttrVisitor<'tcx> {
                     lint.build("attribute should be applied to a function")
                         .warn(
                             "this was previously accepted by the compiler but is \
-                               being phased out; it will become a hard error in \
-                               a future release!",
+                             being phased out; it will become a hard error in \
+                             a future release!",
                         )
                         .span_label(*span, "not a function")
                         .emit();
@@ -343,8 +343,8 @@ impl CheckAttrVisitor<'tcx> {
                         lint.build("attribute should be applied to a foreign function or static");
                     diag.warn(
                         "this was previously accepted by the compiler but is \
-                               being phased out; it will become a hard error in \
-                               a future release!",
+                         being phased out; it will become a hard error in \
+                         a future release!",
                     );
 
                     // See issue #47725
@@ -409,8 +409,8 @@ impl CheckAttrVisitor<'tcx> {
                     lint.build("attribute should be applied to a function or static")
                         .warn(
                             "this was previously accepted by the compiler but is \
-                               being phased out; it will become a hard error in \
-                               a future release!",
+                             being phased out; it will become a hard error in \
+                             a future release!",
                         )
                         .span_label(*span, "not a function or static")
                         .emit();
diff --git a/src/test/ui/macros/issue-68060.rs b/src/test/ui/macros/issue-68060.rs
index 78c695d0025..f82eb338f4c 100644
--- a/src/test/ui/macros/issue-68060.rs
+++ b/src/test/ui/macros/issue-68060.rs
@@ -6,11 +6,9 @@ fn main() {
             //~| ERROR: the feature named `` is not valid for this target
             //~| NOTE: `` is not valid for this target
             #[track_caller]
-            //~^ ERROR: attribute should be applied to function [E0739]
-            //~| ERROR: `#[track_caller]` requires Rust ABI [E0737]
+            //~^ ERROR: `#[track_caller]` requires Rust ABI [E0737]
             |_| (),
             //~^ NOTE: not a function
-            //~| NOTE: not a function
         )
         .next();
 }
diff --git a/src/test/ui/macros/issue-68060.stderr b/src/test/ui/macros/issue-68060.stderr
index fa236939a40..a01c3827bb5 100644
--- a/src/test/ui/macros/issue-68060.stderr
+++ b/src/test/ui/macros/issue-68060.stderr
@@ -7,15 +7,6 @@ LL |             #[target_feature(enable = "")]
 LL |             |_| (),
    |             ------ not a function
 
-error[E0739]: attribute should be applied to function
-  --> $DIR/issue-68060.rs:8:13
-   |
-LL |             #[track_caller]
-   |             ^^^^^^^^^^^^^^^
-...
-LL |             |_| (),
-   |             ------ not a function
-
 error: the feature named `` is not valid for this target
   --> $DIR/issue-68060.rs:4:30
    |
@@ -28,7 +19,6 @@ error[E0737]: `#[track_caller]` requires Rust ABI
 LL |             #[track_caller]
    |             ^^^^^^^^^^^^^^^
 
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0737, E0739.
-For more information about an error, try `rustc --explain E0737`.
+For more information about this error, try `rustc --explain E0737`.