diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-12-24 03:59:21 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-12-24 03:59:21 +0100 |
commit | 2c8bf0b1b90b513967fd4f49a9b80dd37fbd4b29 (patch) | |
tree | 08fdf52918c11384750f0432f36225b58c88036f | |
parent | 9f7eaa988bebbb1d78ee8a6b5d58cb6d94f19a7c (diff) |
ir: Move a variable to where it's used.
-rw-r--r-- | src/ir/context.rs | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index e4e828e2..f9cd53f3 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2315,31 +2315,36 @@ If you encounter an error missing from this list, please file an issue or a PR!" return true; } + // Unnamed top-level enums are special and we + // whitelist them via the `whitelisted_vars` filter, + // since they're effectively top-level constants, + // and there's no way for them to be referenced + // consistently. let parent = self.resolve_item(item.parent_id()); - if parent.is_module() { - let mut prefix_path = parent.path_for_whitelisting(self); - - // Unnamed top-level enums are special and we - // whitelist them via the `whitelisted_vars` filter, - // since they're effectively top-level constants, - // and there's no way for them to be referenced - // consistently. - if let TypeKind::Enum(ref enum_) = *ty.kind() { - if ty.name().is_none() && - enum_.variants().iter().any(|variant| { - prefix_path.push(variant.name().into()); - let name = prefix_path[1..].join("::"); - prefix_path.pop().unwrap(); - self.options() - .whitelisted_vars - .matches(&name) - }) { - return true; - } - } + if !parent.is_module() { + return false; } - false + + let enum_ = match *ty.kind() { + TypeKind::Enum(ref e) => e, + _ => return false, + }; + + if ty.name().is_some() { + return false; + } + + let mut prefix_path = + parent.path_for_whitelisting(self); + enum_.variants().iter().any(|variant| { + prefix_path.push(variant.name().into()); + let name = prefix_path[1..].join("::"); + prefix_path.pop().unwrap(); + self.options() + .whitelisted_vars + .matches(&name) + }) } } }) |