@@ -609,36 +609,43 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
609
609
if in_macro ( expr. span ) {
610
610
return ;
611
611
}
612
+
613
+ // apparently stuff in the desugaring of `?` can trigger this
614
+ // so check for that here
615
+ // only the calls to `Try::from_error` is marked as desugared,
616
+ // so we need to check both the current Expr and its parent.
617
+ if is_questionmark_desugar_marked_call ( expr) {
618
+ return ;
619
+ }
620
+ if_chain ! {
621
+ let map = & cx. tcx. hir( ) ;
622
+ let opt_parent_node = map. find( map. get_parent_node( expr. id) ) ;
623
+ if let Some ( hir:: Node :: Expr ( parent_expr) ) = opt_parent_node;
624
+ if is_questionmark_desugar_marked_call( parent_expr) ;
625
+ then {
626
+ return ;
627
+ }
628
+ }
629
+
612
630
match expr. node {
613
631
ExprKind :: Call ( _, ref args) | ExprKind :: MethodCall ( _, _, ref args) => {
614
632
for arg in args {
615
633
if is_unit ( cx. tables . expr_ty ( arg) ) && !is_unit_literal ( arg) {
616
- let map = & cx. tcx . hir ( ) ;
617
- // apparently stuff in the desugaring of `?` can trigger this
618
- // so check for that here
619
- // only the calls to `Try::from_error` is marked as desugared,
620
- // so we need to check both the current Expr and its parent.
621
- if !is_questionmark_desugar_marked_call ( expr) {
622
- if_chain ! {
623
- let opt_parent_node = map. find( map. get_parent_node( expr. id) ) ;
624
- if let Some ( hir:: Node :: Expr ( parent_expr) ) = opt_parent_node;
625
- if is_questionmark_desugar_marked_call( parent_expr) ;
626
- then { }
627
- else {
628
- // `expr` and `parent_expr` where _both_ not from
629
- // desugaring `?`, so lint
630
- span_lint_and_sugg(
631
- cx,
632
- UNIT_ARG ,
633
- arg. span,
634
- "passing a unit value to a function" ,
635
- "if you intended to pass a unit value, use a unit literal instead" ,
636
- "()" . to_string( ) ,
637
- Applicability :: MachineApplicable ,
638
- ) ;
639
- }
634
+ if let ExprKind :: Match ( .., match_source) = & arg. node {
635
+ if * match_source == MatchSource :: TryDesugar {
636
+ continue ;
640
637
}
641
638
}
639
+
640
+ span_lint_and_sugg (
641
+ cx,
642
+ UNIT_ARG ,
643
+ arg. span ,
644
+ "passing a unit value to a function" ,
645
+ "if you intended to pass a unit value, use a unit literal instead" ,
646
+ "()" . to_string ( ) ,
647
+ Applicability :: MachineApplicable ,
648
+ ) ;
642
649
}
643
650
}
644
651
} ,
0 commit comments