Skip to content

Commit 91ed606

Browse files
authored
Consistently refer to the ? operator (#14687)
Matches the `rustc` terminology changelog: none
2 parents 34f81f9 + 736be8b commit 91ed606

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

clippy_lints/src/methods/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4370,11 +4370,10 @@ declare_clippy_lint! {
43704370

43714371
declare_clippy_lint! {
43724372
/// ### What it does
4373-
///
4374-
/// Detect functions that end with `Option::and_then` or `Result::and_then`, and suggest using a question mark (`?`) instead.
4373+
/// Detect functions that end with `Option::and_then` or `Result::and_then`, and suggest using
4374+
/// the `?` operator instead.
43754375
///
43764376
/// ### Why is this bad?
4377-
///
43784377
/// The `and_then` method is used to chain a computation that returns an `Option` or a `Result`.
43794378
/// This can be replaced with the `?` operator, which is more concise and idiomatic.
43804379
///

clippy_lints/src/methods/return_and_then.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ pub(super) fn check<'tcx>(
5555
None => &body_snip,
5656
};
5757

58-
let msg = "use the question mark operator instead of an `and_then` call";
5958
let sugg = format!(
6059
"let {} = {}?;\n{}",
6160
arg_snip,
6261
recv_snip,
6362
reindent_multiline(inner, false, indent_of(cx, expr.span))
6463
);
6564

66-
span_lint_and_sugg(cx, RETURN_AND_THEN, expr.span, msg, "try", sugg, applicability);
65+
span_lint_and_sugg(
66+
cx,
67+
RETURN_AND_THEN,
68+
expr.span,
69+
"use the `?` operator instead of an `and_then` call",
70+
"try",
71+
sugg,
72+
applicability,
73+
);
6774
}

clippy_lints/src/question_mark.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ use rustc_span::symbol::Symbol;
2727

2828
declare_clippy_lint! {
2929
/// ### What it does
30-
/// Checks for expressions that could be replaced by the question mark operator.
30+
/// Checks for expressions that could be replaced by the `?` operator.
3131
///
3232
/// ### Why is this bad?
33-
/// Question mark usage is more idiomatic.
33+
/// Using the `?` operator is shorter and more idiomatic.
3434
///
3535
/// ### Example
3636
/// ```ignore
@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747
#[clippy::version = "pre 1.29.0"]
4848
pub QUESTION_MARK,
4949
style,
50-
"checks for expressions that could be replaced by the question mark operator"
50+
"checks for expressions that could be replaced by the `?` operator"
5151
}
5252

5353
pub struct QuestionMark {
@@ -280,7 +280,7 @@ fn expr_return_none_or_err(
280280
/// }
281281
/// ```
282282
///
283-
/// If it matches, it will suggest to use the question mark operator instead
283+
/// If it matches, it will suggest to use the `?` operator instead
284284
fn check_is_none_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
285285
if let Some(higher::If { cond, then, r#else }) = higher::If::hir(expr)
286286
&& !is_else_clause(cx.tcx, expr)

clippy_lints/src/question_mark_used.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustc_session::declare_lint_pass;
77

88
declare_clippy_lint! {
99
/// ### What it does
10-
/// Checks for expressions that use the question mark operator and rejects them.
10+
/// Checks for expressions that use the `?` operator and rejects them.
1111
///
1212
/// ### Why restrict this?
13-
/// Sometimes code wants to avoid the question mark operator because for instance a local
13+
/// Sometimes code wants to avoid the `?` operator because for instance a local
1414
/// block requires a macro to re-throw errors to attach additional information to the
1515
/// error.
1616
///
@@ -27,7 +27,7 @@ declare_clippy_lint! {
2727
#[clippy::version = "1.69.0"]
2828
pub QUESTION_MARK_USED,
2929
restriction,
30-
"complains if the question mark operator is used"
30+
"checks if the `?` operator is used"
3131
}
3232

3333
declare_lint_pass!(QuestionMarkUsed => [QUESTION_MARK_USED]);
@@ -40,15 +40,9 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed {
4040
}
4141

4242
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
43-
span_lint_and_then(
44-
cx,
45-
QUESTION_MARK_USED,
46-
expr.span,
47-
"question mark operator was used",
48-
|diag| {
49-
diag.help("consider using a custom macro or match expression");
50-
},
51-
);
43+
span_lint_and_then(cx, QUESTION_MARK_USED, expr.span, "the `?` operator was used", |diag| {
44+
diag.help("consider using a custom macro or match expression");
45+
});
5246
}
5347
}
5448
}

clippy_utils/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3101,7 +3101,7 @@ pub fn span_find_starting_semi(sm: &SourceMap, span: Span) -> Span {
31013101
sm.span_take_while(span, |&ch| ch == ' ' || ch == ';')
31023102
}
31033103

3104-
/// Returns whether the given let pattern and else body can be turned into a question mark
3104+
/// Returns whether the given let pattern and else body can be turned into the `?` operator
31053105
///
31063106
/// For this example:
31073107
/// ```ignore
@@ -3124,8 +3124,7 @@ pub fn span_find_starting_semi(sm: &SourceMap, span: Span) -> Span {
31243124
/// ```
31253125
///
31263126
/// We output `Some(a)` in the first instance, and `Some(FooBar { a, b })` in the second, because
3127-
/// the question mark operator is applicable here. Callers have to check whether we are in a
3128-
/// constant or not.
3127+
/// the `?` operator is applicable here. Callers have to check whether we are in a constant or not.
31293128
pub fn pat_and_expr_can_be_question_mark<'a, 'hir>(
31303129
cx: &LateContext<'_>,
31313130
pat: &'a Pat<'hir>,

tests/ui/question_mark_used.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: question mark operator was used
1+
error: the `?` operator was used
22
--> tests/ui/question_mark_used.rs:11:5
33
|
44
LL | other_function()?;

tests/ui/return_and_then.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: use the question mark operator instead of an `and_then` call
1+
error: use the `?` operator instead of an `and_then` call
22
--> tests/ui/return_and_then.rs:5:9
33
|
44
LL | / opt.and_then(|n| {
@@ -20,7 +20,7 @@ LL + ret += n;
2020
LL + if n > 1 { Some(ret) } else { None }
2121
|
2222

23-
error: use the question mark operator instead of an `and_then` call
23+
error: use the `?` operator instead of an `and_then` call
2424
--> tests/ui/return_and_then.rs:14:9
2525
|
2626
LL | opt.and_then(|n| test_opt_block(Some(n)))
@@ -32,7 +32,7 @@ LL ~ let n = opt?;
3232
LL + test_opt_block(Some(n))
3333
|
3434

35-
error: use the question mark operator instead of an `and_then` call
35+
error: use the `?` operator instead of an `and_then` call
3636
--> tests/ui/return_and_then.rs:19:9
3737
|
3838
LL | gen_option(1).and_then(|n| test_opt_block(Some(n)))
@@ -44,7 +44,7 @@ LL ~ let n = gen_option(1)?;
4444
LL + test_opt_block(Some(n))
4545
|
4646

47-
error: use the question mark operator instead of an `and_then` call
47+
error: use the `?` operator instead of an `and_then` call
4848
--> tests/ui/return_and_then.rs:24:9
4949
|
5050
LL | opt.and_then(|n| if n > 1 { Ok(n + 1) } else { Err(n) })
@@ -56,7 +56,7 @@ LL ~ let n = opt?;
5656
LL + if n > 1 { Ok(n + 1) } else { Err(n) }
5757
|
5858

59-
error: use the question mark operator instead of an `and_then` call
59+
error: use the `?` operator instead of an `and_then` call
6060
--> tests/ui/return_and_then.rs:29:9
6161
|
6262
LL | opt.and_then(|n| test_res_block(Ok(n)))
@@ -68,7 +68,7 @@ LL ~ let n = opt?;
6868
LL + test_res_block(Ok(n))
6969
|
7070

71-
error: use the question mark operator instead of an `and_then` call
71+
error: use the `?` operator instead of an `and_then` call
7272
--> tests/ui/return_and_then.rs:35:9
7373
|
7474
LL | Some("").and_then(|x| if x.len() > 2 { Some(3) } else { None })
@@ -80,7 +80,7 @@ LL ~ let x = Some("")?;
8080
LL + if x.len() > 2 { Some(3) } else { None }
8181
|
8282

83-
error: use the question mark operator instead of an `and_then` call
83+
error: use the `?` operator instead of an `and_then` call
8484
--> tests/ui/return_and_then.rs:41:9
8585
|
8686
LL | / Some(match (vec![1, 2, 3], vec![1, 2, 4]) {

0 commit comments

Comments
 (0)