diff options
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/expr.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 8 | ||||
-rw-r--r-- | crates/hir_def/src/per_ns.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/resolver.rs | 12 | ||||
-rw-r--r-- | crates/hir_def/src/visibility.rs | 2 |
6 files changed, 18 insertions, 12 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 6be1eaade..3dc33f248 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -581,7 +581,7 @@ impl ExprCollector<'_> { | |||
581 | match res.value { | 581 | match res.value { |
582 | Some((mark, expansion)) => { | 582 | Some((mark, expansion)) => { |
583 | // FIXME: Statements are too complicated to recover from error for now. | 583 | // FIXME: Statements are too complicated to recover from error for now. |
584 | // It is because we don't have any hygenine for local variable expansion right now. | 584 | // It is because we don't have any hygiene for local variable expansion right now. |
585 | if T::can_cast(syntax::SyntaxKind::MACRO_STMTS) && res.err.is_some() { | 585 | if T::can_cast(syntax::SyntaxKind::MACRO_STMTS) && res.err.is_some() { |
586 | self.expander.exit(self.db, mark); | 586 | self.expander.exit(self.db, mark); |
587 | collector(self, None); | 587 | collector(self, None); |
@@ -959,7 +959,7 @@ impl ExprCollector<'_> { | |||
959 | 959 | ||
960 | fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) { | 960 | fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) { |
961 | // Find the location of the `..`, if there is one. Note that we do not | 961 | // Find the location of the `..`, if there is one. Note that we do not |
962 | // consider the possiblity of there being multiple `..` here. | 962 | // consider the possibility of there being multiple `..` here. |
963 | let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::RestPat(_))); | 963 | let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::RestPat(_))); |
964 | // We want to skip the `..` pattern here, since we account for it above. | 964 | // We want to skip the `..` pattern here, since we account for it above. |
965 | let args = args | 965 | let args = args |
diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index 6a481769d..76f5721e5 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! This module describes hir-level representation of expressions. | 1 | //! This module describes hir-level representation of expressions. |
2 | //! | 2 | //! |
3 | //! This representaion is: | 3 | //! This representation is: |
4 | //! | 4 | //! |
5 | //! 1. Identity-based. Each expression has an `id`, so we can distinguish | 5 | //! 1. Identity-based. Each expression has an `id`, so we can distinguish |
6 | //! between different `1` in `1 + 1`. | 6 | //! between different `1` in `1 + 1`. |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 77017e4ea..f027fd48d 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -267,7 +267,7 @@ impl DefCollector<'_> { | |||
267 | 267 | ||
268 | // Resolve all indeterminate resolved imports again | 268 | // Resolve all indeterminate resolved imports again |
269 | // As some of the macros will expand newly import shadowing partial resolved imports | 269 | // As some of the macros will expand newly import shadowing partial resolved imports |
270 | // FIXME: We maybe could skip this, if we handle the Indetermine imports in `resolve_imports` | 270 | // FIXME: We maybe could skip this, if we handle the indeterminate imports in `resolve_imports` |
271 | // correctly | 271 | // correctly |
272 | let partial_resolved = self.resolved_imports.iter().filter_map(|directive| { | 272 | let partial_resolved = self.resolved_imports.iter().filter_map(|directive| { |
273 | if let PartialResolvedImport::Indeterminate(_) = directive.status { | 273 | if let PartialResolvedImport::Indeterminate(_) = directive.status { |
@@ -402,7 +402,7 @@ impl DefCollector<'_> { | |||
402 | 402 | ||
403 | /// Define a proc macro | 403 | /// Define a proc macro |
404 | /// | 404 | /// |
405 | /// A proc macro is similar to normal macro scope, but it would not visiable in legacy textual scoped. | 405 | /// A proc macro is similar to normal macro scope, but it would not visible in legacy textual scoped. |
406 | /// And unconditionally exported. | 406 | /// And unconditionally exported. |
407 | fn define_proc_macro(&mut self, name: Name, macro_: MacroDefId) { | 407 | fn define_proc_macro(&mut self, name: Name, macro_: MacroDefId) { |
408 | self.update( | 408 | self.update( |
@@ -592,7 +592,7 @@ impl DefCollector<'_> { | |||
592 | // XXX: urgh, so this works by accident! Here, we look at | 592 | // XXX: urgh, so this works by accident! Here, we look at |
593 | // the enum data, and, in theory, this might require us to | 593 | // the enum data, and, in theory, this might require us to |
594 | // look back at the crate_def_map, creating a cycle. For | 594 | // look back at the crate_def_map, creating a cycle. For |
595 | // example, `enum E { crate::some_macro!(); }`. Luckely, the | 595 | // example, `enum E { crate::some_macro!(); }`. Luckily, the |
596 | // only kind of macro that is allowed inside enum is a | 596 | // only kind of macro that is allowed inside enum is a |
597 | // `cfg_macro`, and we don't need to run name resolution for | 597 | // `cfg_macro`, and we don't need to run name resolution for |
598 | // it, but this is sheer luck! | 598 | // it, but this is sheer luck! |
@@ -655,7 +655,7 @@ impl DefCollector<'_> { | |||
655 | &mut self, | 655 | &mut self, |
656 | module_id: LocalModuleId, | 656 | module_id: LocalModuleId, |
657 | resolutions: &[(Option<Name>, PerNs)], | 657 | resolutions: &[(Option<Name>, PerNs)], |
658 | // All resolutions are imported with this visibility; the visibilies in | 658 | // All resolutions are imported with this visibility; the visibilities in |
659 | // the `PerNs` values are ignored and overwritten | 659 | // the `PerNs` values are ignored and overwritten |
660 | vis: Visibility, | 660 | vis: Visibility, |
661 | import_type: ImportType, | 661 | import_type: ImportType, |
diff --git a/crates/hir_def/src/per_ns.rs b/crates/hir_def/src/per_ns.rs index 74665c588..a594afce6 100644 --- a/crates/hir_def/src/per_ns.rs +++ b/crates/hir_def/src/per_ns.rs | |||
@@ -7,7 +7,7 @@ use hir_expand::MacroDefId; | |||
7 | 7 | ||
8 | use crate::{item_scope::ItemInNs, visibility::Visibility, ModuleDefId}; | 8 | use crate::{item_scope::ItemInNs, visibility::Visibility, ModuleDefId}; |
9 | 9 | ||
10 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 10 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
11 | pub struct PerNs { | 11 | pub struct PerNs { |
12 | pub types: Option<(ModuleDefId, Visibility)>, | 12 | pub types: Option<(ModuleDefId, Visibility)>, |
13 | pub values: Option<(ModuleDefId, Visibility)>, | 13 | pub values: Option<(ModuleDefId, Visibility)>, |
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 129f1dbac..61059c349 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs | |||
@@ -27,7 +27,7 @@ use crate::{ | |||
27 | 27 | ||
28 | #[derive(Debug, Clone, Default)] | 28 | #[derive(Debug, Clone, Default)] |
29 | pub struct Resolver { | 29 | pub struct Resolver { |
30 | // FIXME: all usages generally call `.rev`, so maybe reverse once in consturciton? | 30 | // FIXME: all usages generally call `.rev`, so maybe reverse once in construction? |
31 | scopes: Vec<Scope>, | 31 | scopes: Vec<Scope>, |
32 | } | 32 | } |
33 | 33 | ||
@@ -490,6 +490,7 @@ pub enum ScopeDef { | |||
490 | 490 | ||
491 | impl Scope { | 491 | impl Scope { |
492 | fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { | 492 | fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { |
493 | let mut seen = FxHashSet::default(); | ||
493 | match self { | 494 | match self { |
494 | Scope::ModuleScope(m) => { | 495 | Scope::ModuleScope(m) => { |
495 | // FIXME: should we provide `self` here? | 496 | // FIXME: should we provide `self` here? |
@@ -503,7 +504,9 @@ impl Scope { | |||
503 | f(name.clone(), ScopeDef::PerNs(def)); | 504 | f(name.clone(), ScopeDef::PerNs(def)); |
504 | }); | 505 | }); |
505 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { | 506 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { |
506 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); | 507 | let scope = PerNs::macros(macro_, Visibility::Public); |
508 | seen.insert((name.clone(), scope)); | ||
509 | f(name.clone(), ScopeDef::PerNs(scope)); | ||
507 | }); | 510 | }); |
508 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { | 511 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { |
509 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); | 512 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); |
@@ -514,7 +517,10 @@ impl Scope { | |||
514 | if let Some(prelude) = m.crate_def_map.prelude { | 517 | if let Some(prelude) = m.crate_def_map.prelude { |
515 | let prelude_def_map = db.crate_def_map(prelude.krate); | 518 | let prelude_def_map = db.crate_def_map(prelude.krate); |
516 | prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { | 519 | prelude_def_map[prelude.local_id].scope.entries().for_each(|(name, def)| { |
517 | f(name.clone(), ScopeDef::PerNs(def)); | 520 | let seen_tuple = (name.clone(), def); |
521 | if !seen.contains(&seen_tuple) { | ||
522 | f(seen_tuple.0, ScopeDef::PerNs(def)); | ||
523 | } | ||
518 | }); | 524 | }); |
519 | } | 525 | } |
520 | } | 526 | } |
diff --git a/crates/hir_def/src/visibility.rs b/crates/hir_def/src/visibility.rs index e6e0853a3..f3bc9d680 100644 --- a/crates/hir_def/src/visibility.rs +++ b/crates/hir_def/src/visibility.rs | |||
@@ -85,7 +85,7 @@ impl RawVisibility { | |||
85 | } | 85 | } |
86 | 86 | ||
87 | /// Visibility of an item, with the path resolved. | 87 | /// Visibility of an item, with the path resolved. |
88 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] | 88 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
89 | pub enum Visibility { | 89 | pub enum Visibility { |
90 | /// Visibility is restricted to a certain module. | 90 | /// Visibility is restricted to a certain module. |
91 | Module(ModuleId), | 91 | Module(ModuleId), |