add error message when #[naked] is used with #[test]
This commit is contained in:
@@ -216,6 +216,11 @@ builtin_macros_multiple_defaults = multiple declared defaults
|
||||
.note = only one variant can be default
|
||||
.suggestion = make `{$ident}` default
|
||||
|
||||
builtin_macros_naked_functions_testing_attribute =
|
||||
cannot use `#[naked]` with testing attributes
|
||||
.label = function marked with testing attribute here
|
||||
.naked_attribute = `#[naked]` is incompatible with testing attributes
|
||||
|
||||
builtin_macros_no_default_variant = no default declared
|
||||
.help = make a unit variant default by placing `#[default]` above it
|
||||
.suggestion = make `{$ident}` default
|
||||
|
||||
@@ -912,3 +912,13 @@ pub(crate) struct ExpectedItem<'a> {
|
||||
pub span: Span,
|
||||
pub token: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0798)]
|
||||
pub struct NakedFunctionTestingAttribute {
|
||||
#[primary_span]
|
||||
#[label(builtin_macros_naked_attribute)]
|
||||
pub naked_span: Span,
|
||||
#[label]
|
||||
pub testing_span: Span,
|
||||
}
|
||||
|
||||
@@ -133,6 +133,14 @@ pub(crate) fn expand_test_or_bench(
|
||||
};
|
||||
};
|
||||
|
||||
if let Some(attr) = attr::find_by_name(&item.attrs, sym::naked) {
|
||||
cx.dcx().emit_err(errors::NakedFunctionTestingAttribute {
|
||||
testing_span: attr_sp,
|
||||
naked_span: attr.span,
|
||||
});
|
||||
return vec![Annotatable::Item(item)];
|
||||
}
|
||||
|
||||
// check_*_signature will report any errors in the type so compilation
|
||||
// will fail. We shouldn't try to expand in this case because the errors
|
||||
// would be spurious.
|
||||
|
||||
14
compiler/rustc_error_codes/src/error_codes/E0798.md
Normal file
14
compiler/rustc_error_codes/src/error_codes/E0798.md
Normal file
@@ -0,0 +1,14 @@
|
||||
Testing attributes cannot be applied to functions marked with `#[naked]`.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```ignore (requires test runner)
|
||||
#[test]
|
||||
#[should_panic]
|
||||
#[naked]
|
||||
fn foo() {}
|
||||
```
|
||||
|
||||
See [the reference page for testing attributes] for more information.
|
||||
|
||||
[the reference page for testing attributes]: https://doc.rust-lang.org/reference/attributes/testing.html
|
||||
@@ -536,6 +536,7 @@ E0794: 0794,
|
||||
E0795: 0795,
|
||||
E0796: 0796,
|
||||
E0797: 0797,
|
||||
E0798: 0798,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user