Skip to content

Commit 2b59b34

Browse files
Add "functions with a body" target group
1 parent 70f4b54 commit 2b59b34

10 files changed

Lines changed: 32 additions & 18 deletions

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ pub(crate) fn allowed_targets_applied(
344344
Target::Method(MethodKind::Trait { body: true }),
345345
Target::Method(MethodKind::TraitImpl),
346346
];
347+
const FUNCTION_WITH_BODY_LIKE: &[Target] = &[
348+
Target::Fn,
349+
Target::Closure,
350+
Target::Method(MethodKind::Inherent),
351+
Target::Method(MethodKind::Trait { body: true }),
352+
Target::Method(MethodKind::TraitImpl),
353+
];
347354
const METHOD_LIKE: &[Target] = &[
348355
Target::Method(MethodKind::Inherent),
349356
Target::Method(MethodKind::Trait { body: false }),
@@ -362,6 +369,13 @@ pub(crate) fn allowed_targets_applied(
362369
target,
363370
&mut added_fake_targets,
364371
);
372+
filter_targets(
373+
&mut allowed_targets,
374+
FUNCTION_WITH_BODY_LIKE,
375+
"functions with a body",
376+
target,
377+
&mut added_fake_targets,
378+
);
365379
filter_targets(&mut allowed_targets, METHOD_LIKE, "methods", target, &mut added_fake_targets);
366380
filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets);
367381
filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets);

tests/ui/asm/naked-invalid-attr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error: `#[naked]` attribute cannot be used on foreign functions
1818
LL | #[unsafe(naked)]
1919
| ^^^^^^^^^^^^^^^^
2020
|
21-
= help: `#[naked]` can be applied to functions and methods
21+
= help: `#[naked]` can only be applied to functions with a body
2222

2323
error: `#[naked]` attribute cannot be used on structs
2424
--> $DIR/naked-invalid-attr.rs:14:1
@@ -42,7 +42,7 @@ error: `#[naked]` attribute cannot be used on required trait methods
4242
LL | #[unsafe(naked)]
4343
| ^^^^^^^^^^^^^^^^
4444
|
45-
= help: `#[naked]` can be applied to functions, inherent methods, provided trait methods, and trait methods in impl blocks
45+
= help: `#[naked]` can only be applied to functions with a body
4646

4747
error: `#[naked]` attribute cannot be used on closures
4848
--> $DIR/naked-invalid-attr.rs:52:5

tests/ui/attributes/codegen_attr_on_required_trait_method.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: `#[cold]` attribute cannot be used on required trait methods
44
LL | #[cold]
55
| ^^^^^^^
66
|
7-
= help: `#[cold]` can be applied to closures, foreign functions, functions, inherent methods, provided trait methods, and trait methods in impl blocks
7+
= help: `#[cold]` can be applied to foreign functions and functions with a body
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
note: the lint level is defined here
1010
--> $DIR/codegen_attr_on_required_trait_method.rs:1:9
@@ -18,7 +18,7 @@ error: `#[link_section]` attribute cannot be used on required trait methods
1818
LL | #[link_section = "__TEXT,__text"]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
21-
= help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
21+
= help: `#[link_section]` can be applied to functions with a body and statics
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323

2424
error: `#[linkage]` attribute cannot be used on required trait methods
@@ -27,7 +27,7 @@ error: `#[linkage]` attribute cannot be used on required trait methods
2727
LL | #[linkage = "common"]
2828
| ^^^^^^^^^^^^^^^^^^^^^
2929
|
30-
= help: `#[linkage]` can be applied to foreign functions, foreign statics, functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
30+
= help: `#[linkage]` can be applied to foreign functions, foreign statics, functions with a body, and statics
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232

3333
error: aborting due to 3 previous errors

tests/ui/coverage-attr/allowed-positions.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ error: `#[coverage]` attribute cannot be used on required trait methods
4646
LL | #[coverage(off)]
4747
| ^^^^^^^^^^^^^^^^
4848
|
49-
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks
49+
= help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules
5050

5151
error: `#[coverage]` attribute cannot be used on required trait methods
5252
--> $DIR/allowed-positions.rs:31:5
5353
|
5454
LL | #[coverage(off)]
5555
| ^^^^^^^^^^^^^^^^
5656
|
57-
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks
57+
= help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules
5858

5959
error: `#[coverage]` attribute cannot be used on associated types
6060
--> $DIR/allowed-positions.rs:39:5
@@ -110,7 +110,7 @@ error: `#[coverage]` attribute cannot be used on foreign functions
110110
LL | #[coverage(off)]
111111
| ^^^^^^^^^^^^^^^^
112112
|
113-
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, methods, and modules
113+
= help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules
114114

