Auto merge of #10342 - mitsuhiko:feature/question-mark-used, r=Alexendoo

Add question-mark-used lint

This lint complains when the question mark operator (try operator) is used.  This is a restriction lint that can be useful on local scopes where a custom error handling macro is supposed to be used to augment the error based on local scope data before returning.

Fixes #10340

---

changelog: New lint [`question_mark_used`]
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
<!-- changelog_checked -->
This commit is contained in:
bors 2023-02-16 14:21:43 +00:00
commit 52c8b536c9
6 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,15 @@
// non rustfixable
#![allow(unreachable_code)]
#![allow(dead_code)]
#![warn(clippy::question_mark_used)]
fn other_function() -> Option<i32> {
Some(32)
}
fn my_function() -> Option<i32> {
other_function()?;
None
}
fn main() {}

View file

@ -0,0 +1,11 @@
error: question mark operator was used
--> $DIR/question_mark_used.rs:11:5
|
LL | other_function()?;
| ^^^^^^^^^^^^^^^^^
|
= help: consider using a custom macro or match expression
= note: `-D clippy::question-mark-used` implied by `-D warnings`
error: aborting due to previous error