Skip to content

Commit 07b1912

Browse files
refactor
1 parent b9e991a commit 07b1912

File tree

1 file changed

+19
-17
lines changed
  • compiler/rustc_mir_build/src/thir/cx

1 file changed

+19
-17
lines changed

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,18 @@ impl<'tcx> Cx<'tcx> {
208208
// so we wouldn't have to compute and store the actual value
209209

210210
let hir::ExprKind::Path(ref qpath) = source.kind else {
211-
return ExprKind::Cast { source: self.mirror_expr(source)};
211+
return ExprKind::Cast { source: self.mirror_expr(source) };
212212
};
213213

214214
let res = self.typeck_results().qpath_res(qpath, source.hir_id);
215215
let ty = self.typeck_results().node_type(source.hir_id);
216216
let ty::Adt(adt_def, substs) = ty.kind() else {
217-
return ExprKind::Cast { source: self.mirror_expr(source)};
217+
return ExprKind::Cast { source: self.mirror_expr(source) };
218218
};
219219

220-
let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res else {
221-
return ExprKind::Cast { source: self.mirror_expr(source)};
220+
let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
221+
else {
222+
return ExprKind::Cast { source: self.mirror_expr(source) };
222223
};
223224

224225
let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
@@ -351,28 +352,29 @@ impl<'tcx> Cx<'tcx> {
351352
});
352353
}
353354
}
354-
let adt_data = if let hir::ExprKind::Path(qpath) = fun.kind {
355+
356+
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
357+
let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
358+
&& let Some(adt_def) = expr_ty.ty_adt_def() {
355359
match qpath {
356-
// Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
357360
hir::QPath::Resolved(_, ref path) => {
358-
expr_ty.ty_adt_def().and_then(|adt_def| match path.res {
361+
match path.res {
359362
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
360363
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
361364
}
362365
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
363366
_ => None,
364-
})
367+
}
365368
}
366369
hir::QPath::TypeRelative(_ty, _) => {
367-
expr_ty.ty_adt_def().and_then(|adt_def| {
368-
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
369-
self.typeck_results().type_dependent_def(fun.hir_id)
370-
{
371-
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
372-
} else {
373-
None
374-
}
375-
})
370+
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
371+
self.typeck_results().type_dependent_def(fun.hir_id)
372+
{
373+
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
374+
} else {
375+
None
376+
}
377+
376378
}
377379
_ => None,
378380
}

0 commit comments

Comments
 (0)