115115
error: `#[coverage]` attribute cannot be used on statements
116116
--> $DIR/allowed-positions.rs:88:5

tests/ui/extern/extern-no-mangle.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ warning: `#[no_mangle]` attribute cannot be used on foreign functions
1818
LL | #[no_mangle]
1919
| ^^^^^^^^^^^^
2020
|
21-
= help: `#[no_mangle]` can be applied to functions, methods, and statics
21+
= help: `#[no_mangle]` can be applied to functions with a body and statics
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323

2424
warning: `#[no_mangle]` attribute cannot be used on statements

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ error: `#[export_name]` attribute cannot be used on required trait methods
213213
LL | #[export_name = "2200"] fn foo();
214214
| ^^^^^^^^^^^^^^^^^^^^^^^
215215
|
216-
= help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
216+
= help: `#[export_name]` can be applied to functions with a body and statics
217217

218218
error[E0517]: attribute should be applied to a struct, enum, or union
219219
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:8

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ warning: `#[no_mangle]` attribute cannot be used on required trait methods
511511
LL | #[no_mangle] fn foo();
512512
| ^^^^^^^^^^^^
513513
|
514-
= help: `#[no_mangle]` can be applied to functions, inherent methods, statics, and trait methods in impl blocks
514+
= help: `#[no_mangle]` can be applied to functions with a body and statics
515515
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
516516

517517
warning: `#[no_mangle]` attribute cannot be used on provided trait methods
@@ -923,7 +923,7 @@ warning: `#[link_section]` attribute cannot be used on required trait methods
923923
LL | #[link_section = ",1800"]
924924
| ^^^^^^^^^^^^^^^^^^^^^^^^^
925925
|
926-
= help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
926+
= help: `#[link_section]` can be applied to functions with a body and statics
927927
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
928928

929929
warning: `#[must_use]` attribute cannot be used on modules

tests/ui/force-inlining/invalid.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ error: `#[rustc_force_inline]` attribute cannot be used on foreign functions
134134
LL | #[rustc_force_inline]
135135
| ^^^^^^^^^^^^^^^^^^^^^
136136
|
137-
= help: `#[rustc_force_inline]` can be applied to functions and inherent methods
137+
= help: `#[rustc_force_inline]` can only be applied to functions with a body
138138

139139
error: `#[rustc_force_inline]` attribute cannot be used on type aliases
140140
--> $DIR/invalid.rs:66:1

tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: `#[inline]` attribute cannot be used on required trait methods
44
LL | #[inline]
55
| ^^^^^^^^^
66
|
7-
= help: `#[inline]` can be applied to closures, functions, inherent methods, provided trait methods, and trait methods in impl blocks
7+
= help: `#[inline]` can only be applied to functions with a body
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
note: the lint level is defined here
1010
--> $DIR/warn-unused-inline-on-fn-prototypes.rs:1:9
@@ -18,7 +18,7 @@ error: `#[inline]` attribute cannot be used on foreign functions
1818
LL | #[inline]
1919
| ^^^^^^^^^
2020
|
21-
= help: `#[inline]` can be applied to closures, functions, and methods
21+
= help: `#[inline]` can only be applied to functions with a body
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323

2424
error: aborting due to 2 previous errors

tests/ui/sanitize-attr/valid-sanitize.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ error: `#[sanitize]` attribute cannot be used on required trait methods
4444
LL | #[sanitize(address = "off")]
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4646
|
47-
= help: `#[sanitize]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, statics, and trait methods in impl blocks
47+
= help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics
4848

4949
error: `#[sanitize]` attribute cannot be used on required trait methods
5050
--> $DIR/valid-sanitize.rs:35:5
5151
|
5252
LL | #[sanitize(address = "off")]
5353
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5454
|
55-
= help: `#[sanitize]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, statics, and trait methods in impl blocks
55+
= help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics
5656

5757
error: `#[sanitize]` attribute cannot be used on associated types
5858
--> $DIR/valid-sanitize.rs:43:5
@@ -108,7 +108,7 @@ error: `#[sanitize]` attribute cannot be used on foreign functions
108108
LL | #[sanitize(address = "off", thread = "on")]
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110110
|
111-
= help: `#[sanitize]` can be applied to closures, crates, functions, impl blocks, methods, modules, and statics
111+
= help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics
112112

113113
error: `#[sanitize]` attribute cannot be used on statements
114114
--> $DIR/valid-sanitize.rs:92:5

0 commit comments

Comments
 (0)