@@ -7,26 +7,25 @@ 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
- // Retrieve the DefId of the BufRead trait
11
- // FIXME: add a diagnostic item for `BufRead`
12
- let Some ( buf_read) = get_trait_def_id ( cx. tcx , & paths:: BUF_READ ) else {
13
- return ;
14
- } ;
10
+ let ty = cx. typeck_results ( ) . expr_ty_adjusted ( recv) ;
15
11
16
- let typ = cx. typeck_results ( ) . expr_ty_adjusted ( recv) ;
17
- if
18
- // The .bytes() call is a call from the given trait
19
- is_trait_method ( cx, expr, sym:: IoRead )
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) = get_trait_def_id ( cx. tcx , & paths:: BUF_READ ) else {
17
+ return ;
18
+ } ;
20
19
// And the implementor of the trait is not buffered
21
- && !implements_trait ( cx, typ , buf_read, & [ ] )
22
- {
23
- span_lint_and_help (
24
- cx ,
25
- UNBUFFERED_BYTES ,
26
- expr . span ,
27
- "calling .bytes() is very inefficient when data is not in memory" ,
28
- None ,
29
- "consider using `BufReader`" ,
30
- ) ;
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
+ }
31
30
}
32
31
}
0 commit comments