Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions compiler/rustc_lint/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,7 @@ pub(crate) enum RedefiningRuntimeSymbolsDiag<'tcx> {
"invalid definition of the runtime `{$symbol_name}` symbol used by the standard library"
)]
#[note(
"expected `{$expected_fn_sig}` (for the current target)
found `{$found_fn_sig}`"
"expected `{$expected_fn_sig}` (for the current target)\n{\" \"}found `{$found_fn_sig}`"
)]
#[help(
"either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
Expand All @@ -955,8 +954,7 @@ pub(crate) enum RedefiningRuntimeSymbolsDiag<'tcx> {
"suspicious definition of the runtime `{$symbol_name}` symbol used by the standard library"
)]
#[note(
"expected `{$expected_fn_sig}` (for the current target)
found `{$found_fn_sig}`"
"expected `{$expected_fn_sig}` (for the current target)\n{\" \"}found `{$found_fn_sig}`"
)]
#[help(
"either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_macros/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ fn verify_message_formatting(attr_span: Span, msg_span: Span, message: &str) {
if line.is_empty() {
continue;
}
if line.trim().starts_with("{") && line.contains(&"found ") {
continue;
}
let indent = line.chars().take_while(|c| *c == ' ').count();
if indent < start {
span_err(
Expand Down
28 changes: 14 additions & 14 deletions tests/ui/lint/runtime-symbols-unix.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub fn open() {}
| ^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const U8, i32, ...) -> i32` (for the current target)
found `fn()`
found `fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "open")]`, or `#[link_name = "open"]`
= note: `#[deny(invalid_runtime_symbol_definitions)]` on by default

Expand All @@ -16,7 +16,7 @@ LL | pub fn read();
| ^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32, *mut c_void, usize) -> isize` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "read")]`, or `#[link_name = "read"]`

error: invalid definition of the runtime `write` symbol used by the standard library
Expand All @@ -26,7 +26,7 @@ LL | pub fn write();
| ^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32, *const c_void, usize) -> isize` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "write")]`, or `#[link_name = "write"]`

error: invalid definition of the runtime `close` symbol used by the standard library
Expand All @@ -36,7 +36,7 @@ LL | pub static close: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> i32` (for the current target)
found `()`
found `()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "close")]`, or `#[link_name = "close"]`

error: invalid definition of the runtime `malloc` symbol used by the standard library
Expand All @@ -46,7 +46,7 @@ LL | pub fn malloc();
| ^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(usize) -> *mut c_void` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "malloc")]`, or `#[link_name = "malloc"]`

error: invalid definition of the runtime `realloc` symbol used by the standard library
Expand All @@ -56,7 +56,7 @@ LL | pub fn realloc();
| ^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "realloc")]`, or `#[link_name = "realloc"]`

error: invalid definition of the runtime `free` symbol used by the standard library
Expand All @@ -66,7 +66,7 @@ LL | pub fn free();
| ^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void)` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "free")]`, or `#[link_name = "free"]`

error: invalid definition of the runtime `exit` symbol used by the standard library
Expand All @@ -76,7 +76,7 @@ LL | pub fn exit();
| ^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> !` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`

warning: suspicious definition of the runtime `open` symbol used by the standard library
Expand All @@ -86,7 +86,7 @@ LL | pub fn open(path: *const U8, oflag: usize, ...) -> c_int;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const U8, i32, ...) -> i32` (for the current target)
found `unsafe extern "C" fn(*const U8, usize, ...) -> i32`
found `unsafe extern "C" fn(*const U8, usize, ...) -> i32`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "open")]`, or `#[link_name = "open"]`
= help: allow this lint if the signature is compatible
= note: `#[warn(suspicious_runtime_symbol_definitions)]` on by default
Expand All @@ -98,7 +98,7 @@ LL | pub fn free(ptr: *const U8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void)` (for the current target)
found `unsafe extern "C" fn(*const U8)`
found `unsafe extern "C" fn(*const U8)`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "free")]`, or `#[link_name = "free"]`
= help: allow this lint if the signature is compatible

Expand All @@ -109,7 +109,7 @@ LL | pub fn exit(code: f32) -> !;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> !` (for the current target)
found `unsafe extern "C" fn(f32) -> !`
found `unsafe extern "C" fn(f32) -> !`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`
= help: allow this lint if the signature is compatible

Expand All @@ -120,7 +120,7 @@ LL | pub static exit2: Option<unsafe extern "C" fn(f32) -> !>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> !` (for the current target)
found `unsafe extern "C" fn(f32) -> !`
found `unsafe extern "C" fn(f32) -> !`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`
= help: allow this lint if the signature is compatible

Expand All @@ -131,7 +131,7 @@ LL | pub fn exit3(code: i32) -> i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> !` (for the current target)
found `unsafe extern "C" fn(i32) -> i32`
found `unsafe extern "C" fn(i32) -> i32`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`
= help: allow this lint if the signature is compatible

