Description
What it does
I have a project where the try operator / question mark operator ?
is banned for performance reasons. I know that longer term ideally that was not necessary, but right now it is. Because of this I would like to avoid accidentally reintroducing it.
There are also other cases where having the ability to deny the question mark operator locally is useful. For instance there are cases where local information has to be attached to errors returned which is why you sometimes see constructs like this:
macro_rules! bail {
($err:expr) => {{
let mut err = $err;
process_err(&mut err, state);
return Err(err);
}};
}
macro_rules! ctx_ok {
($expr:expr) => {
match $expr {
Ok(rv) => rv,
Err(err) => bail!(err),
}
};
}
In that case it would nice to be able to use #[deny(clippy::use_of_try_operator)]
on a block to disallow it.
Lint Name
use_of_try_operator
Category
restriction
Advantage
This is a lint that should never be turned on by default, it's only for specific code styles or local restrictions.
Drawbacks
It might be turned on accidentally by developers not sure of it's actual intention.
Example
let x = foo?;
Could be written as:
let x = ok!(foo);