diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-09-21 17:07:11 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2021-09-30 08:31:04 +0300 |
commit | 581c3f0ee0d16a42ec3e74498d96da251a90672b (patch) | |
tree | e64f2cb02441bdbc2e13facde5de38948aba6276 /ffi-macros/src/lib.rs | |
parent | 75b5b3fbbf8c33d10fd30e21f645b8ef1513363a (diff) |
Use the now-idiomatic option? syntax
This works in Rust now:
foo?;
as a replacement for:
if foo.is_none() {
return None;
}
It's similar to ? for error handling and can only be used in functions
that return an Option.
The instance of this in a macro caused the problem to be reported a
lot of time, once per time the macro was used, but luckily it can
could be fixed in only one place. Magic!
Found by clippy lint question_mark:
https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
Diffstat (limited to 'ffi-macros/src/lib.rs')
-rw-r--r-- | ffi-macros/src/lib.rs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs index 07093733..ab4e295f 100644 --- a/ffi-macros/src/lib.rs +++ b/ffi-macros/src/lib.rs @@ -584,11 +584,9 @@ fn derive_conversion_functions(mut st: syn::ItemStruct, crate::Maybe<#wrapper #generics> { fn ref_mut_raw(self) -> Option<& #ref_lifetime mut #wrapped> { - if self.is_none() { - return None; - } + self?; let wrapper = unsafe { - &mut (*self.unwrap().as_ptr()) + &mut (*self?.as_ptr()) }; wrapper.assert_tag(); match wrapper.0 { |