1 //! False-positive tests to ensure we don't suggest `const` for things where it would cause a
3 //! The .stderr output of this test should be empty. Otherwise it's a bug somewhere.
7 #![warn(clippy::missing_const_for_fn)]
8 #![allow(incomplete_features)]
9 #![feature(start, const_generics)]
10 #![feature(custom_inner_attributes)]
16 // This should not be linted because it's already const
17 const fn already_const() -> i32 {
22 // This should not be linted because it's already const
23 pub const fn already_const() -> i32 {
28 // Allowing on this function, because it would lint, which we don't want in this case.
29 #[allow(clippy::missing_const_for_fn)]
34 // We should not suggest to make this function `const` because `random()` is non-const
35 fn random_caller() -> u32 {
41 // We should not suggest to make this function `const` because const functions are not allowed to
42 // refer to a static variable
48 // Don't lint entrypoint functions
50 fn init(num: isize, something: *const *const u8) -> isize {
55 // This should not be suggested to be made const
56 // (rustc doesn't allow const trait methods)
59 // This should not be suggested to be made const either
65 // Don't lint in external macros (derive)
66 #[derive(PartialEq, Eq)]
67 struct Point(isize, isize);
69 impl std::ops::Add for Point {
72 // Don't lint in trait impls of derived methods
73 fn add(self, other: Self) -> Self {
74 Point(self.0 + other.0, self.1 + other.1)
86 // This can not be const because the type implements `Drop`.
93 // This can not be const because `a` implements `Drop`.
94 pub fn a(self, a: A) -> B {
100 fn const_generic_params<T, const N: usize>(t: &[T; N]) -> &[T; N] {
104 fn const_generic_return<T, const N: usize>(t: &[T]) -> &[T; N] {
105 let p = t.as_ptr() as *const [T; N];
110 // Do not lint this because it calls a function whose constness is unstable.
111 fn unstably_const_fn() {
112 helper::unstably_const_fn()
115 mod const_fn_stabilized_after_msrv {
116 #![clippy::msrv = "1.46.0"]
118 // Do not lint this because `u8::is_ascii_digit` is stabilized as a const function in 1.47.0.
119 fn const_fn_stabilized_after_msrv(byte: u8) {
120 byte.is_ascii_digit();