Skip to content

Commit 5ae611d

Browse files
committed
Improve error message for #![manually_drop]
1 parent ff7e441 commit 5ae611d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

compiler/rustc_passes/src/check_attr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
22072207
sym::rustc_main,
22082208
sym::unix_sigpipe,
22092209
sym::derive,
2210-
sym::manually_drop,
22112210
sym::test,
22122211
sym::test_case,
22132212
sym::global_allocator,

src/test/ui/manually_drop_attr/manually_drop-bad-item.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![feature(manually_drop_attr)]
22
#![forbid(unused_attributes)]
3+
#![manually_drop]
4+
//~^ ERROR `manually_drop` attribute cannot be used at crate level
5+
//~^^ ERROR attribute should be applied to a struct or enum
36

47
#[manually_drop]
58
//~^ ERROR attribute should be applied to a struct or enum

src/test/ui/manually_drop_attr/manually_drop-bad-item.stderr

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: attribute should be applied to a struct or enum
2-
--> $DIR/manually_drop-bad-item.rs:4:1
2+
--> $DIR/manually_drop-bad-item.rs:7:1
33
|
44
LL | #[manually_drop]
55
| ^^^^^^^^^^^^^^^^
@@ -13,5 +13,22 @@ note: the lint level is defined here
1313
LL | #![forbid(unused_attributes)]
1414
| ^^^^^^^^^^^^^^^^^
1515

16-
error: aborting due to previous error
16+
error: attribute should be applied to a struct or enum
17+
--> $DIR/manually_drop-bad-item.rs:3:1
18+
|
19+
LL | #![manually_drop]
20+
| ^^^^^^^^^^^^^^^^^
21+
22+
error: `manually_drop` attribute cannot be used at crate level
23+
--> $DIR/manually_drop-bad-item.rs:3:1
24+
|
25+
LL | #![manually_drop]
26+
| ^^^^^^^^^^^^^^^^^
27+
|
28+
help: perhaps you meant to use an outer attribute
29+
|
30+
LL | #[manually_drop]
31+
|
32+
33+
error: aborting due to 3 previous errors
1734

0 commit comments

Comments
 (0)