@@ -806,6 +806,20 @@ fn trait_impls_for<'a>(
806
806
iter. collect ( )
807
807
}
808
808
809
+ /// Check for resolve collisions between a trait and its derive.
810
+ ///
811
+ /// These are common and we should just resolve to the trait in that case.
812
+ fn is_derive_trait_collision < T > ( ns : & PerNS < Result < Vec < ( Res , T ) > , ResolutionFailure < ' _ > > > ) -> bool {
813
+ if let ( & Ok ( ref type_ns) , & Ok ( ref macro_ns) ) = ( & ns. type_ns , & ns. macro_ns ) {
814
+ type_ns. iter ( ) . any ( |( res, _) | matches ! ( res, Res :: Def ( DefKind :: Trait , _) ) )
815
+ && macro_ns
816
+ . iter ( )
817
+ . any ( |( res, _) | matches ! ( res, Res :: Def ( DefKind :: Macro ( MacroKind :: Derive ) , _) ) )
818
+ } else {
819
+ false
820
+ }
821
+ }
822
+
809
823
impl < ' a , ' tcx > DocVisitor for LinkCollector < ' a , ' tcx > {
810
824
fn visit_item ( & mut self , item : & Item ) {
811
825
self . resolve_links ( item) ;
@@ -1313,9 +1327,22 @@ impl LinkCollector<'_, '_> {
1313
1327
disambiguator,
1314
1328
candidates. into_iter ( ) . filter_map ( |res| res. err ( ) ) . collect ( ) ,
1315
1329
) ;
1330
+ } else if len == 1 {
1331
+ candidates. into_iter ( ) . filter_map ( |res| res. ok ( ) ) . flatten ( ) . collect :: < Vec < _ > > ( )
1332
+ } else {
1333
+ let has_derive_trait_collision = is_derive_trait_collision ( & candidates) ;
1334
+ if len == 2 && has_derive_trait_collision {
1335
+ candidates. type_ns . unwrap ( )
1336
+ } else {
1337
+ // If we're reporting an ambiguity, don't mention the namespaces that failed
1338
+ let mut candidates = candidates. map ( |candidate| candidate. ok ( ) ) ;
1339
+ // If there a collision between a trait and a derive, we ignore the derive.
1340
+ if has_derive_trait_collision {
1341
+ candidates. macro_ns = None ;
1342
+ }
1343
+ candidates. into_iter ( ) . filter_map ( |res| res) . flatten ( ) . collect :: < Vec < _ > > ( )
1344
+ }
1316
1345
}
1317
-
1318
- candidates. into_iter ( ) . filter_map ( |res| res. ok ( ) ) . flatten ( ) . collect :: < Vec < _ > > ( )
1319
1346
}
1320
1347
}
1321
1348
}
0 commit comments