1
1
mod too_many_arguments;
2
+ mod too_many_lines;
2
3
3
4
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help, span_lint_and_then} ;
4
- use clippy_utils:: source:: { snippet , snippet_opt} ;
5
+ use clippy_utils:: source:: snippet_opt;
5
6
use clippy_utils:: ty:: { is_must_use_ty, is_type_diagnostic_item, type_is_unsafe_function} ;
6
7
use clippy_utils:: {
7
8
attr_by_name, attrs:: is_proc_macro, iter_input_pats, match_def_path, must_use_attr, path_to_local, return_ty,
@@ -256,6 +257,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
256
257
hir_id : hir:: HirId ,
257
258
) {
258
259
too_many_arguments:: check_fn ( cx, kind, decl, span, hir_id, self . too_many_arguments_threshold ) ;
260
+ too_many_lines:: check ( cx, span, body, self . too_many_lines_threshold ) ;
259
261
260
262
let unsafety = match kind {
261
263
intravisit:: FnKind :: ItemFn ( _, _, hir:: FnHeader { unsafety, .. } , _) => unsafety,
@@ -264,7 +266,6 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
264
266
} ;
265
267
266
268
Self :: check_raw_ptr ( cx, unsafety, decl, body, hir_id) ;
267
- self . check_line_number ( cx, span, body) ;
268
269
}
269
270
270
271
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: Item < ' _ > ) {
@@ -356,65 +357,6 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
356
357
}
357
358
358
359
impl < ' tcx > Functions {
359
- fn check_line_number ( self , cx : & LateContext < ' _ > , span : Span , body : & ' tcx hir:: Body < ' _ > ) {
360
- if in_external_macro ( cx. sess ( ) , span) {
361
- return ;
362
- }
363
-
364
- let code_snippet = snippet ( cx, body. value . span , ".." ) ;
365
- let mut line_count: u64 = 0 ;
366
- let mut in_comment = false ;
367
- let mut code_in_line;
368
-
369
- // Skip the surrounding function decl.
370
- let start_brace_idx = code_snippet. find ( '{' ) . map_or ( 0 , |i| i + 1 ) ;
371
- let end_brace_idx = code_snippet. rfind ( '}' ) . unwrap_or_else ( || code_snippet. len ( ) ) ;
372
- let function_lines = code_snippet[ start_brace_idx..end_brace_idx] . lines ( ) ;
373
-
374
- for mut line in function_lines {
375
- code_in_line = false ;
376
- loop {
377
- line = line. trim_start ( ) ;
378
- if line. is_empty ( ) {
379
- break ;
380
- }
381
- if in_comment {
382
- if let Some ( i) = line. find ( "*/" ) {
383
- line = & line[ i + 2 ..] ;
384
- in_comment = false ;
385
- continue ;
386
- }
387
- } else {
388
- let multi_idx = line. find ( "/*" ) . unwrap_or_else ( || line. len ( ) ) ;
389
- let single_idx = line. find ( "//" ) . unwrap_or_else ( || line. len ( ) ) ;
390
- code_in_line |= multi_idx > 0 && single_idx > 0 ;
391
- // Implies multi_idx is below line.len()
392
- if multi_idx < single_idx {
393
- line = & line[ multi_idx + 2 ..] ;
394
- in_comment = true ;
395
- continue ;
396
- }
397
- }
398
- break ;
399
- }
400
- if code_in_line {
401
- line_count += 1 ;
402
- }
403
- }
404
-
405
- if line_count > self . too_many_lines_threshold {
406
- span_lint (
407
- cx,
408
- TOO_MANY_LINES ,
409
- span,
410
- & format ! (
411
- "this function has too many lines ({}/{})" ,
412
- line_count, self . too_many_lines_threshold
413
- ) ,
414
- )
415
- }
416
- }
417
-
418
360
fn check_raw_ptr (
419
361
cx : & LateContext < ' tcx > ,
420
362
unsafety : hir:: Unsafety ,
0 commit comments