Skip to content

Commit e251247

Browse files
committed
remove last use of MAX_SUGGESTION_HIGHLIGHT_LINES
1 parent 4c4152b commit e251247

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ 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;
87
use rustc_errors::Applicability;
98
use rustc_hir as hir;
109
use rustc_lint::LateContext;
@@ -33,7 +32,6 @@ pub(super) fn check<'tcx>(
3332
arg: &hir::Expr<'_>,
3433
or_has_args: bool,
3534
span: Span,
36-
method_span: Span,
3735
) -> bool {
3836
let is_default_default = || is_trait_item(cx, fun, sym::Default);
3937

@@ -56,19 +54,14 @@ pub(super) fn check<'tcx>(
5654
then {
5755
let mut applicability = Applicability::MachineApplicable;
5856
let hint = "unwrap_or_default()";
59-
let mut sugg_span = span;
57+
let sugg_span = span;
6058

61-
let mut sugg: String = format!(
59+
let sugg: String = format!(
6260
"{}.{}",
6361
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability),
6462
hint
6563
);
6664

67-
if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES {
68-
sugg_span = method_span.with_hi(span.hi());
69-
sugg = hint.to_string();
70-
}
71-
7265
span_lint_and_sugg(
7366
cx,
7467
OR_FUN_CALL,
@@ -178,7 +171,7 @@ pub(super) fn check<'tcx>(
178171
match inner_arg.kind {
179172
hir::ExprKind::Call(fun, or_args) => {
180173
let or_has_args = !or_args.is_empty();
181-
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span, method_span) {
174+
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span) {
182175
let fun_span = if or_has_args { None } else { Some(fun.span) };
183176
check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span);
184177
}

src/tools/clippy/tests/ui/or_fun_call.fixed

+2-4
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ mod issue8239 {
185185
.reduce(|mut acc, f| {
186186
acc.push_str(&f);
187187
acc
188-
})
189-
.unwrap_or_default();
188+
}).unwrap_or_default();
190189
}
191190

192191
fn more_to_max_suggestion_highest_lines_1() {
@@ -198,8 +197,7 @@ mod issue8239 {
198197
let _ = "";
199198
acc.push_str(&f);
200199
acc
201-
})
202-
.unwrap_or_default();
200+
}).unwrap_or_default();
203201
}
204202

205203
fn equal_to_max_suggestion_highest_lines() {

src/tools/clippy/tests/ui/or_fun_call.stderr

+40-6
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,50 @@ LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
110110

111111
error: use of `unwrap_or` followed by a call to `new`
112-
--> $DIR/or_fun_call.rs:189:14
112+
--> $DIR/or_fun_call.rs:182:9
113+
|
114+
LL | / frames
115+
LL | | .iter()
116+
LL | | .map(|f: &String| f.to_lowercase())
117+
LL | | .reduce(|mut acc, f| {
118+
... |
119+
LL | | })
120+
LL | | .unwrap_or(String::new());
121+
| |_____________________________________^
122+
|
123+
help: try this
124+
|
125+
LL ~ frames
126+
LL + .iter()
127+
LL + .map(|f: &String| f.to_lowercase())
128+
LL + .reduce(|mut acc, f| {
129+
LL + acc.push_str(&f);
130+
LL + acc
131+
LL ~ }).unwrap_or_default();
113132
|
114-
LL | .unwrap_or(String::new());
115-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
116133

117134
error: use of `unwrap_or` followed by a call to `new`
118-
--> $DIR/or_fun_call.rs:202:14
135+
--> $DIR/or_fun_call.rs:195:9
136+
|
137+
LL | / iter.map(|f: &String| f.to_lowercase())
138+
LL | | .reduce(|mut acc, f| {
139+
LL | | let _ = "";
140+
LL | | let _ = "";
141+
... |
142+
LL | | })
143+
LL | | .unwrap_or(String::new());
144+
| |_____________________________________^
145+
|
146+
help: try this
147+
|
148+
LL ~ iter.map(|f: &String| f.to_lowercase())
149+
LL + .reduce(|mut acc, f| {
150+
LL + let _ = "";
151+
LL + let _ = "";
152+
LL + acc.push_str(&f);
153+
LL + acc
154+
LL ~ }).unwrap_or_default();
119155
|
120-
LL | .unwrap_or(String::new());
121-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
122156

123157
error: use of `unwrap_or` followed by a call to `new`
124158
--> $DIR/or_fun_call.rs:208:9

0 commit comments

Comments
 (0)