@@ -2009,7 +2009,10 @@ impl<'tcx> TyCtxt<'tcx> {
2009
2009
true
2010
2010
}
2011
2011
2012
+ // With `cfg(debug_assertions)`, assert that args are compatible with their generics,
2013
+ // and print out the args if not.
2012
2014
pub fn debug_assert_args_compatible ( self , def_id : DefId , args : & ' tcx [ ty:: GenericArg < ' tcx > ] ) {
2015
+ // Fast-path for non-debug, bail out early.
2013
2016
#[ cfg( not( debug_assertions) ) ]
2014
2017
{
2015
2018
return ;
@@ -2019,7 +2022,20 @@ impl<'tcx> TyCtxt<'tcx> {
2019
2022
if let DefKind :: AssocTy = self . def_kind ( def_id)
2020
2023
&& let DefKind :: Impl { of_trait : false } = self . def_kind ( self . parent ( def_id) )
2021
2024
{
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
+ ) ;
2023
2039
} else {
2024
2040
bug ! (
2025
2041
"args not compatible with generics for {}: args={:#?}, generics={:#?}" ,
@@ -2034,11 +2050,11 @@ impl<'tcx> TyCtxt<'tcx> {
2034
2050
#[ inline( always) ]
2035
2051
pub ( crate ) fn check_and_mk_args (
2036
2052
self ,
2037
- _def_id : DefId ,
2053
+ def_id : DefId ,
2038
2054
args : impl IntoIterator < Item : Into < GenericArg < ' tcx > > > ,
2039
2055
) -> GenericArgsRef < ' tcx > {
2040
2056
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) ;
2042
2058
args
2043
2059
}
2044
2060
0 commit comments