Skip to content

Drop the expander borrow in all control flow paths #13154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ impl<'a> TyLoweringContext<'a> {
TypeRef::Macro(macro_call) => {
let (mut expander, recursion_start) = {
match RefMut::filter_map(self.expander.borrow_mut(), Option::as_mut) {
// There already is an expander here, this means we are already recursing
Ok(expander) => (expander, false),
// No expander was created yet, so we are at the start of the expansion recursion
// and therefore have to create an expander.
Err(expander) => (
RefMut::map(expander, |it| {
it.insert(Expander::new(
Expand Down Expand Up @@ -362,9 +365,14 @@ impl<'a> TyLoweringContext<'a> {
.exit(self.db.upcast(), mark);
Some(ty)
}
_ => None,
_ => {
drop(expander);
None
}
}
};

// drop the expander, resetting it to pre-recursion state
if recursion_start {
*self.expander.borrow_mut() = None;
}
Expand Down