From f31dd6b048a614c571e76f128945622cd03823f5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 30 Mar 2024 12:34:15 -0400 Subject: [PATCH] Fix up error message for debug_assert_args_compat for IATs --- compiler/rustc_middle/src/ty/context.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index de625f754ab3b..32f715e17884d 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2009,7 +2009,10 @@ impl<'tcx> TyCtxt<'tcx> { true } + /// With `cfg(debug_assertions)`, assert that args are compatible with their generics, + /// and print out the args if not. pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) { + // Fast-path for non-debug, bail out early. #[cfg(not(debug_assertions))] { return; @@ -2019,7 +2022,20 @@ impl<'tcx> TyCtxt<'tcx> { if let DefKind::AssocTy = self.def_kind(def_id) && let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { - bug!() + bug!( + "args not compatible with generics for {}: args={:#?}, generics={:#?}", + self.def_path_str(def_id), + args, + // Make `[Self, GAT_ARGS...]` (this could be simplified) + self.mk_args_from_iter( + [self.types.self_param.into()].into_iter().chain( + self.generics_of(def_id) + .own_args(ty::GenericArgs::identity_for_item(self, def_id)) + .iter() + .copied() + ) + ) + ); } else { bug!( "args not compatible with generics for {}: args={:#?}, generics={:#?}", @@ -2034,11 +2050,11 @@ impl<'tcx> TyCtxt<'tcx> { #[inline(always)] pub(crate) fn check_and_mk_args( self, - _def_id: DefId, + def_id: DefId, args: impl IntoIterator>>, ) -> GenericArgsRef<'tcx> { let args = self.mk_args_from_iter(args.into_iter().map(Into::into)); - self.debug_assert_args_compatible(_def_id, args); + self.debug_assert_args_compatible(def_id, args); args }