diff options
| author | Marek Downar <marek.downar@evomedia.pl> | 2022-01-15 15:51:46 +0100 |
|---|---|---|
| committer | Marek Downar <marek.downar@evomedia.pl> | 2022-01-15 15:51:46 +0100 |
| commit | ee84ac3396d9ea09c2160ff892cd297ef1b2ea70 (patch) | |
| tree | c0c58db203fdb57231e3b143a37930ac1c1d97f1 | |
| parent | 5cada57f306ee47ee4e9a78008798d734ff7b9d7 (diff) | |
| download | rust-ee84ac3396d9ea09c2160ff892cd297ef1b2ea70.tar.gz rust-ee84ac3396d9ea09c2160ff892cd297ef1b2ea70.zip | |
issue #8239: Printed hint for lint or_fun_call is cropped and does not show the solution
| -rw-r--r-- | clippy_lints/src/methods/or_fun_call.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs index 4e4653dadca..6fb67ff89c3 100644 --- a/clippy_lints/src/methods/or_fun_call.rs +++ b/clippy_lints/src/methods/or_fun_call.rs @@ -4,6 +4,7 @@ use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_mac use clippy_utils::ty::{implements_trait, match_type}; use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths}; use if_chain::if_chain; +use rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_lint::LateContext; @@ -52,16 +53,24 @@ pub(super) fn check<'tcx>( then { let mut applicability = Applicability::MachineApplicable; + let hint = ".unwrap_or_default()"; + let mut sugg: String = format!( + "{}{}", + snippet_with_applicability(cx, self_expr.span, "..", &mut applicability), + hint + ); + + if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES { + sugg = hint.to_string(); + } + span_lint_and_sugg( cx, OR_FUN_CALL, span, &format!("use of `{}` followed by a call to `{}`", name, path), "try this", - format!( - "{}.unwrap_or_default()", - snippet_with_applicability(cx, self_expr.span, "..", &mut applicability) - ), + sugg, applicability, ); |
