@@ -7,25 +7,19 @@ use rustc_lint::LateContext;
7
7
use rustc_span:: sym;
8
8
9
9
pub ( super ) fn check ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , recv : & hir:: Expr < ' _ > ) {
10
- let ty = cx. typeck_results ( ) . expr_ty_adjusted ( recv) ;
11
-
12
- // If the .bytes() call is a call from the Read trait
13
- if is_trait_method ( cx, expr, sym:: IoRead ) {
14
- // Retrieve the DefId of the BufRead trait
15
- // FIXME: add a diagnostic item for `BufRead`
16
- let Some ( buf_read) = cx. tcx . get_diagnostic_item ( sym:: IoBufRead ) else {
17
- return ;
18
- } ;
19
- // And the implementor of the trait is not buffered
20
- if !implements_trait ( cx, ty, buf_read, & [ ] ) {
21
- span_lint_and_help (
22
- cx,
23
- UNBUFFERED_BYTES ,
24
- expr. span ,
25
- "calling .bytes() is very inefficient when data is not in memory" ,
26
- None ,
27
- "consider using `BufReader`" ,
28
- ) ;
29
- }
10
+ // Lint if the `.bytes()` call is from the `Read` trait and the implementor is not buffered.
11
+ if is_trait_method ( cx, expr, sym:: IoRead )
12
+ && let Some ( buf_read) = cx. tcx . get_diagnostic_item ( sym:: IoBufRead )
13
+ && let ty = cx. typeck_results ( ) . expr_ty_adjusted ( recv)
14
+ && !implements_trait ( cx, ty, buf_read, & [ ] )
15
+ {
16
+ span_lint_and_help (
17
+ cx,
18
+ UNBUFFERED_BYTES ,
19
+ expr. span ,
20
+ "calling .bytes() is very inefficient when data is not in memory" ,
21
+ None ,
22
+ "consider using `BufReader`" ,
23
+ ) ;
30
24
}
31
25
}
0 commit comments