File tree Expand file tree Collapse file tree 7 files changed +112
-0
lines changed Expand file tree Collapse file tree 7 files changed +112
-0
lines changed Original file line number Diff line number Diff line change @@ -216,6 +216,11 @@ builtin_macros_multiple_defaults = multiple declared defaults
216216 .note = only one variant can be default
217217 .suggestion = make `{ $ident } ` default
218218
219+ builtin_macros_naked_functions_testing_attribute =
220+ cannot use `#[naked]` with testing attributes
221+ .label = function marked with testing attribute here
222+ .naked_attribute = `#[naked]` is incompatible with testing attributes
223+
219224builtin_macros_no_default_variant = no default declared
220225 .help = make a unit variant default by placing `#[default]` above it
221226 .suggestion = make `{ $ident } ` default
Original file line number Diff line number Diff line change @@ -912,3 +912,13 @@ pub(crate) struct ExpectedItem<'a> {
912912 pub span : Span ,
913913 pub token : & ' a str ,
914914}
915+
916+ #[ derive( Diagnostic ) ]
917+ #[ diag( builtin_macros_naked_functions_testing_attribute, code = E0798 ) ]
918+ pub struct NakedFunctionTestingAttribute {
919+ #[ primary_span]
920+ #[ label( builtin_macros_naked_attribute) ]
921+ pub naked_span : Span ,
922+ #[ label]
923+ pub testing_span : Span ,
924+ }
Original file line number Diff line number Diff line change @@ -133,6 +133,14 @@ pub(crate) fn expand_test_or_bench(
133133 } ;
134134 } ;
135135
136+ if let Some ( attr) = attr:: find_by_name ( & item. attrs , sym:: naked) {
137+ cx. dcx ( ) . emit_err ( errors:: NakedFunctionTestingAttribute {
138+ testing_span : attr_sp,
139+ naked_span : attr. span ,
140+ } ) ;
141+ return vec ! [ Annotatable :: Item ( item) ] ;
142+ }
143+
136144 // check_*_signature will report any errors in the type so compilation
137145 // will fail. We shouldn't try to expand in this case because the errors
138146 // would be spurious.
Original file line number Diff line number Diff line change 1+ Testing attributes cannot be applied to functions marked with ` #[naked] ` .
2+
3+ Erroneous code example:
4+
5+ ``` ignore (requires test runner)
6+ #[test]
7+ #[should_panic]
8+ #[naked]
9+ fn foo() {}
10+ ```
11+
12+ See [ the reference page for testing attributes] for more information.
13+
14+ [ the reference page for testing attributes ] : https://doc.rust-lang.org/reference/attributes/testing.html
Original file line number Diff line number Diff line change @@ -536,6 +536,7 @@ E0794: 0794,
536536E0795 : 0795 ,
537537E0796 : 0796 ,
538538E0797 : 0797 ,
539+ E0798 : 0798 ,
539540 ) ;
540541 )
541542}
Original file line number Diff line number Diff line change 1+ //@ needs-asm-support
2+ //@ compile-flags: --test
3+
4+ #![ allow( undefined_naked_function_abi) ]
5+ #![ feature( naked_functions) ]
6+ #![ feature( test) ]
7+ #![ crate_type = "lib" ]
8+
9+ use std:: arch:: asm;
10+
11+ #[ test]
12+ #[ naked]
13+ //~^ ERROR [E0798]
14+ fn test_naked ( ) {
15+ unsafe { asm ! ( "" , options( noreturn) ) } ;
16+ }
17+
18+ #[ should_panic]
19+ #[ test]
20+ #[ naked]
21+ //~^ ERROR [E0798]
22+ fn test_naked_should_panic ( ) {
23+ unsafe { asm ! ( "" , options( noreturn) ) } ;
24+ }
25+
26+ #[ ignore]
27+ #[ test]
28+ #[ naked]
29+ //~^ ERROR [E0798]
30+ fn test_naked_ignore ( ) {
31+ unsafe { asm ! ( "" , options( noreturn) ) } ;
32+ }
33+
34+ #[ bench]
35+ #[ naked]
36+ //~^ ERROR [E0798]
37+ fn bench_naked ( ) {
38+ unsafe { asm ! ( "" , options( noreturn) ) } ;
39+ }
Original file line number Diff line number Diff line change 1+ error[E0798]: cannot use `#[naked]` with testing attributes
2+ --> $DIR/naked-functions-testattrs.rs:12:1
3+ |
4+ LL | #[test]
5+ | ------- function marked with testing attribute here
6+ LL | #[naked]
7+ | ^^^^^^^^ `#[naked]` is incompatible with testing attributes
8+
9+ error[E0798]: cannot use `#[naked]` with testing attributes
10+ --> $DIR/naked-functions-testattrs.rs:20:1
11+ |
12+ LL | #[test]
13+ | ------- function marked with testing attribute here
14+ LL | #[naked]
15+ | ^^^^^^^^ `#[naked]` is incompatible with testing attributes
16+
17+ error[E0798]: cannot use `#[naked]` with testing attributes
18+ --> $DIR/naked-functions-testattrs.rs:28:1
19+ |
20+ LL | #[test]
21+ | ------- function marked with testing attribute here
22+ LL | #[naked]
23+ | ^^^^^^^^ `#[naked]` is incompatible with testing attributes
24+
25+ error[E0798]: cannot use `#[naked]` with testing attributes
26+ --> $DIR/naked-functions-testattrs.rs:35:1
27+ |
28+ LL | #[bench]
29+ | -------- function marked with testing attribute here
30+ LL | #[naked]
31+ | ^^^^^^^^ `#[naked]` is incompatible with testing attributes
32+
33+ error: aborting due to 4 previous errors
34+
35+ For more information about this error, try `rustc --explain E0798`.
You can’t perform that action at this time.
0 commit comments