Skip to content

Commit c7979d3

Browse files
committed
Fix rebase fallout
1 parent 250c184 commit c7979d3

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

clippy_lints/src/matches.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use crate::utils::paths;
33
use crate::utils::sugg::Sugg;
44
use crate::utils::usage::is_unused;
55
use crate::utils::{
6-
expr_block, get_arg_name, in_macro, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath, match_type,
7-
match_var, multispan_sugg, remove_blocks, snippet, snippet_block, snippet_with_applicability, span_lint_and_help,
8-
span_lint_and_note, span_lint_and_sugg, span_lint_and_then, walk_ptrs_ty,
6+
expr_block, get_arg_name, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_wild, match_qpath,
7+
match_type, match_var, multispan_sugg, remove_blocks, snippet, snippet_block, snippet_with_applicability,
8+
span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then, walk_ptrs_ty,
99
};
1010
use if_chain::if_chain;
1111
use rustc::lint::in_external_macro;
@@ -836,7 +836,7 @@ fn check_match_single_binding(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[A
836836
let mut snippet_body = if match_body.span.from_expansion() {
837837
Sugg::hir_with_macro_callsite(cx, match_body, "..").to_string()
838838
} else {
839-
snippet_block(cx, match_body.span, "..").to_owned().to_string()
839+
snippet_block(cx, match_body.span, "..", Some(expr.span)).to_string()
840840
};
841841

842842
// Do we need to add ';' to suggestion ?
@@ -865,10 +865,11 @@ fn check_match_single_binding(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[A
865865
"this match could be written as a `let` statement",
866866
"consider using `let` statement",
867867
format!(
868-
"let {} = {};\n{}",
868+
"let {} = {};\n{}{}",
869869
snippet_with_applicability(cx, bind_names, "..", &mut applicability),
870870
snippet_with_applicability(cx, matched_vars, "..", &mut applicability),
871-
snippet_body
871+
" ".repeat(indent_of(cx, expr.span).unwrap_or(0)),
872+
snippet_body,
872873
),
873874
applicability,
874875
);

tests/ui/match_single_binding.fixed

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ fn main() {
1414
let c = 3;
1515
// Lint
1616
let (x, y, z) = (a, b, c);
17-
{
18-
println!("{} {} {}", x, y, z);
19-
}
17+
{
18+
println!("{} {} {}", x, y, z);
19+
}
2020
// Lint
2121
let (x, y, z) = (a, b, c);
22-
println!("{} {} {}", x, y, z);
22+
println!("{} {} {}", x, y, z);
2323
// Ok
2424
match a {
2525
2 => println!("2"),
@@ -35,29 +35,29 @@ println!("{} {} {}", x, y, z);
3535
println!("whatever");
3636
// Lint
3737
{
38-
let x = 29;
39-
println!("x has a value of {}", x);
40-
}
38+
let x = 29;
39+
println!("x has a value of {}", x);
40+
}
4141
// Lint
4242
{
43-
let e = 5 * a;
44-
if e >= 5 {
45-
println!("e is superior to 5");
43+
let e = 5 * a;
44+
if e >= 5 {
45+
println!("e is superior to 5");
46+
}
4647
}
47-
}
4848
// Lint
4949
let p = Point { x: 0, y: 7 };
5050
let Point { x, y } = p;
51-
println!("Coords: ({}, {})", x, y);
51+
println!("Coords: ({}, {})", x, y);
5252
// Lint
5353
let Point { x: x1, y: y1 } = p;
54-
println!("Coords: ({}, {})", x1, y1);
54+
println!("Coords: ({}, {})", x1, y1);
5555
// Lint
5656
let x = 5;
5757
let ref r = x;
58-
println!("Got a reference to {}", r);
58+
println!("Got a reference to {}", r);
5959
// Lint
6060
let mut x = 5;
6161
let ref mut mr = x;
62-
println!("Got a mutable reference to {}", mr);
62+
println!("Got a mutable reference to {}", mr);
6363
}

tests/ui/match_single_binding.stderr

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ LL | | }
1212
help: consider using `let` statement
1313
|
1414
LL | let (x, y, z) = (a, b, c);
15-
LL | {
16-
LL | println!("{} {} {}", x, y, z);
17-
LL | }
15+
LL | {
16+
LL | println!("{} {} {}", x, y, z);
17+
LL | }
1818
|
1919

2020
error: this match could be written as a `let` statement
@@ -28,7 +28,7 @@ LL | | }
2828
help: consider using `let` statement
2929
|
3030
LL | let (x, y, z) = (a, b, c);
31-
LL | println!("{} {} {}", x, y, z);
31+
LL | println!("{} {} {}", x, y, z);
3232
|
3333

3434
error: this match could be replaced by its body itself
@@ -53,9 +53,9 @@ LL | | }
5353
help: consider using the match body instead
5454
|
5555
LL | {
56-
LL | let x = 29;
57-
LL | println!("x has a value of {}", x);
58-
LL | }
56+
LL | let x = 29;
57+
LL | println!("x has a value of {}", x);
58+
LL | }
5959
|
6060

6161
error: this match could be replaced by its body itself
@@ -73,11 +73,11 @@ LL | | }
7373
help: consider using the match body instead
7474
|
7575
LL | {
76-
LL | let e = 5 * a;
77-
LL | if e >= 5 {
78-
LL | println!("e is superior to 5");
76+
LL | let e = 5 * a;
77+
LL | if e >= 5 {
78+
LL | println!("e is superior to 5");
79+
LL | }
7980
LL | }
80-
LL | }
8181
|
8282

8383
error: this match could be written as a `let` statement
@@ -91,7 +91,7 @@ LL | | }
9191
help: consider using `let` statement
9292
|
9393
LL | let Point { x, y } = p;
94-
LL | println!("Coords: ({}, {})", x, y);
94+
LL | println!("Coords: ({}, {})", x, y);
9595
|
9696

9797
error: this match could be written as a `let` statement
@@ -105,7 +105,7 @@ LL | | }
105105
help: consider using `let` statement
106106
|
107107
LL | let Point { x: x1, y: y1 } = p;
108-
LL | println!("Coords: ({}, {})", x1, y1);
108+
LL | println!("Coords: ({}, {})", x1, y1);
109109
|
110110

111111
error: this match could be written as a `let` statement
@@ -119,7 +119,7 @@ LL | | }
119119
help: consider using `let` statement
120120
|
121121
LL | let ref r = x;
122-
LL | println!("Got a reference to {}", r);
122+
LL | println!("Got a reference to {}", r);
123123
|
124124

125125
error: this match could be written as a `let` statement
@@ -133,7 +133,7 @@ LL | | }
133133
help: consider using `let` statement
134134
|
135135
LL | let ref mut mr = x;
136-
LL | println!("Got a mutable reference to {}", mr);
136+
LL | println!("Got a mutable reference to {}", mr);
137137
|
138138

139139
error: aborting due to 9 previous errors

0 commit comments

Comments
 (0)