cleanup spaghetti code
This commit is contained in:
parent
0e233492d3
commit
5692677b3b
5 changed files with 88 additions and 39 deletions
|
|
@ -127,6 +127,7 @@ with_span! {
|
|||
fn dont_check_in_proc_macro() {}
|
||||
}
|
||||
|
||||
// Do not lint `String` has `Vec<u8>`, which cannot be dropped in const contexts
|
||||
fn a(this: String) {}
|
||||
|
||||
enum A {
|
||||
|
|
@ -134,6 +135,25 @@ enum A {
|
|||
N,
|
||||
}
|
||||
|
||||
// Same here.
|
||||
fn b(this: A) {}
|
||||
|
||||
// Minimized version of `a`.
|
||||
fn c(this: Vec<u16>) {}
|
||||
|
||||
struct F(A);
|
||||
|
||||
// Do not lint
|
||||
fn f(this: F) {}
|
||||
|
||||
// Do not lint
|
||||
fn g<T>(this: T) {}
|
||||
|
||||
struct Issue10617(String);
|
||||
|
||||
impl Issue10617 {
|
||||
// Do not lint
|
||||
pub fn name(self) -> String {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#![warn(clippy::missing_const_for_fn)]
|
||||
#![allow(incomplete_features, clippy::let_and_return)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
|
|
@ -87,3 +89,14 @@ fn msrv_1_46() -> i32 {
|
|||
|
||||
// Should not be const
|
||||
fn main() {}
|
||||
|
||||
struct D;
|
||||
|
||||
impl const Drop for D {
|
||||
fn drop(&mut self) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
// Lint this, since it can be dropped in const contexts
|
||||
fn d(this: D) {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:12:5
|
||||
--> $DIR/could_be_const.rs:14:5
|
||||
|
|
||||
LL | / pub fn new() -> Self {
|
||||
LL | | Self { guess: 42 }
|
||||
|
|
@ -9,7 +9,7 @@ LL | | }
|
|||
= note: `-D clippy::missing-const-for-fn` implied by `-D warnings`
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:16:5
|
||||
--> $DIR/could_be_const.rs:18:5
|
||||
|
|
||||
LL | / fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
|
||||
LL | | b
|
||||
|
|
@ -17,7 +17,7 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:22:1
|
||||
--> $DIR/could_be_const.rs:24:1
|
||||
|
|
||||
LL | / fn one() -> i32 {
|
||||
LL | | 1
|
||||
|
|
@ -25,7 +25,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:27:1
|
||||
--> $DIR/could_be_const.rs:29:1
|
||||
|
|
||||
LL | / fn two() -> i32 {
|
||||
LL | | let abc = 2;
|
||||
|
|
@ -34,7 +34,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:33:1
|
||||
--> $DIR/could_be_const.rs:35:1
|
||||
|
|
||||
LL | / fn string() -> String {
|
||||
LL | | String::new()
|
||||
|
|
@ -42,7 +42,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:38:1
|
||||
--> $DIR/could_be_const.rs:40:1
|
||||
|
|
||||
LL | / unsafe fn four() -> i32 {
|
||||
LL | | 4
|
||||
|
|
@ -50,7 +50,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:43:1
|
||||
--> $DIR/could_be_const.rs:45:1
|
||||
|
|
||||
LL | / fn generic<T>(t: T) -> T {
|
||||
LL | | t
|
||||
|
|
@ -58,7 +58,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:51:1
|
||||
--> $DIR/could_be_const.rs:53:1
|
||||
|
|
||||
LL | / fn generic_arr<T: Copy>(t: [T; 1]) -> T {
|
||||
LL | | t[0]
|
||||
|
|
@ -66,7 +66,7 @@ LL | | }
|
|||
| |_^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:64:9
|
||||
--> $DIR/could_be_const.rs:66:9
|
||||
|
|
||||
LL | / pub fn b(self, a: &A) -> B {
|
||||
LL | | B
|
||||
|
|
@ -74,7 +74,7 @@ LL | | }
|
|||
| |_________^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:73:5
|
||||
--> $DIR/could_be_const.rs:75:5
|
||||
|
|
||||
LL | / fn const_fn_stabilized_before_msrv(byte: u8) {
|
||||
LL | | byte.is_ascii_digit();
|
||||
|
|
@ -82,12 +82,18 @@ LL | | }
|
|||
| |_____^
|
||||
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:84:1
|
||||
--> $DIR/could_be_const.rs:86:1
|
||||
|
|
||||
LL | / fn msrv_1_46() -> i32 {
|
||||
LL | | 46
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
error: this could be a `const fn`
|
||||
--> $DIR/could_be_const.rs:102:1
|
||||
|
|
||||
LL | fn d(this: D) {}
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue