@@ -31,7 +31,7 @@ use crate::{
3131 item_scope:: { ImportId , ImportOrExternCrate , ImportType , PerNsGlobImports } ,
3232 item_tree:: {
3333 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 ,
3535 } ,
3636 macro_call_as_call_id, macro_call_as_call_id_with_eager,
3737 nameres:: {
@@ -1058,8 +1058,33 @@ impl DefCollector<'_> {
10581058 vis : Visibility ,
10591059 def_import_type : Option < ImportType > ,
10601060 ) -> 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+ }
10631088 }
10641089 if let Some ( ( _, v, _) ) = defs. values . as_mut ( ) {
10651090 * v = v. min ( vis, & self . def_map ) . unwrap_or ( vis) ;
0 commit comments