@@ -6,8 +6,8 @@ use rustc_errors::Applicability;
6
6
use rustc_hir:: def_id:: LocalDefId ;
7
7
use rustc_hir:: intravisit:: FnKind ;
8
8
use rustc_hir:: {
9
- AssocItemConstraintKind , Body , Expr , ExprKind , FnDecl , FnRetTy , GenericArgsParentheses , Node , PolyTraitRef , Term ,
10
- Ty , TyKind ,
9
+ AssocItemConstraintKind , Body , Expr , ExprKind , FnDecl , FnRetTy , GenericArgsParentheses , PolyTraitRef , Term , Ty ,
10
+ TyKind ,
11
11
} ;
12
12
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
13
13
use rustc_session:: declare_lint_pass;
@@ -49,19 +49,22 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnit {
49
49
decl : & ' tcx FnDecl < ' tcx > ,
50
50
body : & ' tcx Body < ' tcx > ,
51
51
span : Span ,
52
- def_id : LocalDefId ,
52
+ _def_id : LocalDefId ,
53
53
) {
54
54
if let FnRetTy :: Return ( hir_ty) = decl. output
55
55
&& is_unit_ty ( hir_ty)
56
56
&& !hir_ty. span . from_expansion ( )
57
57
&& get_def ( span) == get_def ( hir_ty. span )
58
58
{
59
- // implicit types in closure signatures are forbidden when `for<...>` is present
60
- if let FnKind :: Closure = kind
61
- && let Node :: Expr ( expr) = cx. tcx . hir_node_by_def_id ( def_id)
62
- && let ExprKind :: Closure ( closure) = expr. kind
63
- && !closure. bound_generic_params . is_empty ( )
64
- {
59
+ // The explicit `-> ()` in the closure signature might be necessary for multiple reasons:
60
+ // - Implicit types in closure signatures are forbidden when `for<...>` is present
61
+ // - If the closure body ends with a function call, and that function's return type is generic, the
62
+ // `-> ()` could be required for it to be inferred
63
+ //
64
+ // There could be more reasons to have it, and, in general, we shouldn't discourage the users from
65
+ // writing more type annotations than strictly necessary, because it can help readability and
66
+ // maintainability
67
+ if let FnKind :: Closure = kind {
65
68
return ;
66
69
}
67
70
0 commit comments