Skip to content

Commit a3c73a9

Browse files
committed
submodules: update clippy from d8e6e4c to 1ff81c1
Changes: ```` rustup rust-lang/rust#69968 Fix documentation generation for configurable lints Fix single binding in closure Improvement: Don't show function body in needless_lifetimes ````
1 parent 5fb022a commit a3c73a9

9 files changed

+93
-73
lines changed

clippy_lints/src/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ fn lint_for_missing_headers<'a, 'tcx>(
234234
if implements_trait(cx, ret_ty, future, &[]);
235235
if let ty::Opaque(_, subs) = ret_ty.kind;
236236
if let Some(gen) = subs.types().next();
237-
if let ty::Generator(def_id, subs, _) = gen.kind;
238-
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT);
237+
if let ty::Generator(_, subs, _) = gen.kind;
238+
if match_type(cx, subs.as_generator().return_ty(), &paths::RESULT);
239239
then {
240240
span_lint(
241241
cx,

clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn check_fn_inner<'a, 'tcx>(
169169
span_lint(
170170
cx,
171171
NEEDLESS_LIFETIMES,
172-
span,
172+
span.with_hi(decl.output.span().hi()),
173173
"explicit lifetimes given in parameter types where they could be elided \
174174
(or replaced with `'_` if needed by type declaration)",
175175
);

clippy_lints/src/matches.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ 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, 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,
6+
expr_block, get_arg_name, get_parent_expr, in_macro, indent_of, is_allowed, is_expn_of, is_refutable, is_wild,
7+
match_qpath, match_type, match_var, multispan_sugg, remove_blocks, snippet, snippet_block,
8+
snippet_with_applicability, span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
9+
walk_ptrs_ty,
910
};
1011
use if_chain::if_chain;
1112
use rustc::lint::in_external_macro;
@@ -928,14 +929,27 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms:
928929
),
929930
)
930931
} else {
932+
// If we are in closure, we need curly braces around suggestion
933+
let mut indent = " ".repeat(indent_of(cx, ex.span).unwrap_or(0));
934+
let (mut cbrace_start, mut cbrace_end) = ("".to_string(), "".to_string());
935+
if let Some(parent_expr) = get_parent_expr(cx, expr) {
936+
if let ExprKind::Closure(..) = parent_expr.kind {
937+
cbrace_end = format!("\n{}}}", indent);
938+
// Fix body indent due to the closure
939+
indent = " ".repeat(indent_of(cx, bind_names).unwrap_or(0));
940+
cbrace_start = format!("{{\n{}", indent);
941+
}
942+
};
931943
(
932944
expr.span,
933945
format!(
934-
"let {} = {};\n{}{}",
946+
"{}let {} = {};\n{}{}{}",
947+
cbrace_start,
935948
snippet_with_applicability(cx, bind_names, "..", &mut applicability),
936949
snippet_with_applicability(cx, matched_vars, "..", &mut applicability),
937-
" ".repeat(indent_of(cx, expr.span).unwrap_or(0)),
938-
snippet_body
950+
indent,
951+
snippet_body,
952+
cbrace_end
939953
),
940954
)
941955
};

tests/ui/issue_4266.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ error: explicit lifetimes given in parameter types where they could be elided (o
22
--> $DIR/issue_4266.rs:4:1
33
|
44
LL | async fn sink1<'a>(_: &'a str) {} // lint
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
88

99
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
1010
--> $DIR/issue_4266.rs:8:1
1111
|
12-
LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str {
13-
LL | | s
14-
LL | | }
15-
| |_^
12+
LL | async fn one_to_one<'a>(s: &'a str) -> &'a str {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1614

1715
error: aborting due to 2 previous errors
1816

tests/ui/match_single_binding.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ fn main() {
6767
// Lint
6868
let Point { x, y } = coords();
6969
let product = x * y;
70+
// Lint
71+
let v = vec![Some(1), Some(2), Some(3), Some(4)];
72+
#[allow(clippy::let_and_return)]
73+
let _ = v
74+
.iter()
75+
.map(|i| {
76+
let unwrapped = i.unwrap();
77+
unwrapped
78+
})
79+
.collect::<Vec<u8>>();
7080
}

tests/ui/match_single_binding.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,13 @@ fn main() {
8080
let product = match coords() {
8181
Point { x, y } => x * y,
8282
};
83+
// Lint
84+
let v = vec![Some(1), Some(2), Some(3), Some(4)];
85+
#[allow(clippy::let_and_return)]
86+
let _ = v
87+
.iter()
88+
.map(|i| match i.unwrap() {
89+
unwrapped => unwrapped,
90+
})
91+
.collect::<Vec<u8>>();
8392
}

tests/ui/match_single_binding.stderr

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,22 @@ LL | let Point { x, y } = coords();
150150
LL | let product = x * y;
151151
|
152152

153-
error: aborting due to 10 previous errors
153+
error: this match could be written as a `let` statement
154+
--> $DIR/match_single_binding.rs:88:18
155+
|
156+
LL | .map(|i| match i.unwrap() {
157+
| __________________^
158+
LL | | unwrapped => unwrapped,
159+
LL | | })
160+
| |_________^
161+
|
162+
help: consider using `let` statement
163+
|
164+
LL | .map(|i| {
165+
LL | let unwrapped = i.unwrap();
166+
LL | unwrapped
167+
LL | })
168+
|
169+
170+
error: aborting due to 11 previous errors
154171

