Skip to content

Commit

Permalink
Auto merge of #11055 - smoelius:try-this, r=dswij
Browse files Browse the repository at this point in the history
"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").
  • Loading branch information
bors committed Jul 9, 2023
2 parents b46033e + 420f3d1 commit ebd8d31
Show file tree
Hide file tree
Showing 105 changed files with 682 additions and 680 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
pat.spans,
"this pattern creates a reference to a reference",
|diag| {
diag.multipart_suggestion("try this", replacements, app);
diag.multipart_suggestion("try", replacements, app);
},
);
}
Expand Down Expand Up @@ -1531,7 +1531,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
Mutability::Not => "explicit `deref` method call",
Mutability::Mut => "explicit `deref_mut` method call",
},
"try this",
"try",
format!("{addr_of_str}{deref_str}{expr_str}"),
app,
);
Expand Down Expand Up @@ -1593,7 +1593,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
} else {
format!("{prefix}{snip}")
};
diag.span_suggestion(data.span, "try this", sugg, app);
diag.span_suggestion(data.span, "try", sugg, app);
},
);
},
Expand All @@ -1620,7 +1620,7 @@ fn report<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, state: State, data
|diag| {
let mut app = Applicability::MachineApplicable;
let snip = snippet_with_context(cx, expr.span, data.span.ctxt(), "..", &mut app).0;
diag.span_suggestion(data.span, "try this", snip.into_owned(), app);
diag.span_suggestion(data.span, "try", snip.into_owned(), app);
},
);
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
MAP_ENTRY,
expr.span,
&format!("usage of `contains_key` followed by `insert` on a `{}`", map_ty.name()),
"try this",
"try",
sugg,
app,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
EXPLICIT_WRITE,
expr.span,
&format!("use of `{used}.unwrap()`"),
"try this",
"try",
format!("{prefix}{sugg_mac}!({inputs_snippet})"),
applicability,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/init_numbered_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
INIT_NUMBERED_FIELDS,
e.span,
"used a field initializer for a tuple struct",
"try this instead",
"try",
snippet,
appl,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/missing_spin_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, body: &'
MISSING_SPIN_LOOP,
body.span,
"busy-waiting loop should at least have a spin loop hint",
"try this",
"try",
(if is_no_std_crate(cx) {
"{ core::hint::spin_loop() }"
} else {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn lint_map_unit_fn(
);

span_lint_and_then(cx, lint, expr.span, &msg, |diag| {
diag.span_suggestion(stmt.span, "try this", suggestion, applicability);
diag.span_suggestion(stmt.span, "try", suggestion, applicability);
});
} else if let Some((binding, closure_expr)) = unit_closure(cx, fn_arg) {
let msg = suggestion_msg("closure", map_type);
Expand All @@ -241,15 +241,15 @@ fn lint_map_unit_fn(
snippet_with_applicability(cx, var_arg.span, "_", &mut applicability),
snippet_with_context(cx, reduced_expr_span, var_arg.span.ctxt(), "_", &mut applicability).0,
);
diag.span_suggestion(stmt.span, "try this", suggestion, applicability);
diag.span_suggestion(stmt.span, "try", suggestion, applicability);
} else {
let suggestion = format!(
"if let {0}({1}) = {2} {{ ... }}",
variant,
snippet(cx, binding.pat.span, "_"),
snippet(cx, var_arg.span, "_"),
);
diag.span_suggestion(stmt.span, "try this", suggestion, Applicability::HasPlaceholders);
diag.span_suggestion(stmt.span, "try", suggestion, Applicability::HasPlaceholders);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/infallible_destructuring_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) fn check(cx: &LateContext<'_>, local: &Local<'_>) -> bool {
local.span,
"you seem to be trying to use `match` to destructure a single infallible pattern. \
Consider using `let`",
"try this",
"try",
format!(
"let {}({}{}) = {};",
snippet_with_applicability(cx, variant_name.span, "..", &mut applicability),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/manual_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn check<'tcx>(
MANUAL_FILTER,
expr.span,
"manual implementation of `Option::filter`",
"try this",
"try",
if sugg_info.needs_brackets {
format!(
"{{ {}{}.filter({body_str}) }}",
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/manual_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn check<'tcx>(
MANUAL_MAP,
expr.span,
"manual implementation of `Option::map`",
"try this",
"try",
if sugg_info.needs_brackets {
format!(
"{{ {}{}.map({}) }}",
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/match_as_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
MATCH_AS_REF,
expr.span,
&format!("use `{suggestion}()` instead"),
"try this",
"try",
format!(
"{}.{suggestion}(){cast}",
snippet_with_applicability(cx, ex.span, "_", &mut applicability),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/match_like_matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
MATCH_LIKE_MATCHES_MACRO,
expr.span,
&format!("{} expression looks like `matches!` macro", if is_if_let { "if let .. else" } else { "match" }),
"try this",
"try",
format!(
"{}matches!({}, {pat_and_guard})",
if b0 { "" } else { "!" },
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/match_on_vec_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, scrutinee: &'tcx Expr<'_>) {
MATCH_ON_VEC_ITEMS,
scrutinee.span,
"indexing into a vector may panic",
"try this",
"try",
format!(
"{}.get({})",
snippet(cx, vec.span, ".."),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/matches/match_wild_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
MATCH_WILDCARD_FOR_SINGLE_VARIANTS,
wildcard_span,
"wildcard matches only a single variant and will also match any future added variants",
"try this",
"try",
format_suggestion(x),
Applicability::MaybeIncorrect,
),
Expand All @@ -161,7 +161,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
WILDCARD_ENUM_MATCH_ARM,
wildcard_span,
message,
"try this",
"try",
suggestions.join(" | "),
Applicability::MaybeIncorrect,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/matches/redundant_pattern_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn find_sugg_for_if_let<'tcx>(
.maybe_par()
.to_string();

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

if needs_drop {
diag.note("this will change drop order of the result, as well as all temporaries");
Expand All @@ -200,7 +200,7 @@ pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op
REDUNDANT_PATTERN_MATCHING,
span,
&format!("redundant pattern matching, consider using `{good_method}`"),
"try this",
"try",
format!("{}.{good_method}", snippet(cx, result_expr.span, "_")),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/single_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn report_single_pattern(
}
};

span_lint_and_sugg(cx, lint, expr.span, msg, "try this", sugg, app);
span_lint_and_sugg(cx, lint, expr.span, msg, "try", sugg, app);
}

fn check_opt_like<'a>(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/try_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
TRY_ERR,
expr.span,
"returning an `Err(_)` with the `?` operator",
"try this",
"try",
suggestion,
applicability,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/bind_instead_of_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) trait BindInsteadOfMap {
BIND_INSTEAD_OF_MAP,
expr.span,
&msg,
"try this",
"try",
note,
app,
);
Expand Down Expand Up @@ -124,7 +124,7 @@ pub(crate) trait BindInsteadOfMap {
span_lint_and_then(cx, BIND_INSTEAD_OF_MAP, expr.span, &msg, |diag| {
multispan_sugg_with_applicability(
diag,
"try this",
"try",
Applicability::MachineApplicable,
std::iter::once((span, Self::GOOD_METHOD_NAME.into())).chain(
suggs
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/clone_on_ref_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(super) fn check(
CLONE_ON_REF_PTR,
expr.span,
"using `.clone()` on a ref-counted pointer",
"try this",
"try",
format!("{caller_type}::<{}>::clone(&{snippet})", subst.type_at(0)),
app,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/expect_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(super) fn check<'tcx>(
EXPECT_FUN_CALL,
span_replace_word,
&format!("use of `{name}` followed by a function call"),
"try this",
"try",
format!("unwrap_or_else({closure_args} panic!({sugg}))"),
applicability,
);
Expand All @@ -162,7 +162,7 @@ pub(super) fn check<'tcx>(
EXPECT_FUN_CALL,
span_replace_word,
&format!("use of `{name}` followed by a function call"),
"try this",
"try",
format!("unwrap_or_else({closure_args} {{ panic!(\"{{}}\", {arg_root_snippet}) }})"),
applicability,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/extend_with_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg:
EXTEND_WITH_DRAIN,
expr.span,
"use of `extend` instead of `append` for adding the full range of a second vector",
"try this",
"try",
format!(
"{}.append({}{})",
snippet_with_applicability(cx, recv.span, "..", &mut applicability),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/filter_map_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(
FILTER_MAP_NEXT,
expr.span,
msg,
"try this",
"try",
format!("{iter_snippet}.find_map({filter_snippet})"),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/filter_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(
FILTER_NEXT,
expr.span,
msg,
"try this",
"try",
format!("{iter_snippet}.find({filter_snippet})"),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/get_unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(super) fn check<'tcx>(
GET_UNWRAP,
span,
&format!("called `.get{mut_str}().unwrap()` on a {caller_type}. Using `[]` is more clear and more concise"),
"try this",
"try",
format!(
"{borrow_str}{}[{get_args_str}]",
snippet_with_applicability(cx, recv.span, "..", &mut applicability)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/iter_overeager_cloned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(super) fn check<'tcx>(
if let Some(mut snip) = snippet_opt(cx, method_span) {
snip.push_str(trailing_clone);
let replace_span = expr.span.with_lo(cloned_recv.span.hi());
diag.span_suggestion(replace_span, "try this", snip, Applicability::MachineApplicable);
diag.span_suggestion(replace_span, "try", snip, Applicability::MachineApplicable);
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/iter_with_drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span
ITER_WITH_DRAIN,
span.with_hi(expr.span.hi()),
&format!("`drain(..)` used on a `{ty_name}`"),
"try this",
"try",
"into_iter()".to_string(),
Applicability::MaybeIncorrect,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_str_repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(super) fn check(
MANUAL_STR_REPEAT,
collect_expr.span,
"manual implementation of `str::repeat` using iterators",
"try this",
"try",
format!("{val_str}.repeat({count_snip})"),
app
)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/map_collect_result_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, iter: &hir::Expr
MAP_COLLECT_RESULT_UNIT,
expr.span,
"`.map().collect()` can be replaced with `.try_for_each()`",
"try this",
"try",
format!(
"{}.try_for_each({})",
snippet(cx, iter.span, ".."),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/map_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(super) fn check<'tcx>(
MAP_UNWRAP_OR,
expr.span,
msg,
"try this",
"try",
format!("{var_snippet}.map_or_else({unwrap_snippet}, {map_snippet})"),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/needless_option_as_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, name
NEEDLESS_OPTION_AS_DEREF,
expr.span,
"derefed type is same as origin",
"try this",
"try",
snippet_opt(cx, recv.span).unwrap(),
Applicability::MachineApplicable,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
OR_FUN_CALL,
method_span.with_hi(span.hi()),
&format!("use of `{name}` followed by a call to `{path}`"),
"try this",
"try",
format!("{sugg}()"),
Applicability::MachineApplicable,
);
Expand Down Expand Up @@ -139,7 +139,7 @@ pub(super) fn check<'tcx>(
OR_FUN_CALL,
span_replace_word,
&format!("use of `{name}` followed by a function call"),
"try this",
"try",
format!("{name}_{suffix}({sugg})"),
app,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/or_then_unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(super) fn check<'tcx>(
OR_THEN_UNWRAP,
unwrap_expr.span.with_lo(or_span.lo()),
title,
"try this",
"try",
suggestion,
applicability,
);
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/str_splitn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn lint_needless(cx: &LateContext<'_>, method_name: &str, expr: &Expr<'_>, self_
NEEDLESS_SPLITN,
expr.span,
&format!("unnecessary use of `{r}splitn`"),
"try this",
"try",
format!(
"{}.{r}split({})",
snippet_with_context(cx, self_arg.span, expr.span.ctxt(), "..", &mut app).0,
Expand Down Expand Up @@ -110,7 +110,7 @@ fn check_manual_split_once(
IterUsageKind::Nth(_) => return,
};

span_lint_and_sugg(cx, MANUAL_SPLIT_ONCE, usage.span, msg, "try this", sugg, app);
span_lint_and_sugg(cx, MANUAL_SPLIT_ONCE, usage.span, msg, "try", sugg, app);
}

/// checks for
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/string_extend_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
STRING_EXTEND_CHARS,
expr.span,
"calling `.extend(_.chars())`",
"try this",
"try",
format!(
"{}.push_str({ref_str}{})",
snippet_with_applicability(cx, recv.span, "..", &mut applicability),
Expand Down
Loading

0 comments on commit ebd8d31

Please sign in to comment.