Skip to content

Commit a6562bd

Browse files
committed
Only lower tuple structs if in fact a constructor
1 parent 475cd1e commit a6562bd

File tree

1 file changed

+16
-4
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+16
-4
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
88
use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::struct_span_err;
1010
use rustc_hir as hir;
11-
use rustc_hir::def::Res;
11+
use rustc_hir::def::{DefKind, Res};
1212
use rustc_span::hygiene::ForLoopLoc;
1313
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1414
use rustc_span::symbol::{sym, Ident, Symbol};
@@ -940,9 +940,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
940940
ParamMode::Optional,
941941
ImplTraitContext::disallowed(),
942942
);
943-
let tuple_struct_pat =
944-
hir::PatKind::TupleStruct(qpath, pats, rest.map(|r| r.0));
945-
return self.pat(lhs.span, tuple_struct_pat);
943+
match qpath {
944+
hir::QPath::Resolved(
945+
_,
946+
hir::Path { res: Res::Def(DefKind::Ctor(..), _), .. },
947+
) => {
948+
// Destructure like a tuple struct since the path is in fact a constructor.
949+
let tuple_struct_pat =
950+
hir::PatKind::TupleStruct(qpath, pats, rest.map(|r| r.0));
951+
return self.pat(lhs.span, tuple_struct_pat);
952+
}
953+
_ => {
954+
// If the path is not a constructor, lower as an ordinary LHS.
955+
// Typecheck will report an error later.
956+
}
957+
}
946958
}
947959
}
948960
// structs:

0 commit comments

Comments
 (0)