Skip to content

Commit cca4828

Browse files
Format type_of
1 parent 57ee5cf commit cca4828

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+36-28
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
333333
find_opaque_ty_constraints_for_tait(tcx, def_id)
334334
}
335335
// Opaque types desugared from `impl Trait`.
336-
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner), in_trait, .. }) => {
336+
ItemKind::OpaqueTy(OpaqueTy {
337+
origin:
338+
hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner),
339+
in_trait,
340+
..
341+
}) => {
337342
if in_trait {
338343
span_bug!(item.span, "impl-trait in trait has no default")
339344
} else {
@@ -378,7 +383,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
378383

379384
Node::Field(field) => icx.to_ty(field.ty),
380385

381-
Node::Expr(&Expr { kind: ExprKind::Closure{..}, .. }) => tcx.typeck(def_id).node_type(hir_id),
386+
Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => {
387+
tcx.typeck(def_id).node_type(hir_id)
388+
}
382389

383390
Node::AnonConst(_) if let Some(param) = tcx.opt_const_param_of(def_id) => {
384391
// We defer to `type_of` of the corresponding parameter
@@ -410,40 +417,42 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
410417
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
411418
if asm.operands.iter().any(|(op, _op_sp)| match op {
412419
hir::InlineAsmOperand::Const { anon_const }
413-
| hir::InlineAsmOperand::SymFn { anon_const } => anon_const.hir_id == hir_id,
420+
| hir::InlineAsmOperand::SymFn { anon_const } => {
421+
anon_const.hir_id == hir_id
422+
}
414423
_ => false,
415424
}) =>
416425
{
417426
tcx.typeck(def_id).node_type(hir_id)
418427
}
419428

420-
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
421-
.adt_def(tcx.hir().get_parent_item(hir_id))
422-
.repr()
423-
.discr_type()
424-
.to_ty(tcx),
429+
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
430+
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
431+
}
425432

426-
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
427-
if let Node::TraitRef(trait_ref) = tcx.hir().get(
428-
tcx.hir().get_parent_node(binding_id)
429-
) =>
433+
Node::TypeBinding(binding @ &TypeBinding { hir_id: binding_id, .. })
434+
if let Node::TraitRef(trait_ref) =
435+
tcx.hir().get(tcx.hir().get_parent_node(binding_id)) =>
430436
{
431-
let Some(trait_def_id) = trait_ref.trait_def_id() else {
437+
let Some(trait_def_id) = trait_ref.trait_def_id() else {
432438
return tcx.ty_error_with_message(DUMMY_SP, "Could not find trait");
433439
};
434-
let assoc_items = tcx.associated_items(trait_def_id);
435-
let assoc_item = assoc_items.find_by_name_and_kind(
436-
tcx, binding.ident, ty::AssocKind::Const, def_id.to_def_id(),
437-
);
438-
if let Some(assoc_item) = assoc_item {
439-
tcx.type_of(assoc_item.def_id)
440-
} else {
441-
// FIXME(associated_const_equality): add a useful error message here.
442-
tcx.ty_error_with_message(
443-
DUMMY_SP,
444-
"Could not find associated const on trait",
445-
)
446-
}
440+
let assoc_items = tcx.associated_items(trait_def_id);
441+
let assoc_item = assoc_items.find_by_name_and_kind(
442+
tcx,
443+
binding.ident,
444+
ty::AssocKind::Const,
445+
def_id.to_def_id(),
446+
);
447+
if let Some(assoc_item) = assoc_item {
448+
tcx.type_of(assoc_item.def_id)
449+
} else {
450+
// FIXME(associated_const_equality): add a useful error message here.
451+
tcx.ty_error_with_message(
452+
DUMMY_SP,
453+
"Could not find associated const on trait",
454+
)
455+
}
447456
}
448457

449458
Node::GenericParam(&GenericParam {
@@ -452,8 +461,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
452461
..
453462
}) if ct.hir_id == hir_id => tcx.type_of(tcx.hir().local_def_id(param_hir_id)),
454463

455-
x =>
456-
tcx.ty_error_with_message(
464+
x => tcx.ty_error_with_message(
457465
DUMMY_SP,
458466
&format!("unexpected const parent in type_of(): {x:?}"),
459467
),

0 commit comments

Comments
 (0)