@@ -6,8 +6,8 @@ use rustc_errors::Applicability;
66use rustc_hir:: def_id:: LocalDefId ;
77use rustc_hir:: intravisit:: FnKind ;
88use 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 ,
1111} ;
1212use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass } ;
1313use rustc_session:: declare_lint_pass;
@@ -49,19 +49,22 @@ impl<'tcx> LateLintPass<'tcx> for UnusedUnit {
4949 decl : & ' tcx FnDecl < ' tcx > ,
5050 body : & ' tcx Body < ' tcx > ,
5151 span : Span ,
52- def_id : LocalDefId ,
52+ _def_id : LocalDefId ,
5353 ) {
5454 if let FnRetTy :: Return ( hir_ty) = decl. output
5555 && is_unit_ty ( hir_ty)
5656 && !hir_ty. span . from_expansion ( )
5757 && get_def ( span) == get_def ( hir_ty. span )
5858 {
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 {
6568 return ;
6669 }
6770
0 commit comments