Skip to content

Commit d1b4fc9

Browse files
committed
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
2 parents 128647d + 38e7bd2 commit d1b4fc9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/ui/drop_forget_ref.rs

+35
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,38 @@ fn test_similarly_named_function() {
5555
forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name
5656
std::mem::forget(&SomeStruct);
5757
}
58+
59+
#[derive(Copy, Clone)]
60+
pub struct Error;
61+
fn produce_half_owl_error() -> Result<(), Error> {
62+
Ok(())
63+
}
64+
65+
fn produce_half_owl_ok() -> Result<bool, ()> {
66+
Ok(true)
67+
}
68+
69+
#[allow(dead_code)]
70+
fn test_owl_result() -> Result<(), ()> {
71+
produce_half_owl_error().map_err(|_| ())?;
72+
produce_half_owl_ok().map(|_| ())?;
73+
// the following should not be linted,
74+
// we should not force users to use toilet closures
75+
// to produce owl results when drop is more convenient
76+
produce_half_owl_error().map_err(drop)?;
77+
produce_half_owl_ok().map_err(drop)?;
78+
Ok(())
79+
}
80+
81+
82+
#[allow(dead_code)]
83+
fn test_owl_result_2() -> Result<u8, ()> {
84+
produce_half_owl_error().map_err(|_| ())?;
85+
produce_half_owl_ok().map(|_| ())?;
86+
// the following should not be linted,
87+
// we should not force users to use toilet closures
88+
// to produce owl results when drop is more convenient
89+
produce_half_owl_error().map_err(drop)?;
90+
produce_half_owl_ok().map(drop)?;
91+
Ok(1)
92+
}

0 commit comments

Comments
 (0)