@@ -45,6 +45,7 @@ use crate::{
45
45
} ,
46
46
path:: { ImportAlias , ModPath , PathKind } ,
47
47
per_ns:: PerNs ,
48
+ src:: HasChildSource ,
48
49
tt,
49
50
visibility:: { RawVisibility , Visibility } ,
50
51
AdtId , AstId , AstIdWithPath , ConstLoc , CrateRootModuleId , EnumLoc , EnumVariantLoc ,
@@ -1058,8 +1059,34 @@ impl DefCollector<'_> {
1058
1059
vis : Visibility ,
1059
1060
def_import_type : Option < ImportType > ,
1060
1061
) -> bool {
1061
- if let Some ( ( _, v, _) ) = defs. types . as_mut ( ) {
1062
- * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
1062
+ // `extern crate crate_name` things can be re-exported as `pub use crate_name`.
1063
+ // But they cannot be re-exported as `pub use self::crate_name`, `pub use crate::crate_name`
1064
+ // or `pub use ::crate_name`.
1065
+ if let Some ( ( _, v, it) ) = defs. types . as_mut ( ) {
1066
+ let is_extern_crate_reimport_without_prefix = || {
1067
+ let Some ( ImportOrExternCrate :: ExternCrate ( _) ) = it else {
1068
+ return false ;
1069
+ } ;
1070
+ let Some ( ImportType :: Import ( id) ) = def_import_type else {
1071
+ return false ;
1072
+ } ;
1073
+ let source = id. import . child_source ( self . db ) ;
1074
+ let Some ( use_tree_src) = source. value . get ( id. idx ) else {
1075
+ return false ;
1076
+ } ;
1077
+ use_tree_src. top_use_tree ( ) . path ( ) . and_then ( |p| p. first_segment ( ) ) . is_some_and (
1078
+ |s| {
1079
+ s. crate_token ( ) . is_none ( )
1080
+ && s. self_token ( ) . is_none ( )
1081
+ && s. coloncolon_token ( ) . is_none ( )
1082
+ } ,
1083
+ )
1084
+ } ;
1085
+ if is_extern_crate_reimport_without_prefix ( ) {
1086
+ * v = vis;
1087
+ } else {
1088
+ * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
1089
+ }
1063
1090
}
1064
1091
if let Some ( ( _, v, _) ) = defs. values . as_mut ( ) {
1065
1092
* v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
0 commit comments