Expand All @@ -142,7 +142,7 @@ LL | pub fn exit4(code: i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(i32) -> !` (for the current target)
found `unsafe extern "C" fn(i32)`
found `unsafe extern "C" fn(i32)`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "exit")]`, or `#[link_name = "exit"]`
= help: allow this lint if the signature is compatible

Expand Down
26 changes: 13 additions & 13 deletions tests/ui/lint/runtime-symbols.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub fn memmove() {}
| ^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void` (for the current target)
found `fn()`
found `fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memmove")]`, or `#[link_name = "memmove"]`
= note: `#[deny(invalid_runtime_symbol_definitions)]` on by default

Expand All @@ -16,7 +16,7 @@ LL | pub fn memset();
| ^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, i32, usize) -> *mut c_void` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memset")]`, or `#[link_name = "memset"]`

error: invalid definition of the runtime `memcmp` symbol used by the standard library
Expand All @@ -26,7 +26,7 @@ LL | pub fn memcmp();
| ^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32` (for the current target)
found `unsafe extern "C" fn()`
found `unsafe extern "C" fn()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcmp")]`, or `#[link_name = "memcmp"]`

error: invalid definition of the runtime `strlen` symbol used by the standard library
Expand All @@ -36,7 +36,7 @@ LL | pub static strlen: () = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const U8) -> usize` (for the current target)
found `()`
found `()`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "strlen")]`, or `#[link_name = "strlen"]`

error: invalid definition of the runtime `strlen` symbol used by the standard library
Expand All @@ -46,7 +46,7 @@ LL | static strlen2: Option<unsafe extern "C" fn(s: *const c_char)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const U8) -> usize` (for the current target)
found `unsafe extern "C" fn(*const U8)`
found `unsafe extern "C" fn(*const U8)`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "strlen")]`, or `#[link_name = "strlen"]`

error: invalid definition of the runtime `memcpy` symbol used by the standard library
Expand All @@ -56,7 +56,7 @@ LL | pub fn memcpy(dest: *mut c_void, src: *const c_void, n: usize) -> *mut
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void` (for the current target)
found `fn(*mut c_void, *const c_void, usize) -> *mut c_void`
found `fn(*mut c_void, *const c_void, usize) -> *mut c_void`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcpy")]`, or `#[link_name = "memcpy"]`

error: invalid definition of the runtime `bcmp` symbol used by the standard library
Expand All @@ -66,7 +66,7 @@ LL | pub unsafe extern "C" fn bcmp(s1: *const c_void, s2: *const c_void, n:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32` (for the current target)
found `unsafe extern "C" fn(*const c_void, *const c_void, usize, ...) -> i32`
found `unsafe extern "C" fn(*const c_void, *const c_void, usize, ...) -> i32`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "bcmp")]`, or `#[link_name = "bcmp"]`

error: invalid definition of the runtime `bcmp` symbol used by the standard library
Expand All @@ -76,7 +76,7 @@ LL | pub extern "C" fn bcmp_(s1: *const c_void, s2: *const c_void, n: usize)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32` (for the current target)
found `extern "C" fn(*const c_void, *const c_void, usize)`
found `extern "C" fn(*const c_void, *const c_void, usize)`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "bcmp")]`, or `#[link_name = "bcmp"]`

warning: suspicious definition of the runtime `memcpy` symbol used by the standard library
Expand All @@ -86,7 +86,7 @@ LL | pub extern "C" fn memcpy(dest: *mut c_void, src: *const c_void, n: i64)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void` (for the current target)
found `extern "C" fn(*mut c_void, *const c_void, i64) -> *mut c_void`
found `extern "C" fn(*mut c_void, *const c_void, i64) -> *mut c_void`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcpy")]`, or `#[link_name = "memcpy"]`
= help: allow this lint if the signature is compatible
= note: `#[warn(suspicious_runtime_symbol_definitions)]` on by default
Expand All @@ -98,7 +98,7 @@ LL | pub extern "C" fn memmove(dest: *mut c_void, src: *const c_void, n: i64
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void` (for the current target)
found `extern "C" fn(*mut c_void, *const c_void, i64) -> *mut c_void`
found `extern "C" fn(*mut c_void, *const c_void, i64) -> *mut c_void`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memmove")]`, or `#[link_name = "memmove"]`
= help: allow this lint if the signature is compatible

Expand All @@ -109,7 +109,7 @@ LL | fn memset(s: *mut c_void, c: c_int, n: usize) -> f64;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*mut c_void, i32, usize) -> *mut c_void` (for the current target)
found `unsafe extern "C" fn(*mut c_void, i32, usize) -> f64`
found `unsafe extern "C" fn(*mut c_void, i32, usize) -> f64`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memset")]`, or `#[link_name = "memset"]`
= help: allow this lint if the signature is compatible

Expand All @@ -120,7 +120,7 @@ LL | pub extern "C" fn bcmp_(s1: *const U8, s2: *const U8, n: usize) -> c_in
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32` (for the current target)
found `extern "C" fn(*const U8, *const U8, usize) -> i32`
found `extern "C" fn(*const U8, *const U8, usize) -> i32`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "bcmp")]`, or `#[link_name = "bcmp"]`
= help: allow this lint if the signature is compatible

Expand All @@ -131,7 +131,7 @@ LL | pub extern "C" fn strlen(s: *const u64) -> usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected `unsafe extern "C" fn(*const U8) -> usize` (for the current target)
found `extern "C" fn(*const u64) -> usize`
found `extern "C" fn(*const u64) -> usize`
= help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "strlen")]`, or `#[link_name = "strlen"]`
= help: allow this lint if the signature is compatible

Expand Down
Loading