rust-clippy/tests/ui/drop_ref.rs

75 lines
1.8 KiB
Rust
Raw Normal View History

2020-02-01 11:28:27 +00:00
#![warn(clippy::drop_ref)]
#![allow(clippy::toplevel_ref_arg)]
#![allow(clippy::map_err_ignore)]
#![allow(clippy::unnecessary_wraps)]
2020-02-01 11:28:27 +00:00
use std::mem::drop;
struct SomeStruct;
fn main() {
2017-02-08 13:58:07 +00:00
drop(&SomeStruct);
let mut owned1 = SomeStruct;
2017-02-08 13:58:07 +00:00
drop(&owned1);
drop(&&owned1);
drop(&mut owned1);
drop(owned1); //OK
let reference1 = &SomeStruct;
2017-02-08 13:58:07 +00:00
drop(reference1);
let reference2 = &mut SomeStruct;
2017-02-08 13:58:07 +00:00
drop(reference2);
2020-02-01 11:28:27 +00:00
let ref reference3 = SomeStruct;
drop(reference3);
}
#[allow(dead_code)]
fn test_generic_fn_drop<T>(val: T) {
2017-02-08 13:58:07 +00:00
drop(&val);
drop(val); //OK
}
#[allow(dead_code)]
fn test_similarly_named_function() {
fn drop<T>(_val: T) {}
drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name
2017-02-08 13:58:07 +00:00
std::mem::drop(&SomeStruct);
}
#[derive(Copy, Clone)]
pub struct Error;
fn produce_half_owl_error() -> Result<(), Error> {
Ok(())
}
fn produce_half_owl_ok() -> Result<bool, ()> {
Ok(true)
}
#[allow(dead_code)]
fn test_owl_result() -> Result<(), ()> {
produce_half_owl_error().map_err(|_| ())?;
produce_half_owl_ok().map(|_| ())?;
// the following should not be linted,
// we should not force users to use toilet closures
// to produce owl results when drop is more convenient
produce_half_owl_error().map_err(drop)?;
produce_half_owl_ok().map_err(drop)?;
Ok(())
}
#[allow(dead_code)]
fn test_owl_result_2() -> Result<u8, ()> {
produce_half_owl_error().map_err(|_| ())?;
produce_half_owl_ok().map(|_| ())?;
// the following should not be linted,
// we should not force users to use toilet closures
// to produce owl results when drop is more convenient
produce_half_owl_error().map_err(drop)?;
produce_half_owl_ok().map(drop)?;
Ok(1)
}