Skip to content

Commit 3c49827

Browse files
committed
too_many_lines: only highlight the function signature
1 parent 833937a commit 3c49827

File tree

4 files changed

+22
-40
lines changed

4 files changed

+22
-40
lines changed

clippy_lints/src/functions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
503503
) {
504504
let hir_id = cx.tcx.local_def_id_to_hir_id(def_id);
505505
too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold);
506-
too_many_lines::check_fn(cx, kind, body, span, self.too_many_lines_threshold);
506+
too_many_lines::check_fn(cx, kind, decl, body, span, self.too_many_lines_threshold);
507507
not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id);
508508
misnamed_getters::check_fn(cx, kind, decl, body, span);
509509
impl_trait_in_params::check_fn(cx, &kind, body, hir_id);

clippy_lints/src/functions/too_many_lines.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::TOO_MANY_LINES;
1010
pub(super) fn check_fn(
1111
cx: &LateContext<'_>,
1212
kind: FnKind<'_>,
13+
decl: &hir::FnDecl<'_>,
1314
body: &hir::Body<'_>,
1415
span: Span,
1516
too_many_lines_threshold: u64,
@@ -74,7 +75,7 @@ pub(super) fn check_fn(
7475
span_lint(
7576
cx,
7677
TOO_MANY_LINES,
77-
span,
78+
span.with_hi(decl.output.span().hi()),
7879
format!("this function has too many lines ({line_count}/{too_many_lines_threshold})"),
7980
);
8081
}
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,29 @@
11
error: this function has too many lines (2/1)
22
--> tests/ui-toml/functions_maxlines/test.rs:19:1
33
|
4-
LL | / fn too_many_lines() {
5-
LL | |
6-
LL | | println!("This is bad.");
7-
LL | | println!("This is bad.");
8-
LL | | }
9-
| |_^
4+
LL | fn too_many_lines() {
5+
| ^^^^^^^^^^^^^^^^^^^
106
|
117
= note: `-D clippy::too-many-lines` implied by `-D warnings`
128
= help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]`
139

1410
error: this function has too many lines (4/1)
1511
--> tests/ui-toml/functions_maxlines/test.rs:26:1
1612
|
17-
LL | / async fn async_too_many_lines() {
18-
LL | |
19-
LL | | println!("This is bad.");
20-
LL | | println!("This is bad.");
21-
LL | | }
22-
| |_^
13+
LL | async fn async_too_many_lines() {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2315

2416
error: this function has too many lines (4/1)
2517
--> tests/ui-toml/functions_maxlines/test.rs:33:1
2618
|
27-
LL | / fn closure_too_many_lines() {
28-
LL | |
29-
LL | | let _ = {
30-
LL | | println!("This is bad.");
31-
LL | | println!("This is bad.");
32-
LL | | };
33-
LL | | }
34-
| |_^
19+
LL | fn closure_too_many_lines() {
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3521

3622
error: this function has too many lines (2/1)
3723
--> tests/ui-toml/functions_maxlines/test.rs:56:1
3824
|
39-
LL | / fn comment_before_code() {
40-
LL | |
41-
LL | | let _ = "test";
42-
LL | | /* This comment extends to the front of
43-
LL | | the code but this line should still count. */ let _ = 5;
44-
LL | | }
45-
| |_^
25+
LL | fn comment_before_code() {
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^
4627

4728
error: aborting due to 4 previous errors
4829

tests/ui/functions_maxlines.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error: this function has too many lines (102/100)
2-
--> tests/ui/functions_maxlines.rs:58:1
1+
error: this function has too many lines (104/100)
2+
--> tests/ui/functions_maxlines.rs:60:1
33
|
4-
LL | / fn bad_lines() {
5-
LL | |
6-
LL | |
7-
LL | | println!("Dont get confused by braces: {{}}");
8-
... |
9-
LL | | println!("This is bad.");
10-
LL | | }
11-
| |_^
4+
LL | pub async unsafe extern "Rust" fn bad_lines() -> () {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126
|
137
= note: `-D clippy::too-many-lines` implied by `-D warnings`
148
= help: to override `-D warnings` add `#[allow(clippy::too_many_lines)]`
159

16-
error: aborting due to 1 previous error
10+
error: this function has too many lines (104/100)
11+
--> tests/ui/functions_maxlines.rs:170:5
12+
|
13+
LL | pub async unsafe extern "Rust" fn bad_lines() -> () {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
1717

0 commit comments

Comments
 (0)