Skip to content

Commit 330b181

Browse files
committed
Check for constructors in early return condition
1 parent 5e39caa commit 330b181

File tree

1 file changed

+26
-11
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+26
-11
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,33 @@ impl<'hir> LoweringContext<'_, 'hir> {
870870
whole_span: Span,
871871
) -> hir::ExprKind<'hir> {
872872
// Return early in case of an ordinary assignment.
873-
match lhs.kind {
874-
ExprKind::Array(..)
875-
| ExprKind::Call(..)
876-
| ExprKind::Struct(_, _, None)
877-
| ExprKind::Tup(..) => {}
878-
_ => {
879-
return hir::ExprKind::Assign(
880-
self.lower_expr(lhs),
881-
self.lower_expr(rhs),
882-
eq_sign_span,
883-
);
873+
let is_ordinary = match &lhs.kind {
874+
ExprKind::Array(..) | ExprKind::Struct(_, _, None) | ExprKind::Tup(..) => false,
875+
ExprKind::Call(callee, ..) => {
876+
// Check for tuple struct constructor.
877+
if let ExprKind::Path(qself, path) = &callee.kind {
878+
let qpath = self.lower_qpath(
879+
callee.id,
880+
qself,
881+
path,
882+
ParamMode::Optional,
883+
ImplTraitContext::disallowed(),
884+
);
885+
match qpath {
886+
hir::QPath::Resolved(
887+
_,
888+
hir::Path { res: Res::Def(DefKind::Ctor(..), _), .. },
889+
) => false,
890+
_ => true,
891+
}
892+
} else {
893+
true
894+
}
884895
}
896+
_ => true,
897+
};
898+
if is_ordinary {
899+
return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span);
885900
}
886901

887902
let mut assignments = Vec::new();

0 commit comments

Comments
 (0)