remove last use of MAX_SUGGESTION_HIGHLIGHT_LINES
This commit is contained in:
parent
9395c261d6
commit
ee37029afa
@ -4,7 +4,6 @@
|
|||||||
use clippy_utils::ty::{implements_trait, match_type};
|
use clippy_utils::ty::{implements_trait, match_type};
|
||||||
use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths};
|
use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES;
|
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
@ -33,7 +32,6 @@ fn check_unwrap_or_default(
|
|||||||
arg: &hir::Expr<'_>,
|
arg: &hir::Expr<'_>,
|
||||||
or_has_args: bool,
|
or_has_args: bool,
|
||||||
span: Span,
|
span: Span,
|
||||||
method_span: Span,
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let is_default_default = || is_trait_item(cx, fun, sym::Default);
|
let is_default_default = || is_trait_item(cx, fun, sym::Default);
|
||||||
|
|
||||||
@ -56,19 +54,14 @@ fn check_unwrap_or_default(
|
|||||||
then {
|
then {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
let hint = "unwrap_or_default()";
|
let hint = "unwrap_or_default()";
|
||||||
let mut sugg_span = span;
|
let sugg_span = span;
|
||||||
|
|
||||||
let mut sugg: String = format!(
|
let sugg: String = format!(
|
||||||
"{}.{}",
|
"{}.{}",
|
||||||
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability),
|
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability),
|
||||||
hint
|
hint
|
||||||
);
|
);
|
||||||
|
|
||||||
if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES {
|
|
||||||
sugg_span = method_span.with_hi(span.hi());
|
|
||||||
sugg = hint.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
OR_FUN_CALL,
|
OR_FUN_CALL,
|
||||||
@ -178,7 +171,7 @@ fn check_general_case<'tcx>(
|
|||||||
match inner_arg.kind {
|
match inner_arg.kind {
|
||||||
hir::ExprKind::Call(fun, or_args) => {
|
hir::ExprKind::Call(fun, or_args) => {
|
||||||
let or_has_args = !or_args.is_empty();
|
let or_has_args = !or_args.is_empty();
|
||||||
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span, method_span) {
|
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span) {
|
||||||
let fun_span = if or_has_args { None } else { Some(fun.span) };
|
let fun_span = if or_has_args { None } else { Some(fun.span) };
|
||||||
check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span);
|
check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span);
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,7 @@ mod issue8239 {
|
|||||||
.reduce(|mut acc, f| {
|
.reduce(|mut acc, f| {
|
||||||
acc.push_str(&f);
|
acc.push_str(&f);
|
||||||
acc
|
acc
|
||||||
})
|
}).unwrap_or_default();
|
||||||
.unwrap_or_default();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn more_to_max_suggestion_highest_lines_1() {
|
fn more_to_max_suggestion_highest_lines_1() {
|
||||||
@ -198,8 +197,7 @@ mod issue8239 {
|
|||||||
let _ = "";
|
let _ = "";
|
||||||
acc.push_str(&f);
|
acc.push_str(&f);
|
||||||
acc
|
acc
|
||||||
})
|
}).unwrap_or_default();
|
||||||
.unwrap_or_default();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn equal_to_max_suggestion_highest_lines() {
|
fn equal_to_max_suggestion_highest_lines() {
|
||||||
|
@ -109,16 +109,50 @@ LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
|
||||||
|
|
||||||
error: use of `unwrap_or` followed by a call to `new`
|
error: use of `unwrap_or` followed by a call to `new`
|
||||||
--> $DIR/or_fun_call.rs:189:14
|
--> $DIR/or_fun_call.rs:182:9
|
||||||
|
|
|
||||||
|
LL | / frames
|
||||||
|
LL | | .iter()
|
||||||
|
LL | | .map(|f: &String| f.to_lowercase())
|
||||||
|
LL | | .reduce(|mut acc, f| {
|
||||||
|
... |
|
||||||
|
LL | | })
|
||||||
|
LL | | .unwrap_or(String::new());
|
||||||
|
| |_____________________________________^
|
||||||
|
|
|
||||||
|
help: try this
|
||||||
|
|
|
||||||
|
LL ~ frames
|
||||||
|
LL + .iter()
|
||||||
|
LL + .map(|f: &String| f.to_lowercase())
|
||||||
|
LL + .reduce(|mut acc, f| {
|
||||||
|
LL + acc.push_str(&f);
|
||||||
|
LL + acc
|
||||||
|
LL ~ }).unwrap_or_default();
|
||||||
|
|
|
|
||||||
LL | .unwrap_or(String::new());
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
|
|
||||||
|
|
||||||
error: use of `unwrap_or` followed by a call to `new`
|
error: use of `unwrap_or` followed by a call to `new`
|
||||||
--> $DIR/or_fun_call.rs:202:14
|
--> $DIR/or_fun_call.rs:195:9
|
||||||
|
|
|
||||||
|
LL | / iter.map(|f: &String| f.to_lowercase())
|
||||||
|
LL | | .reduce(|mut acc, f| {
|
||||||
|
LL | | let _ = "";
|
||||||
|
LL | | let _ = "";
|
||||||
|
... |
|
||||||
|
LL | | })
|
||||||
|
LL | | .unwrap_or(String::new());
|
||||||
|
| |_____________________________________^
|
||||||
|
|
|
||||||
|
help: try this
|
||||||
|
|
|
||||||
|
LL ~ iter.map(|f: &String| f.to_lowercase())
|
||||||
|
LL + .reduce(|mut acc, f| {
|
||||||
|
LL + let _ = "";
|
||||||
|
LL + let _ = "";
|
||||||
|
LL + acc.push_str(&f);
|
||||||
|
LL + acc
|
||||||
|
LL ~ }).unwrap_or_default();
|
||||||
|
|
|
|
||||||
LL | .unwrap_or(String::new());
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
|
|
||||||
|
|
||||||
error: use of `unwrap_or` followed by a call to `new`
|
error: use of `unwrap_or` followed by a call to `new`
|
||||||
--> $DIR/or_fun_call.rs:208:9
|
--> $DIR/or_fun_call.rs:208:9
|
||||||
|
Loading…
Reference in New Issue
Block a user