rust/tests/ui/functions.rs

105 lines
2.5 KiB
Rust
Raw Normal View History

2018-07-28 17:34:52 +02:00
#![warn(clippy::all)]
2016-03-09 00:48:10 +01:00
#![allow(dead_code)]
2019-10-02 17:19:30 +02:00
#![allow(unused_unsafe, clippy::missing_safety_doc)]
2016-03-09 00:48:10 +01:00
// TOO_MANY_ARGUMENTS
2016-03-09 00:48:10 +01:00
fn good(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool) {}
2018-12-09 23:26:16 +01:00
fn bad(_one: u32, _two: u32, _three: &str, _four: bool, _five: f32, _six: f32, _seven: bool, _eight: ()) {}
2016-03-09 00:48:10 +01:00
#[rustfmt::skip]
fn bad_multiline(
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;
}
// don't lint extern fns
2018-12-09 23:26:16 +01:00
extern "C" fn extern_fn(
_one: u32,
_two: u32,
_three: *const u8,
2018-12-09 23:26:16 +01:00
_four: bool,
_five: f32,
_six: f32,
_seven: bool,
_eight: *const std::ffi::c_void,
2018-12-09 23:26:16 +01:00
) {
}
pub trait Foo {
2016-03-09 00:48:10 +01: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: ());
2017-02-08 14:58:07 +01:00
fn ptr(p: *const u8);
2016-03-09 00:48:10 +01:00
}
pub struct Bar;
2016-03-09 00:48:10 +01: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: ()) {}
}
// ok, we dont 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: ()) {}
fn ptr(p: *const u8) {
println!("{}", unsafe { *p });
println!("{:?}", unsafe { p.as_ref() });
unsafe { std::ptr::read(p) };
}
}
// NOT_UNSAFE_PTR_ARG_DEREF
fn private(p: *const u8) {
println!("{}", unsafe { *p });
}
pub fn public(p: *const u8) {
println!("{}", unsafe { *p });
println!("{:?}", unsafe { p.as_ref() });
unsafe { std::ptr::read(p) };
}
impl Bar {
fn private(self, p: *const u8) {
println!("{}", unsafe { *p });
}
pub fn public(self, p: *const u8) {
println!("{}", unsafe { *p });
println!("{:?}", unsafe { p.as_ref() });
unsafe { std::ptr::read(p) };
}
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-09 00:48:10 +01:00
}
fn main() {}