]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/needless_question_mark.rs
3 #![warn(clippy::needless_question_mark)]
5 clippy
::needless_return
,
6 clippy
::unnecessary_unwrap
,
7 clippy
::upper_case_acronyms
,
11 #![feature(custom_inner_attributes)]
18 magic
: Result
<usize, bool
>,
21 fn simple_option_bad1(to
: TO
) -> Option
<usize> {
22 // return as a statement
23 return Some(to
.magic?
);
26 // formatting will add a semi-colon, which would make
27 // this identical to the test case above
29 fn simple_option_bad2(to
: TO
) -> Option
<usize> {
30 // return as an expression
31 return Some(to
.magic?
)
34 fn simple_option_bad3(to
: TO
) -> Option
<usize> {
35 // block value "return"
39 fn simple_option_bad4(to
: Option
<TO
>) -> Option
<usize> {
40 // single line closure
41 to
.and_then(|t
| Some(t
.magic?
))
44 // formatting this will remove the block brackets, making
45 // this test identical to the one above
47 fn simple_option_bad5(to
: Option
<TO
>) -> Option
<usize> {
54 fn simple_result_bad1(tr
: TR
) -> Result
<usize, bool
> {
58 // formatting will add a semi-colon, which would make
59 // this identical to the test case above
61 fn simple_result_bad2(tr
: TR
) -> Result
<usize, bool
> {
65 fn simple_result_bad3(tr
: TR
) -> Result
<usize, bool
> {
69 fn simple_result_bad4(tr
: Result
<TR
, bool
>) -> Result
<usize, bool
> {
70 tr
.and_then(|t
| Ok(t
.magic?
))
73 // formatting this will remove the block brackets, making
74 // this test identical to the one above
76 fn simple_result_bad5(tr
: Result
<TR
, bool
>) -> Result
<usize, bool
> {
82 fn also_bad(tr
: Result
<TR
, bool
>) -> Result
<usize, bool
> {
90 fn false_positive_test
<U
, T
>(x
: Result
<(), U
>) -> Result
<(), T
>
99 // #6921 if a macro wraps an expr in Some( ) and the ? is in the macro use,
100 // the suggestion fails to apply; do not lint
101 macro_rules
! some_in_macro
{
103 || -> _ { Some($expr) }
()
109 let _x
= some_in_macro
!(x?
);
112 // this one is ok because both the ? and the Some are both inside the macro def
113 macro_rules
! some_and_qmark_in_macro
{
115 || -> Option
<_
> { Some(Some($expr)?) }
()
121 let _x
= some_and_qmark_in_macro
!(x?
);