diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-04-03 17:15:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-03 17:15:48 +0200 |
| commit | 94c402733d8bca4675fc8040cd968ecc5e5387a0 (patch) | |
| tree | c9eb833073db69fbced371b64be22d760ca5b0b9 /compiler | |
| parent | f7c34c03bed369b069cf37c581676d0f9ee2c975 (diff) | |
| parent | cc5105d246c77d54cabb4f595d4e87c14358073d (diff) | |
| download | rust-94c402733d8bca4675fc8040cd968ecc5e5387a0.tar.gz rust-94c402733d8bca4675fc8040cd968ecc5e5387a0.zip | |
Rollup merge of #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
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect/type_of.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 722def2563c..9d7deebac48 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -474,9 +474,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty VariantData::Unit(..) | VariantData::Struct { .. } => { tcx.type_of(tcx.hir().get_parent_item(hir_id)).instantiate_identity() } - VariantData::Tuple(..) => { + VariantData::Tuple(_, _, ctor) => { let args = ty::GenericArgs::identity_for_item(tcx, def_id); - Ty::new_fn_def(tcx, def_id.to_def_id(), args) + Ty::new_fn_def(tcx, ctor.to_def_id(), args) } }, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index b5e619f1e2a..ba0898e07c2 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -11,7 +11,7 @@ use crate::ty::{ }; use crate::ty::{GenericArg, GenericArgs, GenericArgsRef}; use crate::ty::{List, ParamEnv}; -use hir::def::DefKind; +use hir::def::{CtorKind, DefKind}; use rustc_data_structures::captures::Captures; use rustc_errors::{DiagArgValue, ErrorGuaranteed, IntoDiagArg, MultiSpan}; use rustc_hir as hir; @@ -1677,6 +1677,10 @@ impl<'tcx> Ty<'tcx> { def_id: DefId, args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, ) -> Ty<'tcx> { + debug_assert_matches!( + tcx.def_kind(def_id), + DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) + ); let args = tcx.check_and_mk_args(def_id, args); Ty::new(tcx, FnDef(def_id, args)) } |
