Skip to content

Commit 310b8f7

Browse files
Fix up error message for debug_assert_args_compat for IATs
1 parent 5bd0be8 commit 310b8f7

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

compiler/rustc_middle/src/ty/context.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,10 @@ impl<'tcx> TyCtxt<'tcx> {
20092009
true
20102010
}
20112011

2012+
// With `cfg(debug_assertions)`, assert that args are compatible with their generics,
2013+
// and print out the args if not.
20122014
pub fn debug_assert_args_compatible(self, def_id: DefId, args: &'tcx [ty::GenericArg<'tcx>]) {
2015+
// Fast-path for non-debug, bail out early.
20132016
#[cfg(not(debug_assertions))]
20142017
{
20152018
return;
@@ -2019,7 +2022,20 @@ impl<'tcx> TyCtxt<'tcx> {
20192022
if let DefKind::AssocTy = self.def_kind(def_id)
20202023
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id))
20212024
{
2022-
bug!()
2025+
bug!(
2026+
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
2027+
self.def_path_str(def_id),
2028+
args,
2029+
// Make `[Self, GAT_ARGS...]` (this could be simplified)
2030+
self.mk_args_from_iter(
2031+
[self.types.self_param.into()].into_iter().chain(
2032+
self.generics_of(def_id)
2033+
.own_args(ty::GenericArgs::identity_for_item(self, def_id))
2034+
.iter()
2035+
.copied()
2036+
)
2037+
)
2038+
);
20232039
} else {
20242040
bug!(
20252041
"args not compatible with generics for {}: args={:#?}, generics={:#?}",
@@ -2034,11 +2050,11 @@ impl<'tcx> TyCtxt<'tcx> {
20342050
#[inline(always)]
20352051
pub(crate) fn check_and_mk_args(
20362052
self,
2037-
_def_id: DefId,
2053+
def_id: DefId,
20382054
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
20392055
) -> GenericArgsRef<'tcx> {
20402056
let args = self.mk_args_from_iter(args.into_iter().map(Into::into));
2041-
self.debug_assert_args_compatible(_def_id, args);
2057+
self.debug_assert_args_compatible(def_id, args);
20422058
args
20432059
}
20442060

0 commit comments

Comments
 (0)