tests/ui/needless_lifetimes.stderr

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,133 +2,105 @@ error: explicit lifetimes given in parameter types where they could be elided (o
22
--> $DIR/needless_lifetimes.rs:4:1
33
|
44
LL | fn distinct_lifetimes<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: u8) {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`
88

99
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
1010
--> $DIR/needless_lifetimes.rs:6:1
1111
|
1212
LL | fn distinct_and_static<'a, 'b>(_x: &'a u8, _y: &'b u8, _z: &'static u8) {}
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
1616
--> $DIR/needless_lifetimes.rs:16:1
1717
|
18-
LL | / fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
19-
LL | | x
20-
LL | | }
21-
| |_^
18+
LL | fn in_and_out<'a>(x: &'a u8, _y: u8) -> &'a u8 {
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2220

2321
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
2422
--> $DIR/needless_lifetimes.rs:45:1
2523
|
26-
LL | / fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
27-
LL | | Ok(x)
28-
LL | | }
29-
| |_^
24+
LL | fn deep_reference_3<'a>(x: &'a u8, _y: u8) -> Result<&'a u8, ()> {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3026

3127
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
3228
--> $DIR/needless_lifetimes.rs:50:1
3329
|
34-
LL | / fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
35-
LL | | where
36-
LL | | T: Copy,
37-
LL | | {
38-
LL | | Ok(x)
39-
LL | | }
40-
| |_^
30+
LL | fn where_clause_without_lt<'a, T>(x: &'a u8, _y: u8) -> Result<&'a u8, ()>
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4132

4233
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
4334
--> $DIR/needless_lifetimes.rs:62:1
4435
|
4536
LL | fn lifetime_param_2<'a, 'b>(_x: Ref<'a>, _y: &'b u8) {}
46-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4738

4839
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
4940
--> $DIR/needless_lifetimes.rs:86:1
5041
|
51-
LL | / fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
52-
LL | | where
53-
LL | | for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>,
54-
LL | | {
55-
LL | | unreachable!()
56-
LL | | }
57-
| |_^
42+
LL | fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5844

5945
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
6046
--> $DIR/needless_lifetimes.rs:120:5
6147
|
62-
LL | / fn self_and_out<'s>(&'s self) -> &'s u8 {
63-
LL | | &self.x
64-
LL | | }
65-
| |_____^
48+
LL | fn self_and_out<'s>(&'s self) -> &'s u8 {
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6650

6751
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
6852
--> $DIR/needless_lifetimes.rs:129:5
6953
|
7054
LL | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) {}
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7256

7357
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
7458
--> $DIR/needless_lifetimes.rs:148:1
7559
|
76-
LL | / fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
77-
LL | | unimplemented!()
78-
LL | | }
79-
| |_^
60+
LL | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str {
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8062

8163
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
8264
--> $DIR/needless_lifetimes.rs:178:1
8365
|
84-
LL | / fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
85-
LL | | unimplemented!()
86-
LL | | }
87-
| |_^
66+
LL | fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8868

8969
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
9070
--> $DIR/needless_lifetimes.rs:184:1
9171
|
92-
LL | / fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
93-
LL | | unimplemented!()
94-
LL | | }
95-
| |_^
72+
LL | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str {
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9674

9775
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
9876
--> $DIR/needless_lifetimes.rs:203:1
9977
|
100-
LL | / fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
101-
LL | | unimplemented!()
102-
LL | | }
103-
| |_^
78+
LL | fn named_input_elided_output<'a>(_arg: &'a str) -> &str {
79+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10480

10581
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
10682
--> $DIR/needless_lifetimes.rs:211:1
10783
|
108-
LL | / fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
109-
LL | | unimplemented!()
110-
LL | | }
111-
| |_^
84+
LL | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) {
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11286

11387
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
11488
--> $DIR/needless_lifetimes.rs:247:1
11589
|
116-
LL | / fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
117-
LL | | unimplemented!()
118-
LL | | }
119-
| |_^
90+
LL | fn out_return_type_lts<'a>(e: &'a str) -> Cow<'a> {
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12092

12193
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
12294
--> $DIR/needless_lifetimes.rs:254:9
12395
|
12496
LL | fn needless_lt<'a>(x: &'a u8) {}
125-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12698

12799
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
128100
--> $DIR/needless_lifetimes.rs:258:9
129101
|
130102
LL | fn needless_lt<'a>(_x: &'a u8) {}
131-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132104

133105
error: aborting due to 17 previous errors
134106

util/lintlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
group_re = re.compile(r'''\s*([a-z_][a-z_0-9]+)''')
1515
conf_re = re.compile(r'''define_Conf! {\n([^}]*)\n}''', re.MULTILINE)
1616
confvar_re = re.compile(
17-
r'''/// Lint: (\w+). (.*).*\n\s*\([^,]+,\s+"([^"]+)",\s+([^=\)]+)=>\s+(.*)\),''', re.MULTILINE)
17+
r'''/// Lint: (\w+)\. (.*)\n\s*\([^,]+,\s+"([^"]+)":\s+([^,]+),\s+([^\.\)]+).*\),''', re.MULTILINE)
1818
comment_re = re.compile(r'''\s*/// ?(.*)''')
1919

2020
lint_levels = {
@@ -93,7 +93,7 @@ def parse_configs(path):
9393
match = re.search(conf_re, contents)
9494
confvars = re.findall(confvar_re, match.group(1))
9595

96-
for (lint, doc, name, default, ty) in confvars:
96+
for (lint, doc, name, ty, default) in confvars:
9797
configs[lint.lower()] = Config(name.replace("_", "-"), ty, doc, default)
9898

9999
return configs

0 commit comments

Comments
 (0)