@@ -31,7 +31,7 @@ use crate::{
31
31
item_scope:: { ImportId , ImportOrExternCrate , ImportType , PerNsGlobImports } ,
32
32
item_tree:: {
33
33
self , AttrOwner , FieldsShape , FileItemTreeId , ImportKind , ItemTree , ItemTreeId ,
34
- ItemTreeNode , Macro2 , MacroCall , MacroRules , Mod , ModItem , ModKind , TreeId ,
34
+ ItemTreeNode , Macro2 , MacroCall , MacroRules , Mod , ModItem , ModKind , TreeId , UseTreeKind ,
35
35
} ,
36
36
macro_call_as_call_id, macro_call_as_call_id_with_eager,
37
37
nameres:: {
@@ -1058,8 +1058,33 @@ impl DefCollector<'_> {
1058
1058
vis : Visibility ,
1059
1059
def_import_type : Option < ImportType > ,
1060
1060
) -> bool {
1061
- if let Some ( ( _, v, _) ) = defs. types . as_mut ( ) {
1062
- * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
1061
+ // `extern crate crate_name` things can be re-exported as `pub use crate_name`.
1062
+ // But they cannot be re-exported as `pub use self::crate_name`, `pub use crate::crate_name`
1063
+ // or `pub use ::crate_name`.
1064
+ //
1065
+ // This has been historically allowed, but may be not allowed in future
1066
+ // https://github.com/rust-lang/rust/issues/127909
1067
+ if let Some ( ( _, v, it) ) = defs. types . as_mut ( ) {
1068
+ let is_extern_crate_reimport_without_prefix = || {
1069
+ let Some ( ImportOrExternCrate :: ExternCrate ( _) ) = it else {
1070
+ return false ;
1071
+ } ;
1072
+ let Some ( ImportType :: Import ( id) ) = def_import_type else {
1073
+ return false ;
1074
+ } ;
1075
+ let use_id = id. import . lookup ( self . db ) . id ;
1076
+ let item_tree = use_id. item_tree ( self . db ) ;
1077
+ let use_kind = item_tree[ use_id. value ] . use_tree . kind ( ) ;
1078
+ let UseTreeKind :: Single { path, .. } = use_kind else {
1079
+ return false ;
1080
+ } ;
1081
+ path. segments ( ) . len ( ) < 2
1082
+ } ;
1083
+ if is_extern_crate_reimport_without_prefix ( ) {
1084
+ * v = vis;
1085
+ } else {
1086
+ * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
1087
+ }
1063
1088
}
1064
1089
if let Some ( ( _, v, _) ) = defs. values . as_mut ( ) {
1065
1090
* v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
0 commit comments