Skip to content

Commit 0c62ef0

Browse files
committed
Allow #[cold], #[track_caller] on closures. Fix whitespace in error messages.
1 parent f745b34 commit 0c62ef0

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ impl CheckAttrVisitor<'tcx> {
121121
lint.build("`#[inline]` is ignored on constants")
122122
.warn(
123123
"this was previously accepted by the compiler but is \
124-
being phased out; it will become a hard error in \
125-
a future release!",
124+
being phased out; it will become a hard error in \
125+
a future release!",
126126
)
127127
.note(
128128
"see issue #65833 <https://github.com/rust-lang/rust/issues/65833> \
129-
for more information",
129+
for more information",
130130
)
131131
.emit();
132132
});
@@ -165,7 +165,7 @@ impl CheckAttrVisitor<'tcx> {
165165
.emit();
166166
false
167167
}
168-
Target::Fn | Target::Method(..) | Target::ForeignFn => true,
168+
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
169169
_ => {
170170
struct_span_err!(
171171
self.tcx.sess,
@@ -231,8 +231,8 @@ impl CheckAttrVisitor<'tcx> {
231231
lint.build("attribute should be applied to a function")
232232
.warn(
233233
"this was previously accepted by the compiler but is \
234-
being phased out; it will become a hard error in \
235-
a future release!",
234+
being phased out; it will become a hard error in \
235+
a future release!",
236236
)
237237
.span_label(*span, "not a function")
238238
.emit();
@@ -313,16 +313,16 @@ impl CheckAttrVisitor<'tcx> {
313313
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
314314
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
315315
match target {
316-
Target::Fn | Target::Method(..) | Target::ForeignFn => {}
316+
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {}
317317
_ => {
318318
// FIXME: #[cold] was previously allowed on non-functions and some crates used
319319
// this, so only emit a warning.
320320
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
321321
lint.build("attribute should be applied to a function")
322322
.warn(
323323
"this was previously accepted by the compiler but is \
324-
being phased out; it will become a hard error in \
325-
a future release!",
324+
being phased out; it will become a hard error in \
325+
a future release!",
326326
)
327327
.span_label(*span, "not a function")
328328
.emit();
@@ -343,8 +343,8 @@ impl CheckAttrVisitor<'tcx> {
343343
lint.build("attribute should be applied to a foreign function or static");
344344
diag.warn(
345345
"this was previously accepted by the compiler but is \
346-
being phased out; it will become a hard error in \
347-
a future release!",
346+
being phased out; it will become a hard error in \
347+
a future release!",
348348
);
349349

350350
// See issue #47725
@@ -409,8 +409,8 @@ impl CheckAttrVisitor<'tcx> {
409409
lint.build("attribute should be applied to a function or static")
410410
.warn(
411411
"this was previously accepted by the compiler but is \
412-
being phased out; it will become a hard error in \
413-
a future release!",
412+
being phased out; it will become a hard error in \
413+
a future release!",
414414
)
415415
.span_label(*span, "not a function or static")
416416
.emit();

src/test/ui/macros/issue-68060.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ fn main() {
66
//~| ERROR: the feature named `` is not valid for this target
77
//~| NOTE: `` is not valid for this target
88
#[track_caller]
9-
//~^ ERROR: attribute should be applied to function [E0739]
10-
//~| ERROR: `#[track_caller]` requires Rust ABI [E0737]
9+
//~^ ERROR: `#[track_caller]` requires Rust ABI [E0737]
1110
|_| (),
1211
//~^ NOTE: not a function
13-
//~| NOTE: not a function
1412
)
1513
.next();
1614
}

src/test/ui/macros/issue-68060.stderr

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ LL | #[target_feature(enable = "")]
77
LL | |_| (),
88
| ------ not a function
99

10-
error[E0739]: attribute should be applied to function
11-
--> $DIR/issue-68060.rs:8:13
12-
|
13-
LL | #[track_caller]
14-
| ^^^^^^^^^^^^^^^
15-
...
16-
LL | |_| (),
17-
| ------ not a function
18-
1910
error: the feature named `` is not valid for this target
2011
--> $DIR/issue-68060.rs:4:30
2112
|
@@ -28,7 +19,6 @@ error[E0737]: `#[track_caller]` requires Rust ABI
2819
LL | #[track_caller]
2920
| ^^^^^^^^^^^^^^^
3021

31-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
3223

33-
Some errors have detailed explanations: E0737, E0739.
34-
For more information about an error, try `rustc --explain E0737`.
24+
For more information about this error, try `rustc --explain E0737`.

0 commit comments

Comments
 (0)