diff options
| author | bors <bors@rust-lang.org> | 2019-07-31 17:57:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-31 17:57:57 +0000 |
| commit | d1b4fc9853d80b3953dd5f2bae9d5d70ef7665ab (patch) | |
| tree | 5f7eccd3088464a3cbdd9817dc32cf04ee52cc79 | |
| parent | 128647d821d9ec26f1a3d525caa8d9cdd3ac9c81 (diff) | |
| parent | 38e7bd20f29bfb6693f32fe7347ace0b95c7e7eb (diff) | |
| download | rust-d1b4fc9853d80b3953dd5f2bae9d5d70ef7665ab.tar.gz rust-d1b4fc9853d80b3953dd5f2bae9d5d70ef7665ab.zip | |
Auto merge of #4313 - Manishearth:owl, r=yaahallo
Don't nudge people towards toilet closures when producing owl results `.map_err(drop)` should never be linted since sometimes you want to produce `Result<(), ()>` and the alternative is `.map_err(|_| ())`, which can be ugly. We don't seem to, but it's good to specifically test for this. changelog: none r? @yaahallo
| -rw-r--r-- | tests/ui/drop_forget_ref.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/drop_forget_ref.rs b/tests/ui/drop_forget_ref.rs index b3c75bc5764..b60f373e75e 100644 --- a/tests/ui/drop_forget_ref.rs +++ b/tests/ui/drop_forget_ref.rs @@ -55,3 +55,38 @@ fn test_similarly_named_function() { forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name std::mem::forget(&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) +} |
