stabilize const_extern_fn
This commit is contained in:
parent
7cccef84cf
commit
b5ea5c23b3
@ -17,6 +17,7 @@ macro_rules! msrv_aliases {
|
||||
|
||||
// names may refer to stabilized feature flags or library items
|
||||
msrv_aliases! {
|
||||
1,83,0 { CONST_EXTERN_FN }
|
||||
1,83,0 { CONST_FLOAT_BITS_CONV }
|
||||
1,81,0 { LINT_REASONS_STABILIZATION }
|
||||
1,80,0 { BOX_INTO_ITER}
|
||||
@ -27,7 +28,7 @@ msrv_aliases! {
|
||||
1,68,0 { PATH_MAIN_SEPARATOR_STR }
|
||||
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
|
||||
1,63,0 { CLONE_INTO }
|
||||
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE, CONST_EXTERN_FN }
|
||||
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE, CONST_EXTERN_C_FN }
|
||||
1,59,0 { THREAD_LOCAL_CONST_INIT }
|
||||
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY, CONST_RAW_PTR_DEREF }
|
||||
1,56,0 { CONST_FN_UNION }
|
||||
|
@ -119,9 +119,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
|
||||
.iter()
|
||||
.any(|param| matches!(param.kind, GenericParamKind::Const { .. }));
|
||||
|
||||
if already_const(header)
|
||||
|| has_const_generic_params
|
||||
|| !could_be_const_with_abi(cx, &self.msrv, header.abi)
|
||||
if already_const(header) || has_const_generic_params || !could_be_const_with_abi(&self.msrv, header.abi)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -183,13 +181,13 @@ fn already_const(header: hir::FnHeader) -> bool {
|
||||
header.constness == Constness::Const
|
||||
}
|
||||
|
||||
fn could_be_const_with_abi(cx: &LateContext<'_>, msrv: &Msrv, abi: Abi) -> bool {
|
||||
fn could_be_const_with_abi(msrv: &Msrv, abi: Abi) -> bool {
|
||||
match abi {
|
||||
Abi::Rust => true,
|
||||
// `const extern "C"` was stabilized after 1.62.0
|
||||
Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_FN),
|
||||
Abi::C { unwind: false } => msrv.meets(msrvs::CONST_EXTERN_C_FN),
|
||||
// Rest ABIs are still unstable and need the `const_extern_fn` feature enabled.
|
||||
_ => cx.tcx.features().const_extern_fn,
|
||||
_ => msrv.meets(msrvs::CONST_EXTERN_FN),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,12 +186,6 @@ mod msrv {
|
||||
extern "C" fn c() {}
|
||||
}
|
||||
|
||||
mod with_extern {
|
||||
extern "C-unwind" fn c_unwind() {}
|
||||
extern "system" fn system() {}
|
||||
extern "system-unwind" fn system_unwind() {}
|
||||
}
|
||||
|
||||
mod with_ty_alias {
|
||||
type Foo = impl std::fmt::Debug;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
|
||||
#![allow(unsupported_calling_conventions)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
@ -204,3 +205,16 @@ mod with_ty_alias {
|
||||
// in this test.
|
||||
const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
|
||||
}
|
||||
|
||||
mod extern_fn {
|
||||
const extern "C-unwind" fn c_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
const extern "system" fn system() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
const extern "system-unwind" fn system_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub const extern "stdcall" fn std_call() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub const extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
|
||||
#![allow(unsupported_calling_conventions)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
@ -204,3 +205,16 @@ mod with_ty_alias {
|
||||
// in this test.
|
||||
fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
|
||||
}
|
||||
|
||||
mod extern_fn {
|
||||
extern "C-unwind" fn c_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
extern "system" fn system() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
extern "system-unwind" fn system_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub extern "stdcall" fn std_call() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:14:5
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:15:5
|
||||
|
|
||||
LL | / pub fn new() -> Self {
|
||||
LL | |
|
||||
@ -16,7 +16,7 @@ LL | pub const fn new() -> Self {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:20:5
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:21:5
|
||||
|
|
||||
LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
|
||||
LL | |
|
||||
@ -30,7 +30,7 @@ LL | const fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T;
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:27:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:28:1
|
||||
|
|
||||
LL | / fn one() -> i32 {
|
||||
LL | |
|
||||
@ -44,7 +44,7 @@ LL | const fn one() -> i32 {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:33:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:34:1
|
||||
|
|
||||
LL | / fn two() -> i32 {
|
||||
LL | |
|
||||
@ -59,7 +59,7 @@ LL | const fn two() -> i32 {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:40:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:41:1
|
||||
|
|
||||
LL | / fn string() -> String {
|
||||
LL | |
|
||||
@ -73,7 +73,7 @@ LL | const fn string() -> String {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:46:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:47:1
|
||||
|
|
||||
LL | / unsafe fn four() -> i32 {
|
||||
LL | |
|
||||
@ -87,7 +87,7 @@ LL | const unsafe fn four() -> i32 {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:52:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:53:1
|
||||
|
|
||||
LL | / fn generic<T>(t: T) -> T {
|
||||
LL | |
|
||||
@ -101,7 +101,7 @@ LL | const fn generic<T>(t: T) -> T {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:61:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:62:1
|
||||
|
|
||||
LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
|
||||
LL | |
|
||||
@ -115,7 +115,7 @@ LL | const fn generic_arr<T: Copy>(t: [T; 1]) -> T {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:75:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:76:9
|
||||
|
|
||||
LL | / pub fn b(self, a: &A) -> B {
|
||||
LL | |
|
||||
@ -129,7 +129,7 @@ LL | pub const fn b(self, a: &A) -> B {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:85:5
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:86:5
|
||||
|
|
||||
LL | / fn const_fn_stabilized_before_msrv(byte: u8) {
|
||||
LL | |
|
||||
@ -143,7 +143,7 @@ LL | const fn const_fn_stabilized_before_msrv(byte: u8) {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:97:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:98:1
|
||||
|
|
||||
LL | / fn msrv_1_46() -> i32 {
|
||||
LL | |
|
||||
@ -157,7 +157,7 @@ LL | const fn msrv_1_46() -> i32 {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:117:1
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:118:1
|
||||
|
|
||||
LL | fn d(this: D) {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@ -168,7 +168,7 @@ LL | const fn d(this: D) {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:125:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:126:9
|
||||
|
|
||||
LL | / fn deref_ptr_can_be_const(self) -> usize {
|
||||
LL | |
|
||||
@ -182,7 +182,7 @@ LL | const fn deref_ptr_can_be_const(self) -> usize {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:130:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:131:9
|
||||
|
|
||||
LL | / fn deref_copied_val(self) -> usize {
|
||||
LL | |
|
||||
@ -196,7 +196,7 @@ LL | const fn deref_copied_val(self) -> usize {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:141:5
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:142:5
|
||||
|
|
||||
LL | / fn union_access_can_be_const() {
|
||||
LL | |
|
||||
@ -211,7 +211,7 @@ LL | const fn union_access_can_be_const() {
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:149:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:150:9
|
||||
|
|
||||
LL | extern "C" fn c() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
@ -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:153:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:154:9
|
||||
|
|
||||
LL | extern fn implicit_c() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -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:170:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:171:9
|
||||
|
|
||||
LL | / pub fn new(strings: Vec<String>) -> Self {
|
||||
LL | | Self { strings }
|
||||
@ -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:175:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:176:9
|
||||
|
|
||||
LL | / pub fn empty() -> Self {
|
||||
LL | | Self { strings: Vec::new() }
|
||||
@ -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:186:9
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:187:9
|
||||
|
|
||||
LL | / pub fn new(text: String) -> Self {
|
||||
LL | | let vec = Vec::new();
|
||||
@ -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:205:5
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:206:5
|
||||
|
|
||||
LL | fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -283,5 +283,60 @@ help: make the function `const`
|
||||
LL | const fn alias_ty_is_projection(bar: <() as FooTrait>::Foo) {}
|
||||
| +++++
|
||||
|
||||
error: aborting due to 21 previous errors
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:210:5
|
||||
|
|
||||
LL | extern "C-unwind" fn c_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
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:212:5
|
||||
|
|
||||
LL | extern "system" fn system() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const extern "system" fn system() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:214:5
|
||||
|
|
||||
LL | extern "system-unwind" fn system_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const extern "system-unwind" fn system_unwind() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:216:5
|
||||
|
|
||||
LL | pub extern "stdcall" fn std_call() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | pub const extern "stdcall" fn std_call() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const.rs:218:5
|
||||
|
|
||||
LL | pub extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | pub const extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
| +++++
|
||||
|
||||
error: aborting due to 26 previous errors
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(unsupported_calling_conventions)]
|
||||
#![feature(const_extern_fn)]
|
||||
|
||||
const extern "C-unwind" fn c_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
const extern "system" fn system() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
const extern "system-unwind" fn system_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub const extern "stdcall" fn std_call() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub const extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
@ -1,14 +0,0 @@
|
||||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(unsupported_calling_conventions)]
|
||||
#![feature(const_extern_fn)]
|
||||
|
||||
extern "C-unwind" fn c_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
extern "system" fn system() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
extern "system-unwind" fn system_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub extern "stdcall" fn std_call() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
||||
pub extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
//~^ ERROR: this could be a `const fn`
|
@ -1,59 +0,0 @@
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:5:1
|
||||
|
|
||||
LL | extern "C-unwind" fn c_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::missing_const_for_fn)]`
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const extern "C-unwind" fn c_unwind() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:7:1
|
||||
|
|
||||
LL | extern "system" fn system() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const extern "system" fn system() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:9:1
|
||||
|
|
||||
LL | extern "system-unwind" fn system_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | const extern "system-unwind" fn system_unwind() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:11:1
|
||||
|
|
||||
LL | pub extern "stdcall" fn std_call() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | pub const extern "stdcall" fn std_call() {}
|
||||
| +++++
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> tests/ui/missing_const_for_fn/could_be_const_with_const_extern_fn.rs:13:1
|
||||
|
|
||||
LL | pub extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: make the function `const`
|
||||
|
|
||||
LL | pub const extern "stdcall-unwind" fn std_call_unwind() {}
|
||||
| +++++
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user