Skip to content

Commit 33ed8b5

Browse files
committed
Remove needless_question_mark MSRV
1 parent a362a4d commit 33ed8b5

File tree

6 files changed

+13
-199
lines changed

6 files changed

+13
-199
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10761076
store.register_late_pass(move || box from_over_into::FromOverInto::new(msrv));
10771077
store.register_late_pass(move || box use_self::UseSelf::new(msrv));
10781078
store.register_late_pass(move || box missing_const_for_fn::MissingConstForFn::new(msrv));
1079-
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark::new(msrv));
1079+
store.register_late_pass(move || box needless_question_mark::NeedlessQuestionMark);
10801080
store.register_late_pass(move || box casts::Casts::new(msrv));
10811081
store.register_early_pass(move || box unnested_or_patterns::UnnestedOrPatterns::new(msrv));
10821082

clippy_lints/src/needless_question_mark.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::is_lang_ctor;
32
use clippy_utils::source::snippet;
43
use 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};
65
use if_chain::if_chain;
76
use rustc_errors::Applicability;
87
use rustc_hir::LangItem::{OptionSome, ResultOk};
98
use 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};
1311
use rustc_span::sym;
1412

1513
declare_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)]
8367
enum 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

140122
fn 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
}

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ macro_rules! define_Conf {
106106

107107
pub use self::helpers::Conf;
108108
define_Conf! {
109-
/// Lint: CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, NEEDLESS_QUESTION_MARK, PTR_AS_PTR. The minimum rust version that the project supports
109+
/// Lint: CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR. The minimum rust version that the project supports
110110
(msrv, "msrv": Option<String>, None),
111111
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
112112
(blacklisted_names, "blacklisted_names": Vec<String>, ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),

tests/ui/needless_question_mark.fixed

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -96,78 +96,6 @@ where
9696

9797
fn main() {}
9898

99-
mod question_mark_none {
100-
#![clippy::msrv = "1.12.0"]
101-
fn needless_question_mark_option() -> Option<usize> {
102-
struct TO {
103-
magic: Option<usize>,
104-
}
105-
let to = TO { magic: None };
106-
Some(to.magic?) // should not be triggered
107-
}
108-
109-
fn needless_question_mark_result() -> Result<usize, bool> {
110-
struct TO {
111-
magic: Result<usize, bool>,
112-
}
113-
let to = TO { magic: Ok(1_usize) };
114-
Ok(to.magic?) // should not be triggered
115-
}
116-
117-
fn main() {
118-
needless_question_mark_option();
119-
needless_question_mark_result();
120-
}
121-
}
122-
123-
mod question_mark_result {
124-
#![clippy::msrv = "1.21.0"]
125-
fn needless_question_mark_option() -> Option<usize> {
126-
struct TO {
127-
magic: Option<usize>,
128-
}
129-
let to = TO { magic: None };
130-
Some(to.magic?) // should not be triggered
131-
}
132-
133-
fn needless_question_mark_result() -> Result<usize, bool> {
134-
struct TO {
135-
magic: Result<usize, bool>,
136-
}
137-
let to = TO { magic: Ok(1_usize) };
138-
to.magic // should be triggered
139-
}
140-
141-
fn main() {
142-
needless_question_mark_option();
143-
needless_question_mark_result();
144-
}
145-
}
146-
147-
mod question_mark_both {
148-
#![clippy::msrv = "1.22.0"]
149-
fn needless_question_mark_option() -> Option<usize> {
150-
struct TO {
151-
magic: Option<usize>,
152-
}
153-
let to = TO { magic: None };
154-
to.magic // should be triggered
155-
}
156-
157-
fn needless_question_mark_result() -> Result<usize, bool> {
158-
struct TO {
159-
magic: Result<usize, bool>,
160-
}
161-
let to = TO { magic: Ok(1_usize) };
162-
to.magic // should be triggered
163-
}
164-
165-
fn main() {
166-
needless_question_mark_option();
167-
needless_question_mark_result();
168-
}
169-
}
170-
17199
// #6921 if a macro wraps an expr in Some( ) and the ? is in the macro use,
172100
// the suggestion fails to apply; do not lint
173101
macro_rules! some_in_macro {

tests/ui/needless_question_mark.rs

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -96,78 +96,6 @@ where
9696

9797
fn main() {}
9898

99-
mod question_mark_none {
100-
#![clippy::msrv = "1.12.0"]
101-
fn needless_question_mark_option() -> Option<usize> {
102-
struct TO {
103-
magic: Option<usize>,
104-
}
105-
let to = TO { magic: None };
106-
Some(to.magic?) // should not be triggered
107-
}
108-
109-
fn needless_question_mark_result() -> Result<usize, bool> {
110-
struct TO {
111-
magic: Result<usize, bool>,
112-
}
113-
let to = TO { magic: Ok(1_usize) };
114-
Ok(to.magic?) // should not be triggered
115-
}
116-
117-
fn main() {
118-
needless_question_mark_option();
119-
needless_question_mark_result();
120-
}
121-
}
122-
123-
mod question_mark_result {
124-
#![clippy::msrv = "1.21.0"]
125-
fn needless_question_mark_option() -> Option<usize> {
126-
struct TO {
127-
magic: Option<usize>,
128-
}
129-
let to = TO { magic: None };
130-
Some(to.magic?) // should not be triggered
131-
}
132-
133-
fn needless_question_mark_result() -> Result<usize, bool> {
134-
struct TO {
135-
magic: Result<usize, bool>,
136-
}
137-
let to = TO { magic: Ok(1_usize) };
138-
Ok(to.magic?) // should be triggered
139-
}
140-
141-
fn main() {
142-
needless_question_mark_option();
143-
needless_question_mark_result();
144-
}
145-
}
146-
147-
mod question_mark_both {
148-
#![clippy::msrv = "1.22.0"]
149-
fn needless_question_mark_option() -> Option<usize> {
150-
struct TO {
151-
magic: Option<usize>,
152-
}
153-
let to = TO { magic: None };
154-
Some(to.magic?) // should be triggered
155-
}
156-
157-
fn needless_question_mark_result() -> Result<usize, bool> {
158-
struct TO {
159-
magic: Result<usize, bool>,
160-
}
161-
let to = TO { magic: Ok(1_usize) };
162-
Ok(to.magic?) // should be triggered
163-
}
164-
165-
fn main() {
166-
needless_question_mark_option();
167-
needless_question_mark_result();
168-
}
169-
}
170-
17199
// #6921 if a macro wraps an expr in Some( ) and the ? is in the macro use,
172100
// the suggestion fails to apply; do not lint
173101
macro_rules! some_in_macro {

tests/ui/needless_question_mark.stderr

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,7 @@ LL | return Ok(t.magic?);
6767
| ^^^^^^^^^^^^ help: try: `t.magic`
6868

6969
error: question mark operator is useless here
70-
--> $DIR/needless_question_mark.rs:138:9
71-
|
72-
LL | Ok(to.magic?) // should be triggered
73-
| ^^^^^^^^^^^^^ help: try: `to.magic`
74-
75-
error: question mark operator is useless here
76-
--> $DIR/needless_question_mark.rs:154:9
77-
|
78-
LL | Some(to.magic?) // should be triggered
79-
| ^^^^^^^^^^^^^^^ help: try: `to.magic`
80-
81-
error: question mark operator is useless here
82-
--> $DIR/needless_question_mark.rs:162:9
83-
|
84-
LL | Ok(to.magic?) // should be triggered
85-
| ^^^^^^^^^^^^^ help: try: `to.magic`
86-
87-
error: question mark operator is useless here
88-
--> $DIR/needless_question_mark.rs:187:27
70+
--> $DIR/needless_question_mark.rs:115:27
8971
|
9072
LL | || -> Option<_> { Some(Some($expr)?) }()
9173
| ^^^^^^^^^^^^^^^^^^ help: try: `Some($expr)`
@@ -95,5 +77,5 @@ LL | let _x = some_and_qmark_in_macro!(x?);
9577
|
9678
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
9779

98-
error: aborting due to 15 previous errors
80+
error: aborting due to 12 previous errors
9981

0 commit comments

Comments
 (0)