@@ -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,37 @@ 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
+ //
1066
+ // This has been historically allowed, but may be not allowed in future
1067
+ // https://github.com/rust-lang/rust/issues/127909
1068
+ if let Some ( ( _, v, it) ) = defs. types . as_mut ( ) {
1069
+ let is_extern_crate_reimport_without_prefix = || {
1070
+ let Some ( ImportOrExternCrate :: ExternCrate ( _) ) = it else {
1071
+ return false ;
1072
+ } ;
1073
+ let Some ( ImportType :: Import ( id) ) = def_import_type else {
1074
+ return false ;
1075
+ } ;
1076
+ let source = id. import . child_source ( self . db ) ;
1077
+ let Some ( use_tree_src) = source. value . get ( id. idx ) else {
1078
+ return false ;
1079
+ } ;
1080
+ use_tree_src. top_use_tree ( ) . path ( ) . and_then ( |p| p. first_segment ( ) ) . is_some_and (
1081
+ |s| {
1082
+ s. crate_token ( ) . is_none ( )
1083
+ && s. self_token ( ) . is_none ( )
1084
+ && s. coloncolon_token ( ) . is_none ( )
1085
+ } ,
1086
+ )
1087
+ } ;
1088
+ if is_extern_crate_reimport_without_prefix ( ) {
1089
+ * v = vis;
1090
+ } else {
1091
+ * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
1092
+ }
1063
1093
}
1064
1094
if let Some ( ( _, v, _) ) = defs. values . as_mut ( ) {
1065
1095
* v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
0 commit comments