Skip to content

Commit ebd8d31

Browse files
committed
Auto merge of #11055 - smoelius:try-this, r=dswij
"try this" -> "try" Current help messages contain a mix of "try", "try this", and one "try this instead". In the spirit of #10631, this PR adopts the first, as it is the most concise. It also updates the `lint_message_conventions` test to catch cases of "try this". (Aside: #10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.) changelog: Make help messages more concise ("try this" -> "try").
2 parents b46033e + 420f3d1 commit ebd8d31

File tree

105 files changed

+682
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+682
-680
lines changed

clippy_lints/src/dereference.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
589589
pat.spans,
590590
"this pattern creates a reference to a reference",
591591
|diag| {
592-
diag.multipart_suggestion("try this", replacements, app);
592+
diag.multipart_suggestion("try", replacements, app);
593593
},
594594
);
595595
}
@@ -1531,7 +1531,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
15311531
Mutability::Not => "explicit `deref` method call",
15321532
Mutability::Mut => "explicit `deref_mut` method call",
15331533
},
1534-
"try this",
1534+
"try",
15351535
format!("{addr_of_str}{deref_str}{expr_str}"),
15361536
app,
15371537
);
@@ -1593,7 +1593,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
15931593
} else {
15941594
format!("{prefix}{snip}")
15951595
};
1596-
diag.span_suggestion(data.span, "try this", sugg, app);
1596+
diag.span_suggestion(data.span, "try", sugg, app);
15971597
},
15981598
);
15991599
},
@@ -1620,7 +1620,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
16201620
|diag| {
16211621
let mut app = Applicability::MachineApplicable;
16221622
let snip = snippet_with_context(cx, expr.span, data.span.ctxt(), "..", &mut app).0;
1623-
diag.span_suggestion(data.span, "try this", snip.into_owned(), app);
1623+
diag.span_suggestion(data.span, "try", snip.into_owned(), app);
16241624
},
16251625
);
16261626
},

clippy_lints/src/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
186186
MAP_ENTRY,
187187
expr.span,
188188
&format!("usage of `contains_key` followed by `insert` on a `{}`", map_ty.name()),
189-
"try this",
189+
"try",
190190
sugg,
191191
app,
192192
);

clippy_lints/src/explicit_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
100100
EXPLICIT_WRITE,
101101
expr.span,
102102
&format!("use of `{used}.unwrap()`"),
103-
"try this",
103+
"try",
104104
format!("{prefix}{sugg_mac}!({inputs_snippet})"),
105105
applicability,
106106
);

clippy_lints/src/init_numbered_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
7171
INIT_NUMBERED_FIELDS,
7272
e.span,
7373
"used a field initializer for a tuple struct",
74-
"try this instead",
74+
"try",
7575
snippet,
7676
appl,
7777
);

clippy_lints/src/loops/missing_spin_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &'
4343
MISSING_SPIN_LOOP,
4444
body.span,
4545
"busy-waiting loop should at least have a spin loop hint",
46-
"try this",
46+
"try",
4747
(if is_no_std_crate(cx) {
4848
"{ core::hint::spin_loop() }"
4949
} else {

clippy_lints/src/map_unit_fn.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn lint_map_unit_fn(
226226
);
227227

228228
span_lint_and_then(cx, lint, expr.span, &msg, |diag| {
229-
diag.span_suggestion(stmt.span, "try this", suggestion, applicability);
229+
diag.span_suggestion(stmt.span, "try", suggestion, applicability);
230230
});
231231
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
232232
let msg = suggestion_msg("closure", map_type);
@@ -241,15 +241,15 @@ fn lint_map_unit_fn(
241241
snippet_with_applicability(cx, var_arg.span, "_", &mut applicability),
242242
snippet_with_context(cx, reduced_expr_span, var_arg.span.ctxt(), "_", &mut applicability).0,
243243
);
244-
diag.span_suggestion(stmt.span, "try this", suggestion, applicability);
244+
diag.span_suggestion(stmt.span, "try", suggestion, applicability);
245245
} else {
246246
let suggestion = format!(
247247
"if let {0}({1}) = {2} {{ ... }}",
248248
variant,
249249
snippet(cx, binding.pat.span, "_"),
250250
snippet(cx, var_arg.span, "_"),
251251
);
252-
diag.span_suggestion(stmt.span, "try this", suggestion, Applicability::HasPlaceholders);
252+
diag.span_suggestion(stmt.span, "try", suggestion, Applicability::HasPlaceholders);
253253
}
254254
});
255255
}

