2023-07-27 13:23:04 +00:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-03-07 14:40:55 +00:00
|
|
|
|
2021-02-20 13:52:56 +00:00
|
|
|
#![warn(clippy::inconsistent_struct_constructor)]
|
|
|
|
#![allow(clippy::redundant_field_names)]
|
|
|
|
#![allow(clippy::unnecessary_operation)]
|
|
|
|
#![allow(clippy::no_effect)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2023-03-07 14:40:55 +00:00
|
|
|
extern crate proc_macros;
|
|
|
|
|
2021-02-20 13:52:56 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
struct Foo {
|
|
|
|
x: i32,
|
|
|
|
y: i32,
|
|
|
|
z: i32,
|
|
|
|
}
|
|
|
|
|
2024-08-03 19:22:22 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
#[allow(clippy::inconsistent_struct_constructor)]
|
|
|
|
struct Bar {
|
|
|
|
x: i32,
|
|
|
|
y: i32,
|
|
|
|
z: i32,
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:52:56 +00:00
|
|
|
mod without_base {
|
|
|
|
use super::Foo;
|
|
|
|
|
2023-03-07 14:40:55 +00:00
|
|
|
#[proc_macros::inline_macros]
|
2021-02-20 13:52:56 +00:00
|
|
|
fn test() {
|
|
|
|
let x = 1;
|
|
|
|
let y = 1;
|
|
|
|
let z = 1;
|
|
|
|
|
|
|
|
// Should lint.
|
|
|
|
Foo { y, x, z };
|
|
|
|
|
2021-04-20 04:33:39 +00:00
|
|
|
// Should NOT lint.
|
|
|
|
// issue #7069.
|
2023-03-07 14:40:55 +00:00
|
|
|
inline!({
|
|
|
|
let x = 1;
|
|
|
|
let y = 1;
|
|
|
|
let z = 1;
|
|
|
|
Foo { y, x, z }
|
|
|
|
});
|
2021-04-20 04:33:39 +00:00
|
|
|
|
2022-07-13 14:48:32 +00:00
|
|
|
// Should NOT lint because the order is the same as in the definition.
|
2021-02-20 13:52:56 +00:00
|
|
|
Foo { x, y, z };
|
|
|
|
|
|
|
|
// Should NOT lint because z is not a shorthand init.
|
|
|
|
Foo { y, x, z: z };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod with_base {
|
|
|
|
use super::Foo;
|
|
|
|
|
|
|
|
fn test() {
|
|
|
|
let x = 1;
|
|
|
|
let z = 1;
|
|
|
|
|
|
|
|
// Should lint.
|
|
|
|
Foo {
|
|
|
|
z,
|
|
|
|
x,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Should NOT lint because the order is consistent with the definition.
|
|
|
|
Foo {
|
|
|
|
x,
|
|
|
|
z,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
// Should NOT lint because z is not a shorthand init.
|
|
|
|
Foo {
|
|
|
|
z: z,
|
|
|
|
x,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-03 19:22:22 +00:00
|
|
|
mod with_allow_ty_def {
|
|
|
|
use super::Bar;
|
|
|
|
|
|
|
|
fn test() {
|
|
|
|
let x = 1;
|
|
|
|
let y = 1;
|
|
|
|
let z = 1;
|
|
|
|
|
|
|
|
// Should NOT lint because `Bar` is defined with `#[allow(clippy::inconsistent_struct_constructor)]`
|
|
|
|
Bar { y, x, z };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 13:52:56 +00:00
|
|
|
fn main() {}
|