Skip to content

Commit 2c8bf0b

Browse files
committed
ir: Move a variable to where it's used.
1 parent 9f7eaa9 commit 2c8bf0b

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/ir/context.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,31 +2315,36 @@ If you encounter an error missing from this list, please file an issue or a PR!"
23152315
return true;
23162316
}
23172317

2318+
// Unnamed top-level enums are special and we
2319+
// whitelist them via the `whitelisted_vars` filter,
2320+
// since they're effectively top-level constants,
2321+
// and there's no way for them to be referenced
2322+
// consistently.
23182323
let parent = self.resolve_item(item.parent_id());
2319-
if parent.is_module() {
2320-
let mut prefix_path = parent.path_for_whitelisting(self);
2321-
2322-
// Unnamed top-level enums are special and we
2323-
// whitelist them via the `whitelisted_vars` filter,
2324-
// since they're effectively top-level constants,
2325-
// and there's no way for them to be referenced
2326-
// consistently.
2327-
if let TypeKind::Enum(ref enum_) = *ty.kind() {
2328-
if ty.name().is_none() &&
2329-
enum_.variants().iter().any(|variant| {
2330-
prefix_path.push(variant.name().into());
2331-
let name = prefix_path[1..].join("::");
2332-
prefix_path.pop().unwrap();
2333-
self.options()
2334-
.whitelisted_vars
2335-
.matches(&name)
2336-
}) {
2337-
return true;
2338-
}
2339-
}
2324+
if !parent.is_module() {
2325+
return false;
23402326
}
23412327

2342-
false
2328+
2329+
let enum_ = match *ty.kind() {
2330+
TypeKind::Enum(ref e) => e,
2331+
_ => return false,
2332+
};
2333+
2334+
if ty.name().is_some() {
2335+
return false;
2336+
}
2337+
2338+
let mut prefix_path =
2339+
parent.path_for_whitelisting(self);
2340+
enum_.variants().iter().any(|variant| {
2341+
prefix_path.push(variant.name().into());
2342+
let name = prefix_path[1..].join("::");
2343+
prefix_path.pop().unwrap();
2344+
self.options()
2345+
.whitelisted_vars
2346+
.matches(&name)
2347+
})
23432348
}
23442349
}
23452350
})

0 commit comments

Comments
 (0)