@@ -4245,6 +4245,20 @@ impl<'a> CondChecker<'a> {
42454245 }
42464246}
42474247
4248+ impl CondChecker < ' _ > {
4249+ fn get_path_from_rhs ( e : & Expr ) -> Option < ( u32 , & Path ) > {
4250+ Self :: get_path_from_rhs_inner ( e, 0 )
4251+ }
4252+
4253+ fn get_path_from_rhs_inner ( e : & Expr , depth : u32 ) -> Option < ( u32 , & Path ) > {
4254+ match & e. kind {
4255+ ExprKind :: Binary ( _, lhs, _) => Self :: get_path_from_rhs_inner ( lhs, depth + 1 ) ,
4256+ ExprKind :: Path ( _, path) => Some ( ( depth, path) ) ,
4257+ _ => None ,
4258+ }
4259+ }
4260+ }
4261+
42484262impl MutVisitor for CondChecker < ' _ > {
42494263 fn visit_expr ( & mut self , e : & mut Expr ) {
42504264 self . depth += 1 ;
@@ -4304,7 +4318,23 @@ impl MutVisitor for CondChecker<'_> {
43044318 mut_visit:: walk_expr ( self , e) ;
43054319 self . forbid_let_reason = forbid_let_reason;
43064320 }
4307- ExprKind :: Assign ( ref lhs, _, span) => {
4321+ ExprKind :: Assign ( ref lhs, ref rhs, span) => {
4322+ if let ExprKind :: Call ( _, _) = & lhs. kind {
4323+ if let Some ( ( depth, path) ) = CondChecker :: get_path_from_rhs ( rhs) {
4324+ let expr_span = lhs. span . to ( path. span ) ;
4325+
4326+ if depth > 0 {
4327+ let guar = self . parser . dcx ( ) . emit_err ( errors:: LetChainMissingLet {
4328+ span : lhs. span ,
4329+ label_span : expr_span,
4330+ sug_span : lhs. span . shrink_to_lo ( ) ,
4331+ } ) ;
4332+
4333+ self . found_incorrect_let_chain = Some ( guar) ;
4334+ }
4335+ }
4336+ }
4337+
43084338 let forbid_let_reason = self . forbid_let_reason ;
43094339 self . forbid_let_reason = Some ( OtherForbidden ) ;
43104340 let missing_let = self . missing_let ;
0 commit comments