Skip to content

Commit

Permalink
issue rust-lang#8239: Printed hint for lint or_fun_call is cropped an…
Browse files Browse the repository at this point in the history
…d does not show the solution
  • Loading branch information
marekdownar committed Jan 15, 2022
1 parent 5cada57 commit ee84ac3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions clippy_lints/src/methods/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);

Expand Down

0 comments on commit ee84ac3

Please sign in to comment.