Skip to content

Commit 94c4027

Browse files
authored
Rollup merge of rust-lang#123382 - compiler-errors:assert-fndef-kind, r=fmease
Assert `FnDef` kind Only found one bug, where we were using the variant def id rather than its ctor def id to make the `FnDef` for a `type_of` r? fmease
2 parents f7c34c0 + cc5105d commit 94c4027

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
474474
VariantData::Unit(..) | VariantData::Struct { .. } => {
475475
tcx.type_of(tcx.hir().get_parent_item(hir_id)).instantiate_identity()
476476
}
477-
VariantData::Tuple(..) => {
477+
VariantData::Tuple(_, _, ctor) => {
478478
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
479-
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
479+
Ty::new_fn_def(tcx, ctor.to_def_id(), args)
480480
}
481481
},
482482

compiler/rustc_middle/src/ty/sty.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ty::{
1111
};
1212
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
1313
use crate::ty::{List, ParamEnv};
14-
use hir::def::DefKind;
14+
use hir::def::{CtorKind, DefKind};
1515
use rustc_data_structures::captures::Captures;
1616
use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagArg, MultiSpan};
1717
use rustc_hir as hir;
@@ -1677,6 +1677,10 @@ impl<'tcx> Ty<'tcx> {
16771677
def_id: DefId,
16781678
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
16791679
) -> Ty<'tcx> {
1680+
debug_assert_matches!(
1681+
tcx.def_kind(def_id),
1682+
DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)
1683+
);
16801684
let args = tcx.check_and_mk_args(def_id, args);
16811685
Ty::new(tcx, FnDef(def_id, args))
16821686
}

0 commit comments

Comments
 (0)