6
6
//!
7
7
//! This usually involves resolving names, collecting generic arguments etc.
8
8
use std:: {
9
- cell:: { Cell , RefCell } ,
9
+ cell:: { Cell , RefCell , RefMut } ,
10
10
iter,
11
11
sync:: Arc ,
12
12
} ;
@@ -330,26 +330,26 @@ impl<'a> TyLoweringContext<'a> {
330
330
}
331
331
}
332
332
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
+ ) ,
344
346
}
345
347
} ;
346
- let ty = if let Some ( mut expander) = expander {
347
- let expander_mut = expander. as_mut ( ) . unwrap ( ) ;
348
+ let ty = {
348
349
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) {
350
351
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 ( ) ) ;
353
353
let type_ref = TypeRef :: from_ast ( & ctx, expanded) ;
354
354
355
355
drop ( expander) ;
@@ -364,8 +364,6 @@ impl<'a> TyLoweringContext<'a> {
364
364
}
365
365
_ => None ,
366
366
}
367
- } else {
368
- None
369
367
} ;
370
368
if recursion_start {
371
369
* self . expander . borrow_mut ( ) = None ;
0 commit comments