@@ -4,8 +4,8 @@ use std::ops::Deref;
44
55use rustc_ast:: ptr:: P ;
66use rustc_ast:: {
7- Expr , ExprKind , FnDecl , FnRetTy , ForeignItem , ForeignItemKind , Item , ItemKind , NodeId , Path ,
8- QSelf , UseTreeKind , DUMMY_NODE_ID ,
7+ AssocItem , Expr , ExprKind , FnDecl , FnRetTy , ForeignItem , ForeignItemKind , Item , ItemKind ,
8+ NodeId , Path , QSelf , UseTreeKind , DUMMY_NODE_ID ,
99} ;
1010use rustc_data_structures:: fx:: FxHashMap ;
1111use rustc_errors:: { DiagnosticBuilder , Level } ;
@@ -1072,6 +1072,16 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> {
10721072 pub fn compatible_types ( & self , item1 : & Item , item2 : & Item , match_vis : bool ) -> bool {
10731073 use rustc_ast:: ItemKind :: * ;
10741074 match ( & item1. kind , & item2. kind ) {
1075+ ( Impl ( box ref impl1) , Impl ( box ref impl2) ) => {
1076+ if impl1. items . len ( ) != impl2. items . len ( ) {
1077+ return false ;
1078+ }
1079+
1080+ ( impl1. items . iter ( ) )
1081+ . zip ( impl2. items . iter ( ) )
1082+ . all ( |( item1, item2) | self . compatible_assoc_items ( item1, item2, match_vis) )
1083+ }
1084+
10751085 // * Assure that these two items are in fact of the same type, just to be safe.
10761086 ( TyAlias ( box ref ta1) , TyAlias ( box ref ta2) ) => {
10771087 match (
@@ -1226,6 +1236,40 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> {
12261236 }
12271237 }
12281238
1239+ pub fn compatible_assoc_items (
1240+ & self ,
1241+ item1 : & AssocItem ,
1242+ item2 : & AssocItem ,
1243+ match_vis : bool ,
1244+ ) -> bool {
1245+ use rustc_ast:: AssocItemKind :: * ;
1246+
1247+ // Unlike for regular items, associated items must also match by name.
1248+ if item1. ident . as_str ( ) != item2. ident . as_str ( ) {
1249+ return false ;
1250+ }
1251+
1252+ match ( & item1. kind , & item2. kind ) {
1253+ ( Const ( def1, ty1, expr1) , Const ( def2, ty2, expr2) ) => match (
1254+ self . cx . opt_node_type ( item1. id ) ,
1255+ self . cx . opt_node_type ( item2. id ) ,
1256+ ) {
1257+ ( Some ( ty1) , Some ( ty2) ) => {
1258+ self . structural_eq_tys ( ty1, ty2)
1259+ && expr1. unnamed_equiv ( expr2)
1260+ && def1. unnamed_equiv ( def2)
1261+ }
1262+ _ => {
1263+ self . structural_eq_ast_tys ( ty1, ty2, match_vis)
1264+ && expr1. unnamed_equiv ( expr2)
1265+ && def1. unnamed_equiv ( def2)
1266+ }
1267+ } ,
1268+
1269+ _ => false ,
1270+ }
1271+ }
1272+
12291273 /// Compare two function declarations for equivalent argument and return types,
12301274 /// ignoring argument names.
12311275 pub fn compatible_fn_prototypes ( & self , decl1 : & FnDecl , decl2 : & FnDecl ) -> bool {
0 commit comments