Allow #[cold], #[track_caller] on closures. Fix whitespace in error messages.

This commit is contained in:
Caleb Zulawski 2020-08-12 12:43:14 -04:00
parent f745b34960
commit 0c62ef08bd
3 changed files with 16 additions and 28 deletions

View File

@ -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();

View File

@ -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();
}

View File

@ -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`.