Skip to content

Commit ee84ac3

Browse files
committed
issue rust-lang#8239: Printed hint for lint or_fun_call is cropped and does not show the solution
1 parent 5cada57 commit ee84ac3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

clippy_lints/src/methods/or_fun_call.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_mac
44
use clippy_utils::ty::{implements_trait, match_type};
55
use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths};
66
use if_chain::if_chain;
7+
use rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES;
78
use rustc_errors::Applicability;
89
use rustc_hir as hir;
910
use rustc_lint::LateContext;
@@ -52,16 +53,24 @@ pub(super) fn check<'tcx>(
5253

5354
then {
5455
let mut applicability = Applicability::MachineApplicable;
56+
let hint = ".unwrap_or_default()";
57+
let mut sugg: String = format!(
58+
"{}{}",
59+
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability),
60+
hint
61+
);
62+
63+
if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES {
64+
sugg = hint.to_string();
65+
}
66+
5567
span_lint_and_sugg(
5668
cx,
5769
OR_FUN_CALL,
5870
span,
5971
&format!("use of `{}` followed by a call to `{}`", name, path),
6072
"try this",
61-
format!(
62-
"{}.unwrap_or_default()",
63-
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability)
64-
),
73+
sugg,
6574
applicability,
6675
);
6776

0 commit comments

Comments
 (0)