Skip to content

Commit 840e50e

Browse files
committed
Don't expand macro in or_fun_call suggestion
1 parent af1548f commit 840e50e

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::utils::sugg;
2121
use crate::utils::{
2222
get_arg_name, get_trait_def_id, implements_trait, in_macro, is_copy, is_expn_of, is_self, is_self_ty,
2323
iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method, match_type,
24-
match_var, method_chain_args, remove_blocks, return_ty, same_tys, single_segment_path, snippet, span_lint,
24+
match_var, method_chain_args, remove_blocks, return_ty, same_tys, single_segment_path, snippet, snippet_with_macro_callsite, span_lint,
2525
span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq,
2626
};
2727
use if_chain::if_chain;
@@ -1062,9 +1062,9 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
10621062
}
10631063

10641064
let sugg: Cow<'_, _> = match (fn_has_arguments, !or_has_args) {
1065-
(true, _) => format!("|_| {}", snippet(cx, arg.span, "..")).into(),
1066-
(false, false) => format!("|| {}", snippet(cx, arg.span, "..")).into(),
1067-
(false, true) => snippet(cx, fun_span, ".."),
1065+
(true, _) => format!("|_| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1066+
(false, false) => format!("|| {}", snippet_with_macro_callsite(cx, arg.span, "..")).into(),
1067+
(false, true) => snippet_with_macro_callsite(cx, fun_span, ".."),
10681068
};
10691069
let span_replace_word = method_span.with_hi(span.hi());
10701070
span_lint_and_sugg(

tests/ui/methods.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ error: use of `unwrap_or` followed by a function call
297297
--> $DIR/methods.rs:339:14
298298
|
299299
339 | with_vec.unwrap_or(vec![]);
300-
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ))`
300+
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| vec![])`
301301

302302
error: use of `unwrap_or` followed by a function call
303303
--> $DIR/methods.rs:344:21

0 commit comments

Comments
 (0)