about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-28 08:57:16 +0200
committerGitHub <noreply@github.com>2024-07-28 08:57:16 +0200
commita13f40dae64647c524c8d2a64e9b30f97d391377 (patch)
treee6ba63a91ca38d64d0dec2817883056374a9877b /compiler/rustc_error_codes/src
parent3148b35f6a6226548929c12da529ab0d1a4b47d5 (diff)
parentc7e688eccd60ab05a00dea56ac9d984397a2d02e (diff)
downloadrust-a13f40dae64647c524c8d2a64e9b30f97d391377.tar.gz
rust-a13f40dae64647c524c8d2a64e9b30f97d391377.zip
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.
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0736.md18
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0739.md2
2 files changed, 13 insertions, 7 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0736.md b/compiler/rustc_error_codes/src/error_codes/E0736.md
index 0f3d41ba66d..cb7633b7068 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0736.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0736.md
@@ -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.
diff --git a/compiler/rustc_error_codes/src/error_codes/E0739.md b/compiler/rustc_error_codes/src/error_codes/E0739.md
index 8d9039bef93..406d3d52779 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0739.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0739.md
@@ -1,4 +1,4 @@
-`#[track_caller]` can not be applied on struct.
+`#[track_caller]` must  be applied to a function
 
 Erroneous code example: