2023-03-11 05:44:18 -06:00
|
|
|
#![allow(
|
|
|
|
clippy::deref_addrof,
|
|
|
|
dead_code,
|
|
|
|
unused,
|
|
|
|
clippy::no_effect,
|
|
|
|
clippy::unnecessary_struct_initialization
|
|
|
|
)]
|
2019-09-25 12:49:56 -05:00
|
|
|
#![warn(clippy::unnecessary_operation)]
|
|
|
|
|
2023-12-08 07:33:28 -06:00
|
|
|
use std::fmt::Display;
|
|
|
|
use std::ops::Shl;
|
|
|
|
|
2019-09-25 12:49:56 -05:00
|
|
|
struct Tuple(i32);
|
|
|
|
struct Struct {
|
|
|
|
field: i32,
|
|
|
|
}
|
|
|
|
enum Enum {
|
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
|
|
|
}
|
|
|
|
struct DropStruct {
|
|
|
|
field: i32,
|
|
|
|
}
|
|
|
|
impl Drop for DropStruct {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct DropTuple(i32);
|
|
|
|
impl Drop for DropTuple {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
enum DropEnum {
|
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
|
|
|
}
|
|
|
|
impl Drop for DropEnum {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct FooString {
|
|
|
|
s: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_number() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2024-05-23 21:24:54 -05:00
|
|
|
const fn get_usize() -> usize {
|
2019-09-25 12:49:56 -05:00
|
|
|
0
|
|
|
|
}
|
|
|
|
fn get_struct() -> Struct {
|
|
|
|
Struct { field: 0 }
|
|
|
|
}
|
|
|
|
fn get_drop_struct() -> DropStruct {
|
|
|
|
DropStruct { field: 0 }
|
|
|
|
}
|
|
|
|
|
2023-12-08 07:33:28 -06:00
|
|
|
struct Cout;
|
|
|
|
|
|
|
|
impl<T> Shl<T> for Cout
|
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
fn shl(self, rhs: T) -> Self::Output {
|
|
|
|
println!("{}", rhs);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 12:49:56 -05:00
|
|
|
fn main() {
|
|
|
|
get_number();
|
|
|
|
get_number();
|
|
|
|
get_struct();
|
|
|
|
get_number();
|
|
|
|
get_number();
|
|
|
|
5;get_number();
|
|
|
|
get_number();
|
|
|
|
get_number();
|
|
|
|
5;6;get_number();
|
|
|
|
get_number();
|
|
|
|
get_number();
|
|
|
|
5;get_number();
|
|
|
|
42;get_number();
|
2021-09-08 09:31:47 -05:00
|
|
|
assert!([42, 55].len() > get_usize());
|
2019-09-25 12:49:56 -05:00
|
|
|
42;get_number();
|
|
|
|
get_number();
|
2021-09-08 09:31:47 -05:00
|
|
|
assert!([42; 55].len() > get_usize());
|
2019-09-25 12:49:56 -05:00
|
|
|
get_number();
|
|
|
|
String::from("blah");
|
|
|
|
|
|
|
|
// Do not warn
|
|
|
|
DropTuple(get_number());
|
|
|
|
DropStruct { field: get_number() };
|
|
|
|
DropStruct { field: get_number() };
|
|
|
|
DropStruct { ..get_drop_struct() };
|
|
|
|
DropEnum::Tuple(get_number());
|
|
|
|
DropEnum::Struct { field: get_number() };
|
2022-12-01 11:29:38 -06:00
|
|
|
|
|
|
|
// Issue #9954
|
|
|
|
fn one() -> i8 {
|
|
|
|
1
|
|
|
|
}
|
|
|
|
macro_rules! use_expr {
|
|
|
|
($($e:expr),*) => {{ $($e;)* }}
|
|
|
|
}
|
|
|
|
use_expr!(isize::MIN / -(one() as isize), i8::MIN / -one());
|
2023-12-08 07:33:28 -06:00
|
|
|
|
|
|
|
// Issue #11885
|
|
|
|
Cout << 16;
|
2024-01-31 15:09:55 -06:00
|
|
|
|
|
|
|
// Issue #11575
|
|
|
|
// Bad formatting is required to trigger the bug
|
|
|
|
#[rustfmt::skip]
|
|
|
|
'label: {
|
|
|
|
break 'label
|
|
|
|
};
|
2024-05-23 21:24:54 -05:00
|
|
|
let () = const {
|
2024-05-23 22:25:58 -05:00
|
|
|
[42, 55][get_usize()];
|
2024-05-23 21:24:54 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const _: () = {
|
2024-05-23 22:25:58 -05:00
|
|
|
[42, 55][get_usize()];
|
2024-05-23 21:24:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const fn foo() {
|
|
|
|
assert!([42, 55].len() > get_usize());
|
2019-09-25 12:49:56 -05:00
|
|
|
}
|