mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-29 19:17:12 +00:00 
			
		
		
		
	Merge pull request #19016 from Veykril/push-moqnsytyrupu
fix: Fix `ItemScope` not recording glob imports
This commit is contained in:
		
						commit
						93de80d833
					
				
					 11 changed files with 239 additions and 213 deletions
				
			
		|  | @ -475,7 +475,7 @@ fn outer() { | |||
| 
 | ||||
|             block scope::tests | ||||
|             name: _ | ||||
|             outer: v | ||||
|             outer: vg | ||||
| 
 | ||||
|             crate | ||||
|             outer: v | ||||
|  |  | |||
|  | @ -168,6 +168,7 @@ impl ImportMap { | |||
|                         match import { | ||||
|                             ImportOrExternCrate::ExternCrate(id) => Some(id.into()), | ||||
|                             ImportOrExternCrate::Import(id) => Some(id.import.into()), | ||||
|                             ImportOrExternCrate::Glob(id) => Some(id.into()), | ||||
|                         } | ||||
|                     } else { | ||||
|                         match item { | ||||
|  |  | |||
|  | @ -31,10 +31,54 @@ pub struct PerNsGlobImports { | |||
| 
 | ||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||||
| pub enum ImportOrExternCrate { | ||||
|     Glob(UseId), | ||||
|     Import(ImportId), | ||||
|     ExternCrate(ExternCrateId), | ||||
| } | ||||
| 
 | ||||
| impl From<ImportOrGlob> for ImportOrExternCrate { | ||||
|     fn from(value: ImportOrGlob) -> Self { | ||||
|         match value { | ||||
|             ImportOrGlob::Glob(it) => ImportOrExternCrate::Glob(it), | ||||
|             ImportOrGlob::Import(it) => ImportOrExternCrate::Import(it), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl From<ImportType> for ImportOrExternCrate { | ||||
|     fn from(value: ImportType) -> Self { | ||||
|         match value { | ||||
|             ImportType::Glob(it) => ImportOrExternCrate::Glob(it), | ||||
|             ImportType::Import(it) => ImportOrExternCrate::Import(it), | ||||
|             ImportType::ExternCrate(it) => ImportOrExternCrate::ExternCrate(it), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl ImportOrExternCrate { | ||||
|     pub fn into_import(self) -> Option<ImportOrGlob> { | ||||
|         match self { | ||||
|             ImportOrExternCrate::Import(it) => Some(ImportOrGlob::Import(it)), | ||||
|             ImportOrExternCrate::Glob(it) => Some(ImportOrGlob::Glob(it)), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||||
| pub enum ImportOrGlob { | ||||
|     Glob(UseId), | ||||
|     Import(ImportId), | ||||
| } | ||||
| 
 | ||||
| impl ImportOrGlob { | ||||
|     pub fn into_import(self) -> Option<ImportId> { | ||||
|         match self { | ||||
|             ImportOrGlob::Import(it) => Some(it), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||||
| pub(crate) enum ImportType { | ||||
|     Import(ImportId), | ||||
|  | @ -42,21 +86,33 @@ pub(crate) enum ImportType { | |||
|     ExternCrate(ExternCrateId), | ||||
| } | ||||
| 
 | ||||
| impl ImportOrExternCrate { | ||||
|     pub fn into_import(self) -> Option<ImportId> { | ||||
|         match self { | ||||
|             ImportOrExternCrate::Import(it) => Some(it), | ||||
|             _ => None, | ||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||||
| pub enum ImportOrDef { | ||||
|     Import(ImportId), | ||||
|     Glob(UseId), | ||||
|     ExternCrate(ExternCrateId), | ||||
|     Def(ModuleDefId), | ||||
| } | ||||
| 
 | ||||
| impl From<ImportOrExternCrate> for ImportOrDef { | ||||
|     fn from(value: ImportOrExternCrate) -> Self { | ||||
|         match value { | ||||
|             ImportOrExternCrate::Import(it) => ImportOrDef::Import(it), | ||||
|             ImportOrExternCrate::Glob(it) => ImportOrDef::Glob(it), | ||||
|             ImportOrExternCrate::ExternCrate(it) => ImportOrDef::ExternCrate(it), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||||
| pub enum ImportOrDef { | ||||
|     Import(ImportId), | ||||
|     ExternCrate(ExternCrateId), | ||||
|     Def(ModuleDefId), | ||||
| impl From<ImportOrGlob> for ImportOrDef { | ||||
|     fn from(value: ImportOrGlob) -> Self { | ||||
|         match value { | ||||
|             ImportOrGlob::Import(it) => ImportOrDef::Import(it), | ||||
|             ImportOrGlob::Glob(it) => ImportOrDef::Glob(it), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] | ||||
| pub struct ImportId { | ||||
|     pub import: UseId, | ||||
|  | @ -96,8 +152,8 @@ pub struct ItemScope { | |||
| 
 | ||||
|     // the resolutions of the imports of this scope
 | ||||
|     use_imports_types: FxHashMap<ImportOrExternCrate, ImportOrDef>, | ||||
|     use_imports_values: FxHashMap<ImportId, ImportOrDef>, | ||||
|     use_imports_macros: FxHashMap<ImportId, ImportOrDef>, | ||||
|     use_imports_values: FxHashMap<ImportOrGlob, ImportOrDef>, | ||||
|     use_imports_macros: FxHashMap<ImportOrGlob, ImportOrDef>, | ||||
| 
 | ||||
|     use_decls: Vec<UseId>, | ||||
|     extern_crate_decls: Vec<ExternCrateId>, | ||||
|  | @ -162,7 +218,7 @@ impl ItemScope { | |||
|             .map(move |name| (name, self.get(name))) | ||||
|     } | ||||
| 
 | ||||
|     pub fn values(&self) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportId>)> + '_ { | ||||
|     pub fn values(&self) -> impl Iterator<Item = (&Name, Item<ModuleDefId, ImportOrGlob>)> + '_ { | ||||
|         self.values.iter().map(|(n, &i)| (n, i)) | ||||
|     } | ||||
| 
 | ||||
|  | @ -172,7 +228,7 @@ impl ItemScope { | |||
|         self.types.iter().map(|(n, &i)| (n, i)) | ||||
|     } | ||||
| 
 | ||||
|     pub fn macros(&self) -> impl Iterator<Item = (&Name, Item<MacroId, ImportId>)> + '_ { | ||||
|     pub fn macros(&self) -> impl Iterator<Item = (&Name, Item<MacroId, ImportOrGlob>)> + '_ { | ||||
|         self.macros.iter().map(|(n, &i)| (n, i)) | ||||
|     } | ||||
| 
 | ||||
|  | @ -183,6 +239,7 @@ impl ItemScope { | |||
|             .filter_map(ImportOrExternCrate::into_import) | ||||
|             .chain(self.use_imports_values.keys().copied()) | ||||
|             .chain(self.use_imports_macros.keys().copied()) | ||||
|             .filter_map(ImportOrGlob::into_import) | ||||
|             .sorted() | ||||
|             .dedup() | ||||
|     } | ||||
|  | @ -192,7 +249,7 @@ impl ItemScope { | |||
| 
 | ||||
|         let mut def_map; | ||||
|         let mut scope = self; | ||||
|         while let Some(&m) = scope.use_imports_macros.get(&import) { | ||||
|         while let Some(&m) = scope.use_imports_macros.get(&ImportOrGlob::Import(import)) { | ||||
|             match m { | ||||
|                 ImportOrDef::Import(i) => { | ||||
|                     let module_id = i.import.lookup(db).container; | ||||
|  | @ -224,7 +281,7 @@ impl ItemScope { | |||
|             } | ||||
|         } | ||||
|         let mut scope = self; | ||||
|         while let Some(&m) = scope.use_imports_values.get(&import) { | ||||
|         while let Some(&m) = scope.use_imports_values.get(&ImportOrGlob::Import(import)) { | ||||
|             match m { | ||||
|                 ImportOrDef::Import(i) => { | ||||
|                     let module_id = i.import.lookup(db).container; | ||||
|  | @ -514,29 +571,11 @@ impl ItemScope { | |||
|                         } | ||||
|                         _ => _ = glob_imports.types.remove(&lookup), | ||||
|                     } | ||||
|                     let import = match import { | ||||
|                         Some(ImportType::ExternCrate(extern_crate)) => { | ||||
|                             Some(ImportOrExternCrate::ExternCrate(extern_crate)) | ||||
|                         } | ||||
|                         Some(ImportType::Import(import)) => { | ||||
|                             Some(ImportOrExternCrate::Import(import)) | ||||
|                         } | ||||
|                         None | Some(ImportType::Glob(_)) => None, | ||||
|                     }; | ||||
|                     let import = import.map(Into::into); | ||||
|                     let prev = std::mem::replace(&mut fld.import, import); | ||||
|                     if let Some(import) = import { | ||||
|                         self.use_imports_types.insert( | ||||
|                             import, | ||||
|                             match prev { | ||||
|                                 Some(ImportOrExternCrate::Import(import)) => { | ||||
|                                     ImportOrDef::Import(import) | ||||
|                                 } | ||||
|                                 Some(ImportOrExternCrate::ExternCrate(import)) => { | ||||
|                                     ImportOrDef::ExternCrate(import) | ||||
|                                 } | ||||
|                                 None => ImportOrDef::Def(fld.def), | ||||
|                             }, | ||||
|                         ); | ||||
|                         self.use_imports_types | ||||
|                             .insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into)); | ||||
|                     } | ||||
|                     entry.insert(fld); | ||||
|                     changed = true; | ||||
|  | @ -552,28 +591,12 @@ impl ItemScope { | |||
|                         } | ||||
|                         _ => { | ||||
|                             if glob_imports.types.remove(&lookup) { | ||||
|                                 let import = match import { | ||||
|                                     Some(ImportType::ExternCrate(extern_crate)) => { | ||||
|                                         Some(ImportOrExternCrate::ExternCrate(extern_crate)) | ||||
|                                     } | ||||
|                                     Some(ImportType::Import(import)) => { | ||||
|                                         Some(ImportOrExternCrate::Import(import)) | ||||
|                                     } | ||||
|                                     None | Some(ImportType::Glob(_)) => None, | ||||
|                                 }; | ||||
|                                 let import = import.map(Into::into); | ||||
|                                 let prev = std::mem::replace(&mut fld.import, import); | ||||
|                                 if let Some(import) = import { | ||||
|                                     self.use_imports_types.insert( | ||||
|                                         import, | ||||
|                                         match prev { | ||||
|                                             Some(ImportOrExternCrate::Import(import)) => { | ||||
|                                                 ImportOrDef::Import(import) | ||||
|                                             } | ||||
|                                             Some(ImportOrExternCrate::ExternCrate(import)) => { | ||||
|                                                 ImportOrDef::ExternCrate(import) | ||||
|                                             } | ||||
|                                             None => ImportOrDef::Def(fld.def), | ||||
|                                         }, | ||||
|                                         prev.map_or(ImportOrDef::Def(fld.def), Into::into), | ||||
|                                     ); | ||||
|                                 } | ||||
|                                 cov_mark::hit!(import_shadowed); | ||||
|  | @ -597,18 +620,14 @@ impl ItemScope { | |||
|                         _ => _ = glob_imports.values.remove(&lookup), | ||||
|                     } | ||||
|                     let import = match import { | ||||
|                         Some(ImportType::Import(import)) => Some(import), | ||||
|                         Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)), | ||||
|                         Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)), | ||||
|                         _ => None, | ||||
|                     }; | ||||
|                     let prev = std::mem::replace(&mut fld.import, import); | ||||
|                     if let Some(import) = import { | ||||
|                         self.use_imports_values.insert( | ||||
|                             import, | ||||
|                             match prev { | ||||
|                                 Some(import) => ImportOrDef::Import(import), | ||||
|                                 None => ImportOrDef::Def(fld.def), | ||||
|                             }, | ||||
|                         ); | ||||
|                         self.use_imports_values | ||||
|                             .insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into)); | ||||
|                     } | ||||
|                     entry.insert(fld); | ||||
|                     changed = true; | ||||
|  | @ -616,19 +635,16 @@ impl ItemScope { | |||
|                 Entry::Occupied(mut entry) if !matches!(import, Some(ImportType::Glob(..))) => { | ||||
|                     if glob_imports.values.remove(&lookup) { | ||||
|                         cov_mark::hit!(import_shadowed); | ||||
| 
 | ||||
|                         let import = match import { | ||||
|                             Some(ImportType::Import(import)) => Some(import), | ||||
|                             Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)), | ||||
|                             Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)), | ||||
|                             _ => None, | ||||
|                         }; | ||||
|                         let prev = std::mem::replace(&mut fld.import, import); | ||||
|                         if let Some(import) = import { | ||||
|                             self.use_imports_values.insert( | ||||
|                                 import, | ||||
|                                 match prev { | ||||
|                                     Some(import) => ImportOrDef::Import(import), | ||||
|                                     None => ImportOrDef::Def(fld.def), | ||||
|                                 }, | ||||
|                             ); | ||||
|                             self.use_imports_values | ||||
|                                 .insert(import, prev.map_or(ImportOrDef::Def(fld.def), Into::into)); | ||||
|                         } | ||||
|                         entry.insert(fld); | ||||
|                         changed = true; | ||||
|  | @ -649,17 +665,15 @@ impl ItemScope { | |||
|                         _ => _ = glob_imports.macros.remove(&lookup), | ||||
|                     } | ||||
|                     let import = match import { | ||||
|                         Some(ImportType::Import(import)) => Some(import), | ||||
|                         Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)), | ||||
|                         Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)), | ||||
|                         _ => None, | ||||
|                     }; | ||||
|                     let prev = std::mem::replace(&mut fld.import, import); | ||||
|                     if let Some(import) = import { | ||||
|                         self.use_imports_macros.insert( | ||||
|                             import, | ||||
|                             match prev { | ||||
|                                 Some(import) => ImportOrDef::Import(import), | ||||
|                                 None => ImportOrDef::Def(fld.def.into()), | ||||
|                             }, | ||||
|                             prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into), | ||||
|                         ); | ||||
|                     } | ||||
|                     entry.insert(fld); | ||||
|  | @ -669,17 +683,15 @@ impl ItemScope { | |||
|                     if glob_imports.macros.remove(&lookup) { | ||||
|                         cov_mark::hit!(import_shadowed); | ||||
|                         let import = match import { | ||||
|                             Some(ImportType::Import(import)) => Some(import), | ||||
|                             Some(ImportType::Import(import)) => Some(ImportOrGlob::Import(import)), | ||||
|                             Some(ImportType::Glob(u)) => Some(ImportOrGlob::Glob(u)), | ||||
|                             _ => None, | ||||
|                         }; | ||||
|                         let prev = std::mem::replace(&mut fld.import, import); | ||||
|                         if let Some(import) = import { | ||||
|                             self.use_imports_macros.insert( | ||||
|                                 import, | ||||
|                                 match prev { | ||||
|                                     Some(import) => ImportOrDef::Import(import), | ||||
|                                     None => ImportOrDef::Def(fld.def.into()), | ||||
|                                 }, | ||||
|                                 prev.map_or_else(|| ImportOrDef::Def(fld.def.into()), Into::into), | ||||
|                             ); | ||||
|                         } | ||||
|                         entry.insert(fld); | ||||
|  | @ -704,16 +716,27 @@ impl ItemScope { | |||
|             .map(|def| &mut def.vis) | ||||
|             .chain(self.values.values_mut().map(|def| &mut def.vis)) | ||||
|             .chain(self.unnamed_trait_imports.values_mut().map(|def| &mut def.vis)) | ||||
|             .for_each(|vis| { | ||||
|                 *vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit) | ||||
|             .for_each(|vis| match vis { | ||||
|                 &mut Visibility::Module(_, visibility_explicitness) => { | ||||
|                     *vis = Visibility::Module(this_module, visibility_explicitness) | ||||
|                 } | ||||
|                 Visibility::Public => { | ||||
|                     *vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit) | ||||
|                 } | ||||
|             }); | ||||
| 
 | ||||
|         for mac in self.macros.values_mut() { | ||||
|             if matches!(mac.def, MacroId::ProcMacroId(_) if mac.import.is_none()) { | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             mac.vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit); | ||||
|             match mac.vis { | ||||
|                 Visibility::Module(_, visibility_explicitness) => { | ||||
|                     mac.vis = Visibility::Module(this_module, visibility_explicitness) | ||||
|                 } | ||||
|                 Visibility::Public => { | ||||
|                     mac.vis = Visibility::Module(this_module, VisibilityExplicitness::Implicit) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -732,20 +755,25 @@ impl ItemScope { | |||
|                 buf.push_str(" t"); | ||||
|                 match import { | ||||
|                     Some(ImportOrExternCrate::Import(_)) => buf.push('i'), | ||||
|                     Some(ImportOrExternCrate::Glob(_)) => buf.push('g'), | ||||
|                     Some(ImportOrExternCrate::ExternCrate(_)) => buf.push('e'), | ||||
|                     None => (), | ||||
|                 } | ||||
|             } | ||||
|             if let Some(Item { import, .. }) = def.values { | ||||
|                 buf.push_str(" v"); | ||||
|                 if import.is_some() { | ||||
|                     buf.push('i'); | ||||
|                 match import { | ||||
|                     Some(ImportOrGlob::Import(_)) => buf.push('i'), | ||||
|                     Some(ImportOrGlob::Glob(_)) => buf.push('g'), | ||||
|                     None => (), | ||||
|                 } | ||||
|             } | ||||
|             if let Some(Item { import, .. }) = def.macros { | ||||
|                 buf.push_str(" m"); | ||||
|                 if import.is_some() { | ||||
|                     buf.push('i'); | ||||
|                 match import { | ||||
|                     Some(ImportOrGlob::Import(_)) => buf.push('i'), | ||||
|                     Some(ImportOrGlob::Glob(_)) => buf.push('g'), | ||||
|                     None => (), | ||||
|                 } | ||||
|             } | ||||
|             if def.is_none() { | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ use triomphe::Arc; | |||
| use crate::{ | ||||
|     attr::Attrs, | ||||
|     db::DefDatabase, | ||||
|     item_scope::{ImportId, ImportOrExternCrate, ImportType, PerNsGlobImports}, | ||||
|     item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ImportType, PerNsGlobImports}, | ||||
|     item_tree::{ | ||||
|         self, AttrOwner, FieldsShape, FileItemTreeId, ImportKind, ItemTree, ItemTreeId, | ||||
|         ItemTreeNode, Macro2, MacroCall, MacroRules, Mod, ModItem, ModKind, TreeId, UseTreeKind, | ||||
|  | @ -527,7 +527,10 @@ impl DefCollector<'_> { | |||
|                 // FIXME: This should specifically look for a glob import somehow and record that here
 | ||||
|                 self.def_map.prelude = Some(( | ||||
|                     m, | ||||
|                     import.and_then(ImportOrExternCrate::into_import).map(|it| it.import), | ||||
|                     import | ||||
|                         .and_then(ImportOrExternCrate::into_import) | ||||
|                         .and_then(ImportOrGlob::into_import) | ||||
|                         .map(|it| it.import), | ||||
|                 )); | ||||
|             } | ||||
|             types => { | ||||
|  |  | |||
|  | @ -103,8 +103,8 @@ mod a { | |||
|             c: t | ||||
| 
 | ||||
|             crate::a::b::c | ||||
|             A: v | ||||
|             b: t | ||||
|             A: vg | ||||
|             b: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -256,8 +256,8 @@ pub enum Foo { Bar, Baz } | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Bar: t v | ||||
|             Baz: t v | ||||
|             Bar: tg vg | ||||
|             Baz: tg vg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -421,10 +421,10 @@ pub struct NotExported; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Exported: t v | ||||
|             PublicItem: t v | ||||
|             allowed_reexport: t | ||||
|             exported: t | ||||
|             Exported: tg vg | ||||
|             PublicItem: tg vg | ||||
|             allowed_reexport: tg | ||||
|             exported: tg | ||||
|             not_allowed_reexport1: _ | ||||
|             not_allowed_reexport2: _ | ||||
|         "#]],
 | ||||
|  | @ -692,7 +692,7 @@ mod b { | |||
|             b: t | ||||
| 
 | ||||
|             crate::a | ||||
|             T: t v | ||||
|             T: t vg | ||||
| 
 | ||||
|             crate::b | ||||
|             T: v | ||||
|  |  | |||
|  | @ -18,9 +18,9 @@ pub struct Baz; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Baz: t v | ||||
|             Foo: t v | ||||
|             bar: t | ||||
|             Baz: tg vg | ||||
|             Foo: tg vg | ||||
|             bar: tg | ||||
|             foo: t | ||||
| 
 | ||||
|             crate::foo | ||||
|  | @ -53,20 +53,20 @@ pub use super::*; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Baz: t v | ||||
|             Foo: t v | ||||
|             bar: t | ||||
|             Baz: tg vg | ||||
|             Foo: tg vg | ||||
|             bar: tg | ||||
|             foo: t | ||||
| 
 | ||||
|             crate::foo | ||||
|             Baz: t v | ||||
|             Baz: tg vg | ||||
|             Foo: t v | ||||
|             bar: t | ||||
| 
 | ||||
|             crate::foo::bar | ||||
|             Baz: t v | ||||
|             Foo: t v | ||||
|             bar: t | ||||
|             Foo: tg vg | ||||
|             bar: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -91,20 +91,20 @@ pub use super::*; | |||
| ",
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Baz: t v | ||||
|             bar: t | ||||
|             Baz: tg vg | ||||
|             bar: tg | ||||
|             foo: t | ||||
| 
 | ||||
|             crate::foo | ||||
|             Baz: t v | ||||
|             Baz: tg vg | ||||
|             PrivateStructFoo: t v | ||||
|             bar: t | ||||
| 
 | ||||
|             crate::foo::bar | ||||
|             Baz: t v | ||||
|             PrivateStructBar: t v | ||||
|             PrivateStructFoo: t v | ||||
|             bar: t | ||||
|             PrivateStructFoo: tg vg | ||||
|             bar: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -130,9 +130,9 @@ pub(crate) struct PubCrateStruct; | |||
| ",
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Foo: t | ||||
|             PubCrateStruct: t v | ||||
|             bar: t | ||||
|             Foo: tg | ||||
|             PubCrateStruct: tg vg | ||||
|             bar: tg | ||||
|             foo: t | ||||
| 
 | ||||
|             crate::foo | ||||
|  | @ -160,7 +160,7 @@ pub struct Baz; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Baz: t v | ||||
|             Baz: tg vg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -178,7 +178,7 @@ struct Foo; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Baz: t v | ||||
|             Baz: tg vg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -193,8 +193,8 @@ use self::Foo::*; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Bar: t v | ||||
|             Baz: t v | ||||
|             Bar: tg vg | ||||
|             Baz: tg vg | ||||
|             Foo: t | ||||
|         "#]],
 | ||||
|     ); | ||||
|  | @ -210,8 +210,8 @@ use self::Foo::{*}; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Bar: t v | ||||
|             Baz: t v | ||||
|             Bar: tg vg | ||||
|             Baz: tg vg | ||||
|             Foo: t | ||||
|         "#]],
 | ||||
|     ); | ||||
|  | @ -359,7 +359,7 @@ use event::Event; | |||
|             event: t | ||||
| 
 | ||||
|             crate::event | ||||
|             Event: t v | ||||
|             Event: t vg | ||||
|             serenity: t | ||||
| 
 | ||||
|             crate::event::serenity | ||||
|  | @ -388,10 +388,10 @@ use reexport::*; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Trait: t | ||||
|             Trait: tg | ||||
|             defs: t | ||||
|             function: v | ||||
|             makro: m | ||||
|             function: vg | ||||
|             makro: mg | ||||
|             reexport: t | ||||
| 
 | ||||
|             crate::defs | ||||
|  | @ -400,10 +400,10 @@ use reexport::*; | |||
|             makro: m | ||||
| 
 | ||||
|             crate::reexport | ||||
|             Trait: t | ||||
|             function: v | ||||
|             Trait: tg | ||||
|             function: vg | ||||
|             inner: t | ||||
|             makro: m | ||||
|             makro: mg | ||||
| 
 | ||||
|             crate::reexport::inner | ||||
|             Trait: ti | ||||
|  | @ -442,12 +442,12 @@ mod glob_target { | |||
|             ShouldBePrivate: t v | ||||
| 
 | ||||
|             crate::outer | ||||
|             ShouldBePrivate: t v | ||||
|             ShouldBePrivate: tg vg | ||||
|             inner_superglob: t | ||||
| 
 | ||||
|             crate::outer::inner_superglob | ||||
|             ShouldBePrivate: t v | ||||
|             inner_superglob: t | ||||
|             ShouldBePrivate: tg vg | ||||
|             inner_superglob: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -473,20 +473,20 @@ use reexport_2::*; | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Placeholder: t v | ||||
|             Placeholder: tg vg | ||||
|             libs: t | ||||
|             reexport_1: t | ||||
|             reexport_1: tg | ||||
|             reexport_2: t | ||||
| 
 | ||||
|             crate::libs | ||||
|             Placeholder: t v | ||||
| 
 | ||||
|             crate::reexport_2 | ||||
|             Placeholder: t v | ||||
|             Placeholder: tg vg | ||||
|             reexport_1: t | ||||
| 
 | ||||
|             crate::reexport_2::reexport_1 | ||||
|             Placeholder: t v | ||||
|             Placeholder: tg vg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  |  | |||
|  | @ -97,9 +97,9 @@ macro_rules! structs { | |||
|             bar: t | ||||
| 
 | ||||
|             crate::bar | ||||
|             Bar: t | ||||
|             Foo: t | ||||
|             bar: t | ||||
|             Bar: tg | ||||
|             Foo: tg | ||||
|             bar: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -130,9 +130,9 @@ macro_rules! structs { | |||
|             bar: t | ||||
| 
 | ||||
|             crate::bar | ||||
|             Bar: t | ||||
|             Foo: t | ||||
|             bar: t | ||||
|             Bar: tg | ||||
|             Foo: tg | ||||
|             bar: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -169,9 +169,9 @@ macro_rules! inner { | |||
|             bar: t | ||||
| 
 | ||||
|             crate::bar | ||||
|             Bar: t | ||||
|             Foo: t | ||||
|             bar: t | ||||
|             Bar: tg | ||||
|             Foo: tg | ||||
|             bar: tg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -794,7 +794,7 @@ pub trait Clone {} | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             Clone: t m | ||||
|             Clone: tg mg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  | @ -1075,9 +1075,9 @@ macro_rules! mbe { | |||
| "#,
 | ||||
|         expect![[r#" | ||||
|             crate | ||||
|             DummyTrait: m | ||||
|             attribute_macro: m | ||||
|             function_like_macro: m | ||||
|             DummyTrait: mg | ||||
|             attribute_macro: mg | ||||
|             function_like_macro: mg | ||||
|         "#]],
 | ||||
|     ); | ||||
| } | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ | |||
| use bitflags::bitflags; | ||||
| 
 | ||||
| use crate::{ | ||||
|     item_scope::{ImportId, ImportOrExternCrate, ItemInNs}, | ||||
|     item_scope::{ImportId, ImportOrExternCrate, ImportOrGlob, ItemInNs}, | ||||
|     visibility::Visibility, | ||||
|     MacroId, ModuleDefId, | ||||
| }; | ||||
|  | @ -36,8 +36,8 @@ pub struct Item<Def, Import = ImportId> { | |||
| } | ||||
| 
 | ||||
| pub type TypesItem = Item<ModuleDefId, ImportOrExternCrate>; | ||||
| pub type ValuesItem = Item<ModuleDefId>; | ||||
| pub type MacrosItem = Item<MacroId>; | ||||
| pub type ValuesItem = Item<ModuleDefId, ImportOrGlob>; | ||||
| pub type MacrosItem = Item<MacroId, ImportOrGlob>; | ||||
| 
 | ||||
| #[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)] | ||||
| pub struct PerNs { | ||||
|  | @ -59,7 +59,7 @@ impl PerNs { | |||
|         PerNs { types: None, values: None, macros: None } | ||||
|     } | ||||
| 
 | ||||
|     pub fn values(def: ModuleDefId, vis: Visibility, import: Option<ImportId>) -> PerNs { | ||||
|     pub fn values(def: ModuleDefId, vis: Visibility, import: Option<ImportOrGlob>) -> PerNs { | ||||
|         PerNs { types: None, values: Some(Item { def, vis, import }), macros: None } | ||||
|     } | ||||
| 
 | ||||
|  | @ -84,7 +84,7 @@ impl PerNs { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub fn macros(def: MacroId, vis: Visibility, import: Option<ImportId>) -> PerNs { | ||||
|     pub fn macros(def: MacroId, vis: Visibility, import: Option<ImportOrGlob>) -> PerNs { | ||||
|         PerNs { types: None, values: None, macros: Some(Item { def, vis, import }) } | ||||
|     } | ||||
| 
 | ||||
|  | @ -108,7 +108,7 @@ impl PerNs { | |||
|         self.values.map(|it| it.def) | ||||
|     } | ||||
| 
 | ||||
|     pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportId>)> { | ||||
|     pub fn take_values_import(self) -> Option<(ModuleDefId, Option<ImportOrGlob>)> { | ||||
|         self.values.map(|it| (it.def, it.import)) | ||||
|     } | ||||
| 
 | ||||
|  | @ -116,7 +116,7 @@ impl PerNs { | |||
|         self.macros.map(|it| it.def) | ||||
|     } | ||||
| 
 | ||||
|     pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportId>)> { | ||||
|     pub fn take_macros_import(self) -> Option<(MacroId, Option<ImportOrGlob>)> { | ||||
|         self.macros.map(|it| (it.def, it.import)) | ||||
|     } | ||||
| 
 | ||||
|  | @ -159,14 +159,12 @@ impl PerNs { | |||
|             .map(|it| (ItemInNs::Types(it.def), it.import)) | ||||
|             .into_iter() | ||||
|             .chain( | ||||
|                 self.values.map(|it| { | ||||
|                     (ItemInNs::Values(it.def), it.import.map(ImportOrExternCrate::Import)) | ||||
|                 }), | ||||
|                 self.values | ||||
|                     .map(|it| (ItemInNs::Values(it.def), it.import.map(ImportOrExternCrate::from))), | ||||
|             ) | ||||
|             .chain( | ||||
|                 self.macros.map(|it| { | ||||
|                     (ItemInNs::Macros(it.def), it.import.map(ImportOrExternCrate::Import)) | ||||
|                 }), | ||||
|                 self.macros | ||||
|                     .map(|it| (ItemInNs::Macros(it.def), it.import.map(ImportOrExternCrate::from))), | ||||
|             ) | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ use crate::{ | |||
|     db::DefDatabase, | ||||
|     generics::{GenericParams, TypeOrConstParamData}, | ||||
|     hir::{BindingId, ExprId, LabelId}, | ||||
|     item_scope::{BuiltinShadowMode, ImportId, ImportOrExternCrate, BUILTIN_SCOPE}, | ||||
|     item_scope::{BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob, BUILTIN_SCOPE}, | ||||
|     lang_item::LangItemTarget, | ||||
|     nameres::{DefMap, MacroSubNs, ResolvePathResultPrefixInfo}, | ||||
|     path::{ModPath, Path, PathKind}, | ||||
|  | @ -107,7 +107,7 @@ pub enum TypeNs { | |||
| 
 | ||||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||||
| pub enum ResolveValueResult { | ||||
|     ValueNs(ValueNs, Option<ImportId>), | ||||
|     ValueNs(ValueNs, Option<ImportOrGlob>), | ||||
|     Partial(TypeNs, usize, Option<ImportOrExternCrate>), | ||||
| } | ||||
| 
 | ||||
|  | @ -485,7 +485,7 @@ impl Resolver { | |||
|         db: &dyn DefDatabase, | ||||
|         path: &ModPath, | ||||
|         expected_macro_kind: Option<MacroSubNs>, | ||||
|     ) -> Option<(MacroId, Option<ImportId>)> { | ||||
|     ) -> Option<(MacroId, Option<ImportOrGlob>)> { | ||||
|         let (item_map, module) = self.item_scope(); | ||||
|         item_map | ||||
|             .resolve_path(db, module, path, BuiltinShadowMode::Other, expected_macro_kind) | ||||
|  | @ -1014,7 +1014,7 @@ impl ModuleItemMap { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportId>)> { | ||||
| fn to_value_ns(per_ns: PerNs) -> Option<(ValueNs, Option<ImportOrGlob>)> { | ||||
|     let (def, import) = per_ns.take_values_import()?; | ||||
|     let res = match def { | ||||
|         ModuleDefId::FunctionId(it) => ValueNs::FunctionId(it), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth