Skip to content

Commit ca4e10b

Browse files
committed
Auto merge of #13123 - Veykril:simplify, r=Veykril
minor: Simplify
2 parents 55bf51d + 78a7a81 commit ca4e10b

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

crates/hir-ty/src/lower.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! This usually involves resolving names, collecting generic arguments etc.
88
use std::{
9-
cell::{Cell, RefCell},
9+
cell::{Cell, RefCell, RefMut},
1010
iter,
1111
sync::Arc,
1212
};
@@ -330,26 +330,26 @@ impl<'a> TyLoweringContext<'a> {
330330
}
331331
}
332332
TypeRef::Macro(macro_call) => {
333-
let (expander, recursion_start) = {
334-
let mut expander = self.expander.borrow_mut();
335-
if expander.is_some() {
336-
(Some(expander), false)
337-
} else {
338-
*expander = Some(Expander::new(
339-
self.db.upcast(),
340-
macro_call.file_id,
341-
self.resolver.module(),
342-
));
343-
(Some(expander), true)
333+
let (mut expander, recursion_start) = {
334+
match RefMut::filter_map(self.expander.borrow_mut(), Option::as_mut) {
335+
Ok(expander) => (expander, false),
336+
Err(expander) => (
337+
RefMut::map(expander, |it| {
338+
it.insert(Expander::new(
339+
self.db.upcast(),
340+
macro_call.file_id,
341+
self.resolver.module(),
342+
))
343+
}),
344+
true,
345+
),
344346
}
345347
};
346-
let ty = if let Some(mut expander) = expander {
347-
let expander_mut = expander.as_mut().unwrap();
348+
let ty = {
348349
let macro_call = macro_call.to_node(self.db.upcast());
349-
match expander_mut.enter_expand::<ast::Type>(self.db.upcast(), macro_call) {
350+
match expander.enter_expand::<ast::Type>(self.db.upcast(), macro_call) {
350351
Ok(ExpandResult { value: Some((mark, expanded)), .. }) => {
351-
let ctx =
352-
LowerCtx::new(self.db.upcast(), expander_mut.current_file_id());
352+
let ctx = LowerCtx::new(self.db.upcast(), expander.current_file_id());
353353
let type_ref = TypeRef::from_ast(&ctx, expanded);
354354

355355
drop(expander);
@@ -364,8 +364,6 @@ impl<'a> TyLoweringContext<'a> {
364364
}
365365
_ => None,
366366
}
367-
} else {
368-
None
369367
};
370368
if recursion_start {
371369
*self.expander.borrow_mut() = None;

0 commit comments

Comments
 (0)