11use clippy_utils:: diagnostics:: span_lint_and_sugg;
2- use clippy_utils:: is_lang_ctor;
32use clippy_utils:: source:: snippet;
43use clippy_utils:: ty:: is_type_diagnostic_item;
5- use clippy_utils:: { differing_macro_contexts, meets_msrv } ;
4+ use clippy_utils:: { differing_macro_contexts, is_lang_ctor } ;
65use if_chain:: if_chain;
76use rustc_errors:: Applicability ;
87use rustc_hir:: LangItem :: { OptionSome , ResultOk } ;
98use rustc_hir:: { Body , Expr , ExprKind , LangItem , MatchSource , QPath } ;
10- use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
11- use rustc_semver:: RustcVersion ;
12- use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
9+ use rustc_lint:: { LateContext , LateLintPass } ;
10+ use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1311use rustc_span:: sym;
1412
1513declare_clippy_lint ! {
@@ -63,21 +61,7 @@ declare_clippy_lint! {
6361 "Suggest `value.inner_option` instead of `Some(value.inner_option?)`. The same goes for `Result<T, E>`."
6462}
6563
66- const NEEDLESS_QUESTION_MARK_RESULT_MSRV : RustcVersion = RustcVersion :: new ( 1 , 13 , 0 ) ;
67- const NEEDLESS_QUESTION_MARK_OPTION_MSRV : RustcVersion = RustcVersion :: new ( 1 , 22 , 0 ) ;
68-
69- pub struct NeedlessQuestionMark {
70- msrv : Option < RustcVersion > ,
71- }
72-
73- impl NeedlessQuestionMark {
74- #[ must_use]
75- pub fn new ( msrv : Option < RustcVersion > ) -> Self {
76- Self { msrv }
77- }
78- }
79-
80- impl_lint_pass ! ( NeedlessQuestionMark => [ NEEDLESS_QUESTION_MARK ] ) ;
64+ declare_lint_pass ! ( NeedlessQuestionMark => [ NEEDLESS_QUESTION_MARK ] ) ;
8165
8266#[ derive( Debug ) ]
8367enum SomeOkCall < ' a > {
@@ -111,7 +95,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
11195 _ => return ,
11296 } ;
11397
114- if let Some ( ok_some_call) = is_some_or_ok_call ( self , cx, e) {
98+ if let Some ( ok_some_call) = is_some_or_ok_call ( cx, e) {
11599 emit_lint ( cx, & ok_some_call) ;
116100 }
117101 }
@@ -127,14 +111,12 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
127111
128112 if_chain ! {
129113 if let Some ( expr) = expr_opt;
130- if let Some ( ok_some_call) = is_some_or_ok_call( self , cx, expr) ;
114+ if let Some ( ok_some_call) = is_some_or_ok_call( cx, expr) ;
131115 then {
132116 emit_lint( cx, & ok_some_call) ;
133117 }
134118 } ;
135119 }
136-
137- extract_msrv_attr ! ( LateContext ) ;
138120}
139121
140122fn emit_lint ( cx : & LateContext < ' _ > , expr : & SomeOkCall < ' _ > ) {
@@ -153,11 +135,7 @@ fn emit_lint(cx: &LateContext<'_>, expr: &SomeOkCall<'_>) {
153135 ) ;
154136}
155137
156- fn is_some_or_ok_call < ' a > (
157- nqml : & NeedlessQuestionMark ,
158- cx : & ' a LateContext < ' _ > ,
159- expr : & ' a Expr < ' _ > ,
160- ) -> Option < SomeOkCall < ' a > > {
138+ fn is_some_or_ok_call < ' a > ( cx : & ' a LateContext < ' _ > , expr : & ' a Expr < ' _ > ) -> Option < SomeOkCall < ' a > > {
161139 if_chain ! {
162140 // Check outer expression matches CALL_IDENT(ARGUMENT) format
163141 if let ExprKind :: Call ( path, args) = & expr. kind;
@@ -188,8 +166,7 @@ fn is_some_or_ok_call<'a>(
188166 let inner_is_some = is_type_diagnostic_item( cx, inner_ty, sym:: option_type) ;
189167
190168 // Check for Option MSRV
191- let meets_option_msrv = meets_msrv( nqml. msrv. as_ref( ) , & NEEDLESS_QUESTION_MARK_OPTION_MSRV ) ;
192- if outer_is_some && inner_is_some && meets_option_msrv {
169+ if outer_is_some && inner_is_some {
193170 return Some ( SomeOkCall :: SomeCall ( expr, inner_expr) ) ;
194171 }
195172
@@ -202,8 +179,7 @@ fn is_some_or_ok_call<'a>(
202179 let does_not_call_from = !has_implicit_error_from( cx, expr, inner_expr) ;
203180
204181 // Must meet Result MSRV
205- let meets_result_msrv = meets_msrv( nqml. msrv. as_ref( ) , & NEEDLESS_QUESTION_MARK_RESULT_MSRV ) ;
206- if outer_is_result && inner_is_result && does_not_call_from && meets_result_msrv {
182+ if outer_is_result && inner_is_result && does_not_call_from {
207183 return Some ( SomeOkCall :: OkCall ( expr, inner_expr) ) ;
208184 }
209185 }
0 commit comments