@@ -2009,36 +2009,48 @@ 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 > ] ) {
2013
- #[ cfg( not( debug_assertions) ) ]
2014
- {
2015
- return ;
2016
- }
2017
-
2018
- if !self . check_args_compatible ( def_id, args) {
2019
- if let DefKind :: AssocTy = self . def_kind ( def_id)
2020
- && let DefKind :: Impl { of_trait : false } = self . def_kind ( self . parent ( def_id) )
2021
- {
2022
- bug ! ( )
2023
- } else {
2024
- bug ! (
2025
- "args not compatible with generics for {}: args={:#?}, generics={:#?}" ,
2026
- self . def_path_str( def_id) ,
2027
- args,
2028
- ty:: GenericArgs :: identity_for_item( self , def_id)
2029
- ) ;
2015
+ if cfg ! ( debug_assertions) {
2016
+ if !self . check_args_compatible ( def_id, args) {
2017
+ if let DefKind :: AssocTy = self . def_kind ( def_id)
2018
+ && let DefKind :: Impl { of_trait : false } = self . def_kind ( self . parent ( def_id) )
2019
+ {
2020
+ bug ! (
2021
+ "args not compatible with generics for {}: args={:#?}, generics={:#?}" ,
2022
+ self . def_path_str( def_id) ,
2023
+ args,
2024
+ // Make `[Self, GAT_ARGS...]` (this could be simplified)
2025
+ self . mk_args_from_iter(
2026
+ [ self . types. self_param. into( ) ] . into_iter( ) . chain(
2027
+ self . generics_of( def_id)
2028
+ . own_args( ty:: GenericArgs :: identity_for_item( self , def_id) )
2029
+ . iter( )
2030
+ . copied( )
2031
+ )
2032
+ )
2033
+ ) ;
2034
+ } else {
2035
+ bug ! (
2036
+ "args not compatible with generics for {}: args={:#?}, generics={:#?}" ,
2037
+ self . def_path_str( def_id) ,
2038
+ args,
2039
+ ty:: GenericArgs :: identity_for_item( self , def_id)
2040
+ ) ;
2041
+ }
2030
2042
}
2031
2043
}
2032
2044
}
2033
2045
2034
2046
#[ inline( always) ]
2035
2047
pub ( crate ) fn check_and_mk_args (
2036
2048
self ,
2037
- _def_id : DefId ,
2049
+ def_id : DefId ,
2038
2050
args : impl IntoIterator < Item : Into < GenericArg < ' tcx > > > ,
2039
2051
) -> GenericArgsRef < ' tcx > {
2040
2052
let args = self . mk_args_from_iter ( args. into_iter ( ) . map ( Into :: into) ) ;
2041
- self . debug_assert_args_compatible ( _def_id , args) ;
2053
+ self . debug_assert_args_compatible ( def_id , args) ;
2042
2054
args
2043
2055
}
2044
2056
0 commit comments