about summary refs log tree commit diff
path: root/tests/ui/codegen
diff options
context:
space:
mode:
authorAlexandru RADOVICI <alexandru.radovici@wyliodrin.com>2025-04-30 14:52:15 +0300
committerAlexandru RADOVICI <alexandru.radovici@wyliodrin.com>2025-04-30 14:54:10 +0300
commit07c7e5ffb3c096f80ffede421fb20089fbe7fe3f (patch)
treedee779ff48b21c221bdb66b5609ef7ae1acc1acb /tests/ui/codegen
parent49e5e4e3a5610c240a717cb99003a5d5d3356679 (diff)
downloadrust-07c7e5ffb3c096f80ffede421fb20089fbe7fe3f.tar.gz
rust-07c7e5ffb3c096f80ffede421fb20089fbe7fe3f.zip
error when using no_mangle on language items
add suggestion on how to add a panic breakpoint

Co-authored-by: Pat Pannuto <pat.pannuto@gmail.com>
delete no_mangle from ui/panic-handler/panic-handler-wrong-location test

issue an error for the usage of #[no_mangle] on internal language items

delete the comments

add newline

rephrase note

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
update error not to leak implementation details

delete no_mangle_span

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
delete commented code
Diffstat (limited to 'tests/ui/codegen')
-rw-r--r--tests/ui/codegen/no-mangle-on-internal-lang-items.rs14
-rw-r--r--tests/ui/codegen/no-mangle-on-internal-lang-items.stderr12
-rw-r--r--tests/ui/codegen/no-mangle-on-panic-handler.rs14
-rw-r--r--tests/ui/codegen/no-mangle-on-panic-handler.stderr16
4 files changed, 56 insertions, 0 deletions
diff --git a/tests/ui/codegen/no-mangle-on-internal-lang-items.rs b/tests/ui/codegen/no-mangle-on-internal-lang-items.rs
new file mode 100644
index 00000000000..37766936410
--- /dev/null
+++ b/tests/ui/codegen/no-mangle-on-internal-lang-items.rs
@@ -0,0 +1,14 @@
+// Issue a error when the user uses #[no_mangle] on internal language items
+//@ edition:2024
+
+#![feature(rustc_attrs)]
+
+#[rustc_std_internal_symbol]
+#[unsafe(no_mangle)] //~ERROR `#[no_mangle]` cannot be used on internal language items
+fn internal_lang_function () {
+
+}
+
+fn main() {
+
+}
diff --git a/tests/ui/codegen/no-mangle-on-internal-lang-items.stderr b/tests/ui/codegen/no-mangle-on-internal-lang-items.stderr
new file mode 100644
index 00000000000..12461a6abb9
--- /dev/null
+++ b/tests/ui/codegen/no-mangle-on-internal-lang-items.stderr
@@ -0,0 +1,12 @@
+error: `#[no_mangle]` cannot be used on internal language items
+  --> $DIR/no-mangle-on-internal-lang-items.rs:7:1
+   |
+LL | #[unsafe(no_mangle)]
+   | ^^^^^^^^^^^^^^^^^^^^
+LL | fn internal_lang_function () {
+   | ---------------------------- should be the internal language item
+   |
+   = note: Rustc requires this item to have a specific mangled name.
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/codegen/no-mangle-on-panic-handler.rs b/tests/ui/codegen/no-mangle-on-panic-handler.rs
new file mode 100644
index 00000000000..1dc0cce0a2e
--- /dev/null
+++ b/tests/ui/codegen/no-mangle-on-panic-handler.rs
@@ -0,0 +1,14 @@
+// Issue an error when the user uses #[no_mangle] on the panic handler
+//@ edition:2024
+
+#![crate_type="lib"]
+#![no_std]
+#![no_main]
+
+use core::panic::PanicInfo;
+
+#[unsafe(no_mangle)] //~ ERROR `#[no_mangle]` cannot be used on internal language items
+#[panic_handler]
+pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
+    loop {}
+}
diff --git a/tests/ui/codegen/no-mangle-on-panic-handler.stderr b/tests/ui/codegen/no-mangle-on-panic-handler.stderr
new file mode 100644
index 00000000000..dc88b66d1b5
--- /dev/null
+++ b/tests/ui/codegen/no-mangle-on-panic-handler.stderr
@@ -0,0 +1,16 @@
+error: `#[no_mangle]` cannot be used on internal language items
+  --> $DIR/no-mangle-on-panic-handler.rs:10:1
+   |
+LL | #[unsafe(no_mangle)]
+   | ^^^^^^^^^^^^^^^^^^^^
+LL | #[panic_handler]
+LL | pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
+   | -------------------------------------------- should be the internal language item
+   |
+   = note: Rustc requires this item to have a specific mangled name.
+   = note: If you are trying to prevent mangling to ease debugging, many
+   = note: debuggers support a command such as `rbreak rust_begin_unwind` to
+   = note: match `.*rust_begin_unwind.*` instead of `break rust_begin_unwind` on a specific name
+
+error: aborting due to 1 previous error
+