clippy_lints/src/matches/infallible_destructuring_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
2828
local.span,
2929
"you seem to be trying to use `match` to destructure a single infallible pattern. \
3030
Consider using `let`",
31-
"try this",
31+
"try",
3232
format!(
3333
"let {}({}{}) = {};",
3434
snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),

clippy_lints/src/matches/manual_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn check<'tcx>(
143143
MANUAL_FILTER,
144144
expr.span,
145145
"manual implementation of `Option::filter`",
146-
"try this",
146+
"try",
147147
if sugg_info.needs_brackets {
148148
format!(
149149
"{{ {}{}.filter({body_str}) }}",

clippy_lints/src/matches/manual_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn check<'tcx>(
5858
MANUAL_MAP,
5959
expr.span,
6060
"manual implementation of `Option::map`",
61-
"try this",
61+
"try",
6262
if sugg_info.needs_brackets {
6363
format!(
6464
"{{ {}{}.map({}) }}",

clippy_lints/src/matches/match_as_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
4646
MATCH_AS_REF,
4747
expr.span,
4848
&format!("use `{suggestion}()` instead"),
49-
"try this",
49+
"try",
5050
format!(
5151
"{}.{suggestion}(){cast}",
5252
snippet_with_applicability(cx, ex.span, "_", &mut applicability),

clippy_lints/src/matches/match_like_matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ where
139139
MATCH_LIKE_MATCHES_MACRO,
140140
expr.span,
141141
&format!("{} expression looks like `matches!` macro", if is_if_let { "if let .. else" } else { "match" }),
142-
"try this",
142+
"try",
143143
format!(
144144
"{}matches!({}, {pat_and_guard})",
145145
if b0 { "" } else { "!" },

clippy_lints/src/matches/match_on_vec_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'_>) {
2222
MATCH_ON_VEC_ITEMS,
2323
scrutinee.span,
2424
"indexing into a vector may panic",
25-
"try this",
25+
"try",
2626
format!(
2727
"{}.get({})",
2828
snippet(cx, vec.span, ".."),

clippy_lints/src/matches/match_wild_enum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
143143
MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
144144
wildcard_span,
145145
"wildcard matches only a single variant and will also match any future added variants",
146-
"try this",
146+
"try",
147147
format_suggestion(x),
148148
Applicability::MaybeIncorrect,
149149
),
@@ -161,7 +161,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
161161
WILDCARD_ENUM_MATCH_ARM,
162162
wildcard_span,
163163
message,
164-
"try this",
164+
"try",
165165
suggestions.join(" | "),
166166
Applicability::MaybeIncorrect,
167167
);

clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn find_sugg_for_if_let<'tcx>(
175175
.maybe_par()
176176
.to_string();
177177

178-
diag.span_suggestion(span, "try this", format!("{keyword} {sugg}.{good_method}"), app);
178+
diag.span_suggestion(span, "try", format!("{keyword} {sugg}.{good_method}"), app);
179179

180180
if needs_drop {
181181
diag.note("this will change drop order of the result, as well as all temporaries");
@@ -200,7 +200,7 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
200200
REDUNDANT_PATTERN_MATCHING,
201201
span,
202202
&format!("redundant pattern matching, consider using `{good_method}`"),
203-
"try this",
203+
"try",
204204
format!("{}.{good_method}", snippet(cx, result_expr.span, "_")),
205205
Applicability::MachineApplicable,
206206
);

clippy_lints/src/matches/single_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn report_single_pattern(
136136
}
137137
};
138138

139-
span_lint_and_sugg(cx, lint, expr.span, msg, "try this", sugg, app);
139+
span_lint_and_sugg(cx, lint, expr.span, msg, "try", sugg, app);
140140
}
141141

142142
fn check_opt_like<'a>(

clippy_lints/src/matches/try_err.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
7070
TRY_ERR,
7171
expr.span,
7272
"returning an `Err(_)` with the `?` operator",
73-
"try this",
73+
"try",
7474
suggestion,
7575
applicability,
7676
);

clippy_lints/src/methods/bind_instead_of_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(crate) trait BindInsteadOfMap {
8787
BIND_INSTEAD_OF_MAP,
8888
expr.span,
8989
&msg,
90-
"try this",
90+
"try",
9191
note,
9292
app,
9393
);
@@ -124,7 +124,7 @@ pub(crate) trait BindInsteadOfMap {
124124
span_lint_and_then(cx, BIND_INSTEAD_OF_MAP, expr.span, &msg, |diag| {
125125
multispan_sugg_with_applicability(
126126
diag,
127-
"try this",
127+
"try",
128128
Applicability::MachineApplicable,
129129
std::iter::once((span, Self::GOOD_METHOD_NAME.into())).chain(
130130
suggs

clippy_lints/src/methods/clone_on_ref_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(super) fn check(
4242
CLONE_ON_REF_PTR,
4343
expr.span,
4444
"using `.clone()` on a ref-counted pointer",
45-
"try this",
45+
"try",
4646
format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
4747
app,
4848
);

clippy_lints/src/methods/expect_fun_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(super) fn check<'tcx>(
144144
EXPECT_FUN_CALL,
145145
span_replace_word,
146146
&format!("use of `{name}` followed by a function call"),
147-
"try this",
147+
"try",
148148
format!("unwrap_or_else({closure_args} panic!({sugg}))"),
149149
applicability,
150150
);
@@ -162,7 +162,7 @@ pub(super) fn check<'tcx>(
162162
EXPECT_FUN_CALL,
163163
span_replace_word,
164164
&format!("use of `{name}` followed by a function call"),
165-
"try this",
165+
"try",
166166
format!("unwrap_or_else({closure_args} {{ panic!(\"{{}}\", {arg_root_snippet}) }})"),
167167
applicability,
168168
);

clippy_lints/src/methods/extend_with_drain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg:
3131
EXTEND_WITH_DRAIN,
3232
expr.span,
3333
"use of `extend` instead of `append` for adding the full range of a second vector",
34-
"try this",
34+
"try",
3535
format!(
3636
"{}.append({}{})",
3737
snippet_with_applicability(cx, recv.span, "..", &mut applicability),

clippy_lints/src/methods/filter_map_next.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(
3131
FILTER_MAP_NEXT,
3232
expr.span,
3333
msg,
34-
"try this",
34+
"try",
3535
format!("{iter_snippet}.find_map({filter_snippet})"),
3636
Applicability::MachineApplicable,
3737
);

clippy_lints/src/methods/filter_next.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(
3131
FILTER_NEXT,
3232
expr.span,
3333
msg,
34-
"try this",
34+
"try",
3535
format!("{iter_snippet}.find({filter_snippet})"),
3636
Applicability::MachineApplicable,
3737
);

clippy_lints/src/methods/get_unwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(super) fn check<'tcx>(
7171
GET_UNWRAP,
7272
span,
7373
&format!("called `.get{mut_str}().unwrap()` on a {caller_type}. Using `[]` is more clear and more concise"),
74-
"try this",
74+
"try",
7575
format!(
7676
"{borrow_str}{}[{get_args_str}]",
7777
snippet_with_applicability(cx, recv.span, "..", &mut applicability)

clippy_lints/src/methods/iter_overeager_cloned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub(super) fn check<'tcx>(
5151
if let Some(mut snip) = snippet_opt(cx, method_span) {
5252
snip.push_str(trailing_clone);
5353
let replace_span = expr.span.with_lo(cloned_recv.span.hi());
54-
diag.span_suggestion(replace_span, "try this", snip, Applicability::MachineApplicable);
54+
diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable);
5555
}
5656
}
5757
);

clippy_lints/src/methods/iter_with_drain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span
2121
ITER_WITH_DRAIN,
2222
span.with_hi(expr.span.hi()),
2323
&format!("`drain(..)` used on a `{ty_name}`"),
24-
"try this",
24+
"try",
2525
"into_iter()".to_string(),
2626
Applicability::MaybeIncorrect,
2727
);

clippy_lints/src/methods/manual_str_repeat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(super) fn check(
8888
MANUAL_STR_REPEAT,
8989
collect_expr.span,
9090
"manual implementation of `str::repeat` using iterators",
91-
"try this",
91+
"try",
9292
format!("{val_str}.repeat({count_snip})"),
9393
app
9494
)

clippy_lints/src/methods/map_collect_result_unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr
2525
MAP_COLLECT_RESULT_UNIT,
2626
expr.span,
2727
"`.map().collect()` can be replaced with `.try_for_each()`",
28-
"try this",
28+
"try",
2929
format!(
3030
"{}.try_for_each({})",
3131
snippet(cx, iter.span, ".."),

clippy_lints/src/methods/map_unwrap_or.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(super) fn check<'tcx>(
6464
MAP_UNWRAP_OR,
6565
expr.span,
6666
msg,
67-
"try this",
67+
"try",
6868
format!("{var_snippet}.map_or_else({unwrap_snippet}, {map_snippet})"),
6969
Applicability::MachineApplicable,
7070
);

clippy_lints/src/methods/needless_option_as_deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, name
2929
NEEDLESS_OPTION_AS_DEREF,
3030
expr.span,
3131
"derefed type is same as origin",
32-
"try this",
32+
"try",
3333
snippet_opt(cx, recv.span).unwrap(),
3434
Applicability::MachineApplicable,
3535
);

clippy_lints/src/methods/or_fun_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
6262
OR_FUN_CALL,
6363
method_span.with_hi(span.hi()),
6464
&format!("use of `{name}` followed by a call to `{path}`"),
65-
"try this",
65+
"try",
6666
format!("{sugg}()"),
6767
Applicability::MachineApplicable,
6868
);
@@ -139,7 +139,7 @@ pub(super) fn check<'tcx>(
139139
OR_FUN_CALL,
140140
span_replace_word,
141141
&format!("use of `{name}` followed by a function call"),
142-
"try this",
142+
"try",
143143
format!("{name}_{suffix}({sugg})"),
144144
app,
145145
);

