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
|
@ -1,14 +1,20 @@
|
|||
`#[track_caller]` and `#[naked]` cannot both be applied to the same function.
|
||||
Functions marked with the `#[naked]` attribute are restricted in what other
|
||||
attributes they may be marked with.
|
||||
|
||||
Notable attributes that are incompatible with `#[naked]` are:
|
||||
|
||||
* `#[inline]`
|
||||
* `#[track_caller]`
|
||||
* `#[test]`, `#[ignore]`, `#[should_panic]`
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0736
|
||||
#[inline]
|
||||
#[naked]
|
||||
#[track_caller]
|
||||
fn foo() {}
|
||||
```
|
||||
|
||||
This is primarily due to ABI incompatibilities between the two attributes.
|
||||
See [RFC 2091] for details on this and other limitations.
|
||||
|
||||
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
|
||||
These incompatibilities are due to the fact that naked functions deliberately
|
||||
impose strict restrictions regarding the code that the compiler is
|
||||
allowed to produce for this function.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
`#[track_caller]` can not be applied on struct.
|
||||
`#[track_caller]` must be applied to a function
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue