|
1 | 1 | use clippy_utils::diagnostics::span_lint_hir_and_then; |
2 | 2 | use clippy_utils::macros::{is_panic, root_macro_call_first_node}; |
3 | | -use clippy_utils::{is_res_lang_ctor, is_trait_method, match_trait_method, paths, peel_blocks}; |
| 3 | +use clippy_utils::{is_res_lang_ctor, is_trait_method,match_def_path,match_trait_method, paths, peel_blocks}; |
4 | 4 | use hir::{ExprKind,HirId,PatKind}; |
5 | 5 | use rustc_hir as hir; |
6 | 6 | use rustc_lint::{LateContext,LateLintPass}; |
@@ -83,6 +83,28 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { |
83 | 83 | /// to consider the arms, and we want to avoid breaking the logic for situations where things |
84 | 84 | /// get desugared to match. |
85 | 85 | fncheck_block(&mutself,cx:&LateContext<'tcx>,block:&'tcx hir::Block<'tcx>){ |
| 86 | +let fn_def_id = block.hir_id.owner.to_def_id(); |
| 87 | +ifletSome(impl_id) = cx.tcx.impl_of_method(fn_def_id) |
| 88 | + && letSome(trait_id) = cx.tcx.trait_id_of_impl(impl_id) |
| 89 | +{ |
| 90 | +// We don't want to lint inside io::Read or io::Write implementations, as the author has more |
| 91 | +// information about their trait implementation than our lint, see https://github.com/rust-lang/rust-clippy/issues/4836 |
| 92 | +if cx.tcx.is_diagnostic_item(sym::IoRead, trait_id) || cx.tcx.is_diagnostic_item(sym::IoWrite, trait_id){ |
| 93 | +return; |
| 94 | +} |
| 95 | + |
| 96 | +let async_paths:[&[&str];4] = [ |
| 97 | +&paths::TOKIO_IO_ASYNCREADEXT, |
| 98 | +&paths::TOKIO_IO_ASYNCWRITEEXT, |
| 99 | +&paths::FUTURES_IO_ASYNCREADEXT, |
| 100 | +&paths::FUTURES_IO_ASYNCWRITEEXT, |
| 101 | +]; |
| 102 | + |
| 103 | +if async_paths.into_iter().any(|path| match_def_path(cx, trait_id, path)){ |
| 104 | +return; |
| 105 | +} |
| 106 | +} |
| 107 | + |
86 | 108 | for stmt in block.stmts{ |
87 | 109 | iflet hir::StmtKind::Semi(exp) = stmt.kind{ |
88 | 110 | check_expr(cx, exp); |
|
0 commit comments