clippy_lints/src/methods/or_then_unwrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(super) fn check<'tcx>(
5050
OR_THEN_UNWRAP,
5151
unwrap_expr.span.with_lo(or_span.lo()),
5252
title,
53-
"try this",
53+
"try",
5454
suggestion,
5555
applicability,
5656
);

clippy_lints/src/methods/str_splitn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn lint_needless(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, self_
5555
NEEDLESS_SPLITN,
5656
expr.span,
5757
&format!("unnecessary use of `{r}splitn`"),
58-
"try this",
58+
"try",
5959
format!(
6060
"{}.{r}split({})",
6161
snippet_with_context(cx, self_arg.span, expr.span.ctxt(), "..", &mut app).0,
@@ -110,7 +110,7 @@ fn check_manual_split_once(
110110
IterUsageKind::Nth(_) => return,
111111
};
112112

113-
span_lint_and_sugg(cx, MANUAL_SPLIT_ONCE, usage.span, msg, "try this", sugg, app);
113+
span_lint_and_sugg(cx, MANUAL_SPLIT_ONCE, usage.span, msg, "try", sugg, app);
114114
}
115115

116116
/// checks for

clippy_lints/src/methods/string_extend_chars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
3434
STRING_EXTEND_CHARS,
3535
expr.span,
3636
"calling `.extend(_.chars())`",
37-
"try this",
37+
"try",
3838
format!(
3939
"{}.push_str({ref_str}{})",
4040
snippet_with_applicability(cx, recv.span, "..", &mut applicability),

0 commit comments

Comments
 (0)