@@ -11,6 +11,7 @@ use rustc_ast::{
11
11
Item , ItemKind , MethodCall , NodeId , Path , Ty , TyKind ,
12
12
} ;
13
13
use rustc_ast_pretty:: pprust:: where_bound_predicate_to_string;
14
+ use rustc_attr:: collect_doc_alias_symbol_from_attrs;
14
15
use rustc_data_structures:: fx:: { FxHashSet , FxIndexSet } ;
15
16
use rustc_errors:: codes:: * ;
16
17
use rustc_errors:: {
@@ -40,7 +41,7 @@ use crate::late::{
40
41
} ;
41
42
use crate :: ty:: fast_reject:: SimplifiedType ;
42
43
use crate :: {
43
- Module , ModuleKind , ModuleOrUniformRoot , PathResult , PathSource , Segment , errors,
44
+ Module , ModuleKind , ModuleOrUniformRoot , PathResult , PathSource , Resolver , Segment , errors,
44
45
path_names_to_string,
45
46
} ;
46
47
@@ -459,6 +460,18 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
459
460
return ( err, Vec :: new ( ) ) ;
460
461
}
461
462
463
+ if let Some ( did) = self . lookup_doc_alias_name ( path, source. namespace ( ) ) {
464
+ err. span_label (
465
+ self . r . def_span ( did) ,
466
+ format ! (
467
+ "`{}` has a name defined in the doc alias attribute as `{}`" ,
468
+ self . r. tcx. item_name( did) ,
469
+ path. last( ) . unwrap( ) . ident. as_str( )
470
+ ) ,
471
+ ) ;
472
+ return ( err, Vec :: new ( ) ) ;
473
+ } ;
474
+
462
475
let ( found, mut candidates) = self . try_lookup_name_relaxed (
463
476
& mut err,
464
477
source,
@@ -783,6 +796,50 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
783
796
( false , candidates)
784
797
}
785
798
799
+ fn lookup_doc_alias_name ( & mut self , path : & [ Segment ] , ns : Namespace ) -> Option < DefId > {
800
+ let item_str = path. last ( ) . unwrap ( ) . ident ;
801
+
802
+ let find_doc_alias_name = |r : & mut Resolver < ' ra , ' _ > , m : Module < ' ra > | {
803
+ for resolution in r. resolutions ( m) . borrow ( ) . values ( ) {
804
+ let Some ( did) =
805
+ resolution. borrow ( ) . binding . and_then ( |binding| binding. res ( ) . opt_def_id ( ) )
806
+ else {
807
+ continue ;
808
+ } ;
809
+ if did. is_local ( ) {
810
+ // We don't record the doc alias name in the local crate
811
+ // because the people who write doc alias are usually not
812
+ // confused by them.
813
+ continue ;
814
+ }
815
+ let symbols = collect_doc_alias_symbol_from_attrs ( r. tcx . get_attrs ( did, sym:: doc) ) ;
816
+ if symbols. contains ( & item_str. name ) {
817
+ return Some ( did) ;
818
+ }
819
+ }
820
+ None
821
+ } ;
822
+
823
+ if path. len ( ) == 1 {
824
+ for rib in self . ribs [ ns] . iter ( ) . rev ( ) {
825
+ if let RibKind :: Module ( module) = rib. kind
826
+ && let Some ( did) = find_doc_alias_name ( self . r , module)
827
+ {
828
+ return Some ( did) ;
829
+ }
830
+ }
831
+ } else {
832
+ let mod_path = & path[ ..path. len ( ) - 1 ] ;
833
+ if let PathResult :: Module ( ModuleOrUniformRoot :: Module ( module) ) =
834
+ self . resolve_path ( mod_path, Some ( TypeNS ) , None )
835
+ && let Some ( did) = find_doc_alias_name ( self . r , module)
836
+ {
837
+ return Some ( did) ;
838
+ }
839
+ }
840
+ None
841
+ }
842
+
786
843
fn suggest_trait_and_bounds (
787
844
& mut self ,
788
845
err : & mut Diag < ' _ > ,
0 commit comments