Rollup merge of #127853 - folkertdev:naked-function-error-messages, r=bjorn3
`#[naked]`: report incompatible attributes tracking issue: https://github.com/rust-lang/rust/issues/90957 this is a re-implementation of https://github.com/rust-lang/rust/pull/93809 by ``@bstrie`` which was closed 2 years ago due to inactivity. This PR takes some of the final comments into account, specifically providing a little more context in error messages, and using an allow list to determine which attributes are compatible with `#[naked]`. Notable attributes that are incompatible with `#[naked]` are: * `#[inline]` * `#[track_caller]` * ~~`#[target_feature]`~~ (this is now allowed, see PR discussion) * `#[test]`, `#[ignore]`, `#[should_panic]` These attributes just directly conflict with what `#[naked]` should do. Naked functions are still important for systems programming, embedded, and operating systems, so I'd like to move them forward.
This commit is contained in:
commit
a13f40dae6
18 changed files with 380 additions and 131 deletions
|
@ -923,3 +923,13 @@ pub(crate) struct ExpectedItem<'a> {
|
|||
pub span: Span,
|
||||
pub token: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(builtin_macros_naked_functions_testing_attribute, code = E0736)]
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue