Skip to content

Commit

Permalink
Auto merge of rust-lang#12170 - GuillaumeGomez:improve-suggestions-wo…
Browse files Browse the repository at this point in the history
…rding, r=llogiq

Improve wording for suggestion messages

Follow-up of rust-lang#12140.

r? `@llogiq`

changelog: Improve wording for suggestion messages
  • Loading branch information
bors committed Jan 21, 2024
2 parents 64d08a8 + 38d9585 commit 99423e8
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 117 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/same_item_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(
vec.span,
"it looks like the same item is being pushed into this Vec",
None,
&format!("try using vec![{item_str};SIZE] or {vec_str}.resize(NEW_SIZE, {item_str})"),
&format!("consider using vec![{item_str};SIZE] or {vec_str}.resize(NEW_SIZE, {item_str})"),
);
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/join_absolute_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx Expr<'tcx>, join_a
)
.span_suggestion(
expr_span,
"if this is intentional, try using `Path::new` instead",
"if this is intentional, consider using `Path::new`",
format!("PathBuf::from({arg_str})"),
Applicability::Unspecified,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_saturating_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn check(
super::MANUAL_SATURATING_ARITHMETIC,
expr.span,
"manual saturating arithmetic",
&format!("try using `saturating_{arith}`"),
&format!("consider using `saturating_{arith}`"),
format!(
"{}.saturating_{arith}({})",
snippet_with_applicability(cx, arith_lhs.span, "..", &mut applicability),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/option_as_ref_deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub(super) fn check(
};
let method_hint = if is_mut { "as_deref_mut" } else { "as_deref" };
let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, ".."));
let suggestion = format!("try using {method_hint} instead");
let suggestion = format!("consider using {method_hint}");

let msg = format!("called `{current_method}` on an `Option` value");
span_lint_and_sugg(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/option_map_or_err_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn check<'tcx>(
OPTION_MAP_OR_ERR_OK,
expr.span,
msg,
"try using `ok_or` instead",
"consider using `ok_or`",
format!("{self_snippet}.ok_or({err_snippet})"),
Applicability::MachineApplicable,
);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/option_map_or_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(super) fn check<'tcx>(
OPTION_MAP_OR_NONE,
expr.span,
msg,
"try using `map` instead",
"consider using `map`",
format!("{self_snippet}.map({arg_snippet} {func_snippet})"),
Applicability::MachineApplicable,
);
Expand All @@ -85,7 +85,7 @@ pub(super) fn check<'tcx>(
OPTION_MAP_OR_NONE,
expr.span,
msg,
"try using `and_then` instead",
"consider using `and_then`",
format!("{self_snippet}.and_then({func_snippet})"),
Applicability::MachineApplicable,
);
Expand All @@ -97,7 +97,7 @@ pub(super) fn check<'tcx>(
RESULT_MAP_OR_INTO_OPTION,
expr.span,
msg,
"try using `ok` instead",
"consider using `ok`",
format!("{self_snippet}.ok()"),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/result_map_or_else_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
RESULT_MAP_OR_INTO_OPTION,
expr.span,
msg,
"try using `ok` instead",
"consider using `ok`",
format!("{self_snippet}.ok()"),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/single_char_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(super) fn check(
SINGLE_CHAR_PATTERN,
arg.span,
"single-character string constant used as pattern",
"try using a `char` instead",
"consider using a `char`",
hint,
applicability,
);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn check<'tcx>(
UNNECESSARY_JOIN,
span.with_hi(expr.span.hi()),
r#"called `.collect::<Vec<String>>().join("")` on an iterator"#,
"try using",
"consider using",
"collect::<String>()".to_owned(),
applicability,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for AlmostStandardFormulation {
ident.span,
"non-standard lint formulation",
None,
&format!("try using `{}` instead", formulation.correction),
&format!("consider using `{}`", formulation.correction),
);
}
return;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui-internal/check_formulation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: non-standard lint formulation
LL | /// Check for lint formulations that are correct
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try using `Checks for` instead
= help: consider using `Checks for`
= note: `-D clippy::almost-standard-lint-formulation` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::almost_standard_lint_formulation)]`

Expand All @@ -14,7 +14,7 @@ error: non-standard lint formulation
LL | /// Detects uses of incorrect formulations
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try using `Checks for` instead
= help: consider using `Checks for`

error: aborting due to 2 previous errors

8 changes: 4 additions & 4 deletions tests/ui/join_absolute_paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ help: if this is unintentional, try removing the starting separator
|
LL | path.join("sh");
| ~~~~
help: if this is intentional, try using `Path::new` instead
help: if this is intentional, consider using `Path::new`
|
LL | PathBuf::from("/sh");
| ~~~~~~~~~~~~~~~~~~~~
Expand All @@ -27,7 +27,7 @@ help: if this is unintentional, try removing the starting separator
|
LL | path.join("\user");
| ~~~~~~~
help: if this is intentional, try using `Path::new` instead
help: if this is intentional, consider using `Path::new`
|
LL | PathBuf::from("\\user");
| ~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -43,7 +43,7 @@ help: if this is unintentional, try removing the starting separator
|
LL | path.join("sh");
| ~~~~
help: if this is intentional, try using `Path::new` instead
help: if this is intentional, consider using `Path::new`
|
LL | PathBuf::from("/sh");
| ~~~~~~~~~~~~~~~~~~~~
Expand All @@ -59,7 +59,7 @@ help: if this is unintentional, try removing the starting separator
|
LL | path.join(r#"sh"#);
| ~~~~~~~
help: if this is intentional, try using `Path::new` instead
help: if this is intentional, consider using `Path::new`
|
LL | PathBuf::from(r#"/sh"#);
| ~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/manual_ok_or.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ error: called `map_or(Err(_), Ok)` on an `Option` value
--> $DIR/manual_ok_or.rs:14:5
|
LL | foo.map_or(Err("error"), Ok);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok_or` instead: `foo.ok_or("error")`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `ok_or`: `foo.ok_or("error")`
|
= note: `-D clippy::option-map-or-err-ok` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]`
Expand Down
48 changes: 24 additions & 24 deletions tests/ui/manual_saturating_arithmetic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:6:13
|
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::max_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`
|
= note: `-D clippy::manual-saturating-arithmetic` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_saturating_arithmetic)]`
Expand All @@ -11,13 +11,13 @@ error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:7:13
|
LL | let _ = 1u32.checked_add(1).unwrap_or(u32::MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u32.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u32.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:8:13
|
LL | let _ = 1u8.checked_add(1).unwrap_or(255);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1u8.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1u8.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:9:13
Expand All @@ -26,49 +26,49 @@ LL | let _ = 1u128
| _____________^
LL | | .checked_add(1)
LL | | .unwrap_or(340_282_366_920_938_463_463_374_607_431_768_211_455);
| |_______________________________________________________________________^ help: try using `saturating_add`: `1u128.saturating_add(1)`
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1u128.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:14:13
|
LL | let _ = 1u32.checked_mul(1).unwrap_or(u32::MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_mul`: `1u32.saturating_mul(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_mul`: `1u32.saturating_mul(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:16:13
|
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::min_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:17:13
|
LL | let _ = 1u32.checked_sub(1).unwrap_or(u32::MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u32.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u32.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:18:13
|
LL | let _ = 1u8.checked_sub(1).unwrap_or(0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1u8.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1u8.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:22:13
|
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::max_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:23:13
|
LL | let _ = 1i32.checked_add(1).unwrap_or(i32::MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:24:13
|
LL | let _ = 1i8.checked_add(1).unwrap_or(127);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:25:13
Expand All @@ -77,25 +77,25 @@ LL | let _ = 1i128
| _____________^
LL | | .checked_add(1)
LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
| |_______________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(1)`
| |_______________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:28:13
|
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::min_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:29:13
|
LL | let _ = 1i32.checked_add(-1).unwrap_or(i32::MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i32.saturating_add(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i32.saturating_add(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:30:13
|
LL | let _ = 1i8.checked_add(-1).unwrap_or(-128);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_add`: `1i8.saturating_add(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_add`: `1i8.saturating_add(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:31:13
Expand All @@ -104,25 +104,25 @@ LL | let _ = 1i128
| _____________^
LL | | .checked_add(-1)
LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
| |________________________________________________________________________^ help: try using `saturating_add`: `1i128.saturating_add(-1)`
| |________________________________________________________________________^ help: consider using `saturating_add`: `1i128.saturating_add(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:38:13
|
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::min_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:39:13
|
LL | let _ = 1i32.checked_sub(1).unwrap_or(i32::MIN);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:40:13
|
LL | let _ = 1i8.checked_sub(1).unwrap_or(-128);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:41:13
Expand All @@ -131,25 +131,25 @@ LL | let _ = 1i128
| _____________^
LL | | .checked_sub(1)
LL | | .unwrap_or(-170_141_183_460_469_231_731_687_303_715_884_105_728);
| |________________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(1)`
| |________________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:44:13
|
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::max_value());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:45:13
|
LL | let _ = 1i32.checked_sub(-1).unwrap_or(i32::MAX);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i32.saturating_sub(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i32.saturating_sub(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:46:13
|
LL | let _ = 1i8.checked_sub(-1).unwrap_or(127);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `saturating_sub`: `1i8.saturating_sub(-1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `saturating_sub`: `1i8.saturating_sub(-1)`

error: manual saturating arithmetic
--> $DIR/manual_saturating_arithmetic.rs:47:13
Expand All @@ -158,7 +158,7 @@ LL | let _ = 1i128
| _____________^
LL | | .checked_sub(-1)
LL | | .unwrap_or(170_141_183_460_469_231_731_687_303_715_884_105_727);
| |_______________________________________________________________________^ help: try using `saturating_sub`: `1i128.saturating_sub(-1)`
| |_______________________________________________________________________^ help: consider using `saturating_sub`: `1i128.saturating_sub(-1)`

error: aborting due to 24 previous errors

Loading

0 comments on commit 99423e8

Please sign in to comment.