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