2018-07-28 10:34:52 -05:00
|
|
|
|
#![warn(clippy::all)]
|
2022-10-06 02:44:38 -05:00
|
|
|
|
#![allow(dead_code, unused_unsafe)]
|
|
|
|
|
#![allow(clippy::missing_safety_doc, clippy::uninlined_format_args)]
|
2016-03-08 17:48:10 -06:00
|
|
|
|
|
2016-06-07 09:55:55 -05:00
|
|
|
|
// TOO_MANY_ARGUMENTS
|
2016-03-08 17:48:10 -06:00
|
|
|
|
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
|
|
|
|
|
|
2018-12-09 16:26:16 -06:00
|
|
|
|
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this function has too many arguments (8/7)
|
|
|
|
|
//~| NOTE: `-D clippy::too-many-arguments` implied by `-D warnings`
|
2016-03-08 17:48:10 -06:00
|
|
|
|
|
2019-05-01 14:32:54 -05:00
|
|
|
|
#[rustfmt::skip]
|
|
|
|
|
fn bad_multiline(
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this function has too many arguments (8/7)
|
2019-05-01 14:32:54 -05:00
|
|
|
|
one: u32,
|
|
|
|
|
two: u32,
|
|
|
|
|
three: &str,
|
|
|
|
|
four: bool,
|
|
|
|
|
five: f32,
|
|
|
|
|
six: f32,
|
|
|
|
|
seven: bool,
|
|
|
|
|
eight: ()
|
|
|
|
|
) {
|
|
|
|
|
let _one = one;
|
|
|
|
|
let _two = two;
|
|
|
|
|
let _three = three;
|
|
|
|
|
let _four = four;
|
|
|
|
|
let _five = five;
|
|
|
|
|
let _six = six;
|
|
|
|
|
let _seven = seven;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-08 10:21:47 -05:00
|
|
|
|
// don't lint extern fns
|
2018-12-09 16:26:16 -06:00
|
|
|
|
extern "C" fn extern_fn(
|
|
|
|
|
_one: u32,
|
|
|
|
|
_two: u32,
|
2019-11-06 11:38:10 -06:00
|
|
|
|
_three: *const u8,
|
2018-12-09 16:26:16 -06:00
|
|
|
|
_four: bool,
|
|
|
|
|
_five: f32,
|
|
|
|
|
_six: f32,
|
|
|
|
|
_seven: bool,
|
2019-11-06 11:38:10 -06:00
|
|
|
|
_eight: *const std::ffi::c_void,
|
2018-12-09 16:26:16 -06:00
|
|
|
|
) {
|
|
|
|
|
}
|
2016-08-08 10:21:47 -05:00
|
|
|
|
|
2016-06-07 09:55:55 -05:00
|
|
|
|
pub trait Foo {
|
2016-03-08 17:48:10 -06:00
|
|
|
|
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool);
|
|
|
|
|
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ());
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this function has too many arguments (8/7)
|
2017-02-08 07:58:07 -06:00
|
|
|
|
|
2016-06-07 09:55:55 -05:00
|
|
|
|
fn ptr(p: *const u8);
|
2016-03-08 17:48:10 -06:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 09:55:55 -05:00
|
|
|
|
pub struct Bar;
|
2016-03-08 17:48:10 -06:00
|
|
|
|
|
|
|
|
|
impl Bar {
|
|
|
|
|
fn good_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
|
|
|
|
|
fn bad_method(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this function has too many arguments (8/7)
|
2016-03-08 17:48:10 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ok, we don’t want to warn implementations
|
|
|
|
|
impl Foo for Bar {
|
|
|
|
|
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
|
|
|
|
|
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
|
2016-06-07 09:55:55 -05:00
|
|
|
|
|
|
|
|
|
fn ptr(p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
|
|
|
|
//~| NOTE: `-D clippy::not-unsafe-ptr-arg-deref` implied by `-D warnings`
|
2016-06-07 10:29:22 -05:00
|
|
|
|
println!("{:?}", unsafe { p.as_ref() });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
2016-06-07 10:29:22 -05:00
|
|
|
|
unsafe { std::ptr::read(p) };
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
2016-06-07 09:55:55 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOT_UNSAFE_PTR_ARG_DEREF
|
|
|
|
|
|
|
|
|
|
fn private(p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn public(p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2016-06-07 09:55:55 -05:00
|
|
|
|
println!("{:?}", unsafe { p.as_ref() });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2016-06-07 10:29:22 -05:00
|
|
|
|
unsafe { std::ptr::read(p) };
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2016-06-07 09:55:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 06:29:07 -06:00
|
|
|
|
type Alias = *const u8;
|
|
|
|
|
|
|
|
|
|
pub fn type_alias(p: Alias) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2022-01-17 06:29:07 -06:00
|
|
|
|
println!("{:?}", unsafe { p.as_ref() });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2022-01-17 06:29:07 -06:00
|
|
|
|
unsafe { std::ptr::read(p) };
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked `un
|
2022-01-17 06:29:07 -06:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 09:55:55 -05:00
|
|
|
|
impl Bar {
|
|
|
|
|
fn private(self, p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn public(self, p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
2016-06-07 09:55:55 -05:00
|
|
|
|
println!("{:?}", unsafe { p.as_ref() });
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
2016-06-07 10:29:22 -05:00
|
|
|
|
unsafe { std::ptr::read(p) };
|
2023-08-24 14:32:12 -05:00
|
|
|
|
//~^ ERROR: this public function might dereference a raw pointer but is not marked
|
2016-06-07 09:55:55 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn public_ok(self, p: *const u8) {
|
|
|
|
|
if !p.is_null() {
|
|
|
|
|
println!("{:p}", p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub unsafe fn public_unsafe(self, p: *const u8) {
|
|
|
|
|
println!("{}", unsafe { *p });
|
|
|
|
|
println!("{:?}", unsafe { p.as_ref() });
|
|
|
|
|
}
|
2016-03-08 17:48:10 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {}
|