Skip to content

Commit

Permalink
Auto merge of rust-lang#132397 - m-ou-se:warn-missing-abi, r=Nadrieril
Browse files Browse the repository at this point in the history
Make missing_abi lint warn-by-default.

This makes the missing_abi lint warn-by-default, as suggested here: rust-lang/rfcs#3722 (comment)

This needs a lang FCP.
  • Loading branch information
bors committed Jan 8, 2025
2 parents 6afee11 + 585c976 commit c8c16f8
Show file tree
Hide file tree
Showing 64 changed files with 198 additions and 143 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ impl<T> Index<usize> for [T] {
}
}

extern {
extern "C" {
type VaListImpl;
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ fn main() {

assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);

extern {
extern "C" {
#[linkage = "weak"]
static ABC: *const u8;
}

{
extern {
extern "C" {
#[linkage = "weak"]
static ABC: *const u8;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/example/mod_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![allow(internal_features)]

#[link(name = "c")]
extern {}
extern "C" {}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::arch::x86_64::*;
use std::io::Write;
use std::ops::Coroutine;

extern {
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ declare_lint! {
///
/// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
pub MISSING_ABI,
Allow,
Warn,
"No declared ABI for extern declaration"
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/boxed_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ mod issue_3739 {
/// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code.
pub extern "C" fn do_not_warn_me(_c_pointer: Box<String>) -> () {}

#[allow(missing_abi)]
#[rustfmt::skip] // Forces rustfmt to not add ABI
pub extern fn do_not_warn_me_no_abi(_c_pointer: Box<String>) -> () {}

Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/tests/ui/boxed_local.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ LL | pub fn new(_needs_name: Box<PeekableSeekable<&()>>) -> () {}
| ^^^^^^^^^^^

error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:188:44
--> tests/ui/boxed_local.rs:189:44
|
LL | fn default_impl_x(self: Box<Self>, x: Box<u32>) -> u32 {
| ^

error: local variable doesn't need to be boxed here
--> tests/ui/boxed_local.rs:196:16
--> tests/ui/boxed_local.rs:197:16
|
LL | fn foo(x: Box<u32>) {}
| ^
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/doc/doc-fixable.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn parenthesized_word() {}
/// UXes
fn plural_acronym_test() {}

extern {
extern "C" {
/// `foo()`
fn in_extern();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/doc/doc-fixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn parenthesized_word() {}
/// UXes
fn plural_acronym_test() {}

extern {
extern "C" {
/// foo()
fn in_extern();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ mod msrv {
//~^ ERROR: this could be a `const fn`

#[rustfmt::skip]
#[allow(missing_abi)]
const extern fn implicit_c() {}
//~^ ERROR: this could be a `const fn`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ mod msrv {
//~^ ERROR: this could be a `const fn`

#[rustfmt::skip]
#[allow(missing_abi)]
extern fn implicit_c() {}
//~^ ERROR: this could be a `const fn`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ LL | const extern "C" fn c() {}
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:152:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:153:9
|
LL | extern fn implicit_c() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -233,7 +233,7 @@ LL | const extern fn implicit_c() {}
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:169:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:170:9
|
LL | / pub fn new(strings: Vec<String>) -> Self {
LL | | Self { strings }
Expand All @@ -246,7 +246,7 @@ LL | pub const fn new(strings: Vec<String>) -> Self {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:174:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:175:9
|
LL | / pub fn empty() -> Self {
LL | | Self { strings: Vec::new() }
Expand All @@ -259,7 +259,7 @@ LL | pub const fn empty() -> Self {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:185:9
--> tests/ui/missing_const_for_fn/could_be_const.rs:186:9
|
LL | / pub fn new(text: String) -> Self {
LL | | let vec = Vec::new();
Expand All @@ -273,7 +273,7 @@ LL | pub const fn new(text: String) -> Self {
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:204:5
--> tests/ui/missing_const_for_fn/could_be_const.rs:205:5
|
LL | fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -284,7 +284,7 @@ LL | const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:208:5
--> tests/ui/missing_const_for_fn/could_be_const.rs:209:5
|
LL | extern "C-unwind" fn c_unwind() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -295,7 +295,7 @@ LL | const extern "C-unwind" fn c_unwind() {}
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:210:5
--> tests/ui/missing_const_for_fn/could_be_const.rs:211:5
|
LL | extern "system" fn system() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -306,7 +306,7 @@ LL | const extern "system" fn system() {}
| +++++

error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:212:5
--> tests/ui/missing_const_for_fn/could_be_const.rs:213:5
|
LL | extern "system-unwind" fn system_unwind() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/issue-91231.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![feature(extern_types)]
#![allow(dead_code)]

extern {
extern "C" {
type Extern;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/attributes/key-value-expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bug!();
macro_rules! doc_comment {
($x:expr) => {
#[doc = $x]
extern {}
extern "C" {}
};
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-92157.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#[cfg(target_os = "linux")]
#[link(name = "c")]
extern {}
extern "C" {}

#[lang = "start"]
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/coherence/coherence-negative-impls-copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl !Copy for WithDrop {}

struct Type;
trait Trait {}
extern {
extern "C" {
type ExternType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const B: bool = true;

// ForeignType::unresolved - error

extern {
extern "C" {
type ForeignType;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![feature(extern_types)]

extern {
extern "C" {
type Opaque;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/delegation/glob-non-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait OtherTrait {
reuse Trait::*; //~ ERROR glob delegation is only supported in impls
}

extern {
extern "C" {
reuse Trait::*; //~ ERROR delegation is not supported in `extern` blocks
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/extern/extern-type-diag-not-similar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// because they are both extern types.

#![feature(extern_types)]
extern {
extern "C" {
type ShouldNotBeMentioned;
}

extern {
extern "C" {
type Foo;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/issue-10025.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
#![allow(dead_code)]
#![allow(dead_code, missing_abi)]

unsafe extern fn foo() {}
unsafe extern "C" fn bar() {}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extern/issue-95829.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ edition:2018

extern {
extern "C" {
async fn L() { //~ ERROR: incorrect function inside `extern` block
//~^ ERROR: functions in `extern` blocks cannot have `async` qualifier
async fn M() {}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/extern/issue-95829.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: incorrect function inside `extern` block
--> $DIR/issue-95829.rs:4:14
|
LL | extern {
| ------ `extern` blocks define existing foreign functions and functions inside of them cannot have a body
LL | extern "C" {
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
LL | async fn L() {
| ______________^___-
| | |
Expand All @@ -18,8 +18,8 @@ LL | | }
error: functions in `extern` blocks cannot have `async` qualifier
--> $DIR/issue-95829.rs:4:5
|
LL | extern {
| ------ in this `extern` block
LL | extern "C" {
| ---------- in this `extern` block
LL | async fn L() {
| ^^^^^ help: remove the `async` qualifier

Expand Down
1 change: 1 addition & 0 deletions tests/ui/extern/not-in-block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![crate_type = "lib"]
#![allow(missing_abi)]

extern fn none_fn(x: bool) -> i32;
//~^ ERROR free function without a body
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/extern/not-in-block.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: free function without a body
--> $DIR/not-in-block.rs:3:1
--> $DIR/not-in-block.rs:4:1
|
LL | extern fn none_fn(x: bool) -> i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -14,7 +14,7 @@ LL | extern { fn none_fn(x: bool) -> i32; }
| ~~~~~~~~ +

error: free function without a body
--> $DIR/not-in-block.rs:5:1
--> $DIR/not-in-block.rs:6:1
|
LL | extern "C" fn c_fn(x: bool) -> i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/foreign/issue-91370-foreign-fn-block-impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Regression test for issue #91370.

extern {
extern "C" {
//~^ `extern` blocks define existing foreign functions
fn f() {
//~^ incorrect function inside `extern` block
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/foreign/issue-91370-foreign-fn-block-impl.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: incorrect function inside `extern` block
--> $DIR/issue-91370-foreign-fn-block-impl.rs:5:8
|
LL | extern {
| ------ `extern` blocks define existing foreign functions and functions inside of them cannot have a body
LL | extern "C" {
| ---------- `extern` blocks define existing foreign functions and functions inside of them cannot have a body
LL |
LL | fn f() {
| ________^___-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct S;
#[rustc_legacy_const_generics(0usize)] //~ ERROR suffixed literals are not allowed in attributes
fn foo6<const X: usize>() {}

extern {
extern "C" {
#[rustc_legacy_const_generics(1)] //~ ERROR attribute should be applied to a function
fn foo7<const X: usize>(); //~ ERROR foreign items may not have const parameters
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/link-native-libs/issue-109144.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![crate_type = "lib"]
#[link(kind = "static", modifiers = "+whole-archive,+bundle")]
//~^ ERROR `#[link]` attribute requires a `name = "string"` argument
extern {}
extern "C" {}
10 changes: 9 additions & 1 deletion tests/ui/link-native-libs/suggest-libname-only-1.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
warning: extern declarations without an explicit ABI are deprecated
--> $DIR/suggest-libname-only-1.rs:7:1
|
LL | extern { }
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
|
= note: `#[warn(missing_abi)]` on by default

error: could not find native static library `libfoo.a`, perhaps an -L flag is missing?
|
= help: only provide the library name `foo`, not the full filename

error: aborting due to 1 previous error
error: aborting due to 1 previous error; 1 warning emitted

10 changes: 9 additions & 1 deletion tests/ui/link-native-libs/suggest-libname-only-2.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
warning: extern declarations without an explicit ABI are deprecated
--> $DIR/suggest-libname-only-2.rs:7:1
|
LL | extern { }
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
|
= note: `#[warn(missing_abi)]` on by default

error: could not find native static library `bar.lib`, perhaps an -L flag is missing?
|
= help: only provide the library name `bar`, not the full filename

error: aborting due to 1 previous error
error: aborting due to 1 previous error; 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/lint/function-item-references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn baz(x: u32, y: u32) -> u32 { x + y }
unsafe fn unsafe_fn() { }
extern "C" fn c_fn() { }
unsafe extern "C" fn unsafe_c_fn() { }
unsafe extern fn variadic(_x: u32, _args: ...) { }
unsafe extern "C" fn variadic(_x: u32, _args: ...) { }
fn take_generic_ref<'a, T>(_x: &'a T) { }
fn take_generic_array<T, const N: usize>(_x: [T; N]) { }
fn multiple_generic<T, U>(_x: T, _y: U) { }
Expand Down
Loading

0 comments on commit c8c16f8

Please sign in to comment.