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.
6 // aux-build:../../auxiliary/proc_macro_with_span.rs
8 #![warn(clippy::missing_const_for_fn)]
10 #![feature(custom_inner_attributes)]
13 extern crate proc_macro_with_span;
15 use proc_macro_with_span::with_span;
19 // This should not be linted because it's already const
20 const fn already_const() -> i32 {
25 // This should not be linted because it's already const
26 pub const fn already_const() -> i32 {
31 // Allowing on this function, because it would lint, which we don't want in this case.
32 #[allow(clippy::missing_const_for_fn)]
37 // We should not suggest to make this function `const` because `random()` is non-const
38 fn random_caller() -> u32 {
44 // We should not suggest to make this function `const` because const functions are not allowed to
45 // refer to a static variable
51 // Don't lint entrypoint functions
53 fn init(num: isize, something: *const *const u8) -> isize {
58 // This should not be suggested to be made const
59 // (rustc doesn't allow const trait methods)
62 // This should not be suggested to be made const either
68 // Don't lint in external macros (derive)
69 #[derive(PartialEq, Eq)]
70 struct Point(isize, isize);
72 impl std::ops::Add for Point {
75 // Don't lint in trait impls of derived methods
76 fn add(self, other: Self) -> Self {
77 Point(self.0 + other.0, self.1 + other.1)
89 // This can not be const because the type implements `Drop`.
96 // This can not be const because `a` implements `Drop`.
97 pub fn a(self, a: A) -> B {
103 fn const_generic_params<T, const N: usize>(t: &[T; N]) -> &[T; N] {
107 fn const_generic_return<T, const N: usize>(t: &[T]) -> &[T; N] {
108 let p = t.as_ptr() as *const [T; N];
113 // Do not lint this because it calls a function whose constness is unstable.
114 fn unstably_const_fn() {
115 helper::unstably_const_fn()
118 mod const_fn_stabilized_after_msrv {
119 #![clippy::msrv = "1.46.0"]
121 // Do not lint this because `u8::is_ascii_digit` is stabilized as a const function in 1.47.0.
122 fn const_fn_stabilized_after_msrv(byte: u8) {
123 byte.is_ascii_digit();
129 fn dont_check_in_proc_macro() {}