diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-05-02 09:49:00 +0200 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-05-02 09:49:00 +0200 |
| commit | bce9fae97abb255c9fc6c994f50a052be4010a6f (patch) | |
| tree | d88048931c569432e321c522d34795966c1c6647 /src/tools/clippy/tests/ui/drop_ref.rs | |
| parent | 06c44816c1532e5ff08ad072f581fc068eb60e2e (diff) | |
| parent | d2708873ef711ec8ab45df1e984ecf24a96cd369 (diff) | |
| download | rust-bce9fae97abb255c9fc6c994f50a052be4010a6f.tar.gz rust-bce9fae97abb255c9fc6c994f50a052be4010a6f.zip | |
Add 'src/tools/clippy/' from commit 'd2708873ef711ec8ab45df1e984ecf24a96cd369'
git-subtree-dir: src/tools/clippy git-subtree-mainline: 06c44816c1532e5ff08ad072f581fc068eb60e2e git-subtree-split: d2708873ef711ec8ab45df1e984ecf24a96cd369
Diffstat (limited to 'src/tools/clippy/tests/ui/drop_ref.rs')
| -rw-r--r-- | src/tools/clippy/tests/ui/drop_ref.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/drop_ref.rs b/src/tools/clippy/tests/ui/drop_ref.rs new file mode 100644 index 00000000000..9181d789d4f --- /dev/null +++ b/src/tools/clippy/tests/ui/drop_ref.rs @@ -0,0 +1,72 @@ +#![warn(clippy::drop_ref)] +#![allow(clippy::toplevel_ref_arg)] + +use std::mem::drop; + +struct SomeStruct; + +fn main() { + drop(&SomeStruct); + + let mut owned1 = SomeStruct; + drop(&owned1); + drop(&&owned1); + drop(&mut owned1); + drop(owned1); //OK + + let reference1 = &SomeStruct; + drop(reference1); + + let reference2 = &mut SomeStruct; + drop(reference2); + + let ref reference3 = SomeStruct; + drop(reference3); +} + +#[allow(dead_code)] +fn test_generic_fn_drop<T>(val: T) { + 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 + 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) +} |
