Skip to content

Commit 6d27d42

Browse files
committed
fmt
1 parent 5827f6a commit 6d27d42

File tree

18 files changed

+89
-203
lines changed

18 files changed

+89
-203
lines changed

Diff for: crates/base-db/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use salsa::{Durability, Setter};
2121
pub use semver::{BuildMetadata, Prerelease, Version, VersionReq};
2222
use syntax::{ast, Parse, SyntaxError};
2323
use triomphe::Arc;
24-
pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, VfsPath, FileId};
24+
pub use vfs::{file_set::FileSet, AnchoredPath, AnchoredPathBuf, FileId, VfsPath};
2525

2626
#[macro_export]
2727
macro_rules! impl_intern_key {

Diff for: crates/hir-expand/src/db.rs

+49-128
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ use syntax_bridge::{syntax_node_to_token_tree, DocCommentDesugarMode};
1414
use triomphe::Arc;
1515

1616
use crate::{
17-
EagerCallInfo,
18-
attrs::{AttrId, collect_attrs},
17+
attrs::{collect_attrs, AttrId},
1918
builtin::pseudo_derive_attr_expansion,
2019
cfg_process,
2120
declarative::DeclarativeMacroExpander,
2221
fixup::{self, SyntaxFixupUndoInfo},
2322
hygiene::{
24-
SyntaxContextExt as _, span_with_call_site_ctxt, span_with_def_site_ctxt,
25-
span_with_mixed_site_ctxt,
23+
span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt,
24+
SyntaxContextExt as _,
2625
},
2726
proc_macro::{CustomProcMacroExpander, ProcMacros},
2827
span_map::{ExpansionSpanMap, RealSpanMap, SpanMap, SpanMapRef},
29-
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander,
28+
tt, AstId, BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallInfo,
3029
EagerExpander, ExpandError, ExpandResult, ExpandTo, MacroCallKind, MacroCallLoc, MacroDefId,
3130
MacroDefKind,
3231
};
@@ -217,14 +216,8 @@ pub fn expand_speculative(
217216
),
218217
SyntaxFixupUndoInfo::NONE,
219218
),
220-
MacroCallKind::Derive {
221-
derive_attr_index: index,
222-
..
223-
}
224-
| MacroCallKind::Attr {
225-
invoc_attr_index: index,
226-
..
227-
} => {
219+
MacroCallKind::Derive { derive_attr_index: index, .. }
220+
| MacroCallKind::Attr { invoc_attr_index: index, .. } => {
228221
let censor = if let MacroCallKind::Derive { .. } = loc.kind {
229222
censor_derive_input(index, &ast::Adt::cast(speculative_args.clone())?)
230223
} else {
@@ -264,9 +257,7 @@ pub fn expand_speculative(
264257
};
265258

266259
let attr_arg = match loc.kind {
267-
MacroCallKind::Attr {
268-
invoc_attr_index, ..
269-
} => {
260+
MacroCallKind::Attr { invoc_attr_index, .. } => {
270261
let attr = if loc.def.is_attribute_derive() {
271262
// for pseudo-derive expansion we actually pass the attribute itself only
272263
ast::Attr::cast(speculative_args.clone())
@@ -317,18 +308,17 @@ pub fn expand_speculative(
317308
pseudo_derive_attr_expansion(&tt, attr_arg.as_ref()?, span)
318309
}
319310
MacroDefKind::Declarative(it) => {
320-
db.decl_macro_expander(loc.krate, it)
321-
.expand_unhygienic(tt, span, loc.def.edition)
311+
db.decl_macro_expander(loc.krate, it).expand_unhygienic(tt, span, loc.def.edition)
312+
}
313+
MacroDefKind::BuiltIn(_, it) => {
314+
it.expand(db, actual_macro_call, &tt, span).map_err(Into::into)
315+
}
316+
MacroDefKind::BuiltInDerive(_, it) => {
317+
it.expand(db, actual_macro_call, &tt, span).map_err(Into::into)
318+
}
319+
MacroDefKind::BuiltInEager(_, it) => {
320+
it.expand(db, actual_macro_call, &tt, span).map_err(Into::into)
322321
}
323-
MacroDefKind::BuiltIn(_, it) => it
324-
.expand(db, actual_macro_call, &tt, span)
325-
.map_err(Into::into),
326-
MacroDefKind::BuiltInDerive(_, it) => it
327-
.expand(db, actual_macro_call, &tt, span)
328-
.map_err(Into::into),
329-
MacroDefKind::BuiltInEager(_, it) => it
330-
.expand(db, actual_macro_call, &tt, span)
331-
.map_err(Into::into),
332322
MacroDefKind::BuiltInAttr(_, it) => it.expand(db, actual_macro_call, &tt, span),
333323
};
334324

@@ -341,12 +331,7 @@ pub fn expand_speculative(
341331
let syntax_node = node.syntax_node();
342332
let token = rev_tmap
343333
.ranges_with_span(span_map.span_for_range(token_to_map.text_range()))
344-
.filter_map(|(range, ctx)| {
345-
syntax_node
346-
.covering_element(range)
347-
.into_token()
348-
.zip(Some(ctx))
349-
})
334+
.filter_map(|(range, ctx)| syntax_node.covering_element(range).into_token().zip(Some(ctx)))
350335
.map(|(t, ctx)| {
351336
// prefer tokens of the same kind and text, as well as non opaque marked ones
352337
// Note the inversion of the score here, as we want to prefer the first token in case
@@ -389,10 +374,8 @@ fn parse_macro_expansion(
389374
let loc = db.lookup_intern_macro_call(macro_file.macro_call_id);
390375
let def_edition = loc.def.edition;
391376
let expand_to = loc.expand_to();
392-
let mbe::ValueResult {
393-
value: (tt, matched_arm),
394-
err,
395-
} = macro_expand(db, macro_file.macro_call_id, loc);
377+
let mbe::ValueResult { value: (tt, matched_arm), err } =
378+
macro_expand(db, macro_file.macro_call_id, loc);
396379

397380
let (parse, mut rev_token_map) = token_tree_to_syntax_node(
398381
db,
@@ -405,19 +388,15 @@ fn parse_macro_expansion(
405388
);
406389
rev_token_map.matched_arm = matched_arm;
407390

408-
ExpandResult {
409-
value: (parse, Arc::new(rev_token_map)),
410-
err,
411-
}
391+
ExpandResult { value: (parse, Arc::new(rev_token_map)), err }
412392
}
413393

414394
fn parse_macro_expansion_error(
415395
db: &dyn ExpandDatabase,
416396
macro_call_id: MacroCallId,
417397
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>> {
418-
let e: ExpandResult<Arc<[SyntaxError]>> = db
419-
.parse_macro_expansion(MacroFileId { macro_call_id })
420-
.map(|it| Arc::from(it.0.errors()));
398+
let e: ExpandResult<Arc<[SyntaxError]>> =
399+
db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| Arc::from(it.0.errors()));
421400
if e.value.is_empty() && e.err.is_none() {
422401
None
423402
} else {
@@ -457,9 +436,7 @@ fn macro_arg_considering_derives(
457436
) -> MacroArgResult {
458437
match kind {
459438
// Get the macro arg for the derive macro
460-
MacroCallKind::Derive {
461-
derive_macro_id, ..
462-
} => db.macro_arg(*derive_macro_id),
439+
MacroCallKind::Derive { derive_macro_id, .. } => db.macro_arg(*derive_macro_id),
463440
// Normal macro arg
464441
_ => db.macro_arg(id),
465442
}
@@ -469,13 +446,8 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
469446
let loc = db.lookup_intern_macro_call(id);
470447

471448
if let MacroCallLoc {
472-
def: MacroDefId {
473-
kind: MacroDefKind::BuiltInEager(..),
474-
..
475-
},
476-
kind: MacroCallKind::FnLike {
477-
eager: Some(eager), ..
478-
},
449+
def: MacroDefId { kind: MacroDefKind::BuiltInEager(..), .. },
450+
kind: MacroCallKind::FnLike { eager: Some(eager), .. },
479451
..
480452
} = &loc
481453
{
@@ -488,20 +460,15 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
488460
let (censor, item_node, span) = match loc.kind {
489461
MacroCallKind::FnLike { ast_id, .. } => {
490462
let node = &ast_id.to_ptr(db).to_node(&root);
491-
let path_range = node.path().map_or_else(
492-
|| node.syntax().text_range(),
493-
|path| path.syntax().text_range(),
494-
);
463+
let path_range = node
464+
.path()
465+
.map_or_else(|| node.syntax().text_range(), |path| path.syntax().text_range());
495466
let span = map.span_for_range(path_range);
496467

497468
let dummy_tt = |kind| {
498469
(
499470
Arc::new(tt::TopSubtree::from_token_trees(
500-
tt::Delimiter {
501-
open: span,
502-
close: span,
503-
kind,
504-
},
471+
tt::Delimiter { open: span, close: span, kind },
505472
tt::TokenTreesView::new(&[]),
506473
)),
507474
SyntaxFixupUndoInfo::default(),
@@ -512,14 +479,8 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
512479
let Some(tt) = node.token_tree() else {
513480
return dummy_tt(tt::DelimiterKind::Invisible);
514481
};
515-
let first = tt
516-
.left_delimiter_token()
517-
.map(|it| it.kind())
518-
.unwrap_or(T!['(']);
519-
let last = tt
520-
.right_delimiter_token()
521-
.map(|it| it.kind())
522-
.unwrap_or(T![.]);
482+
let first = tt.left_delimiter_token().map(|it| it.kind()).unwrap_or(T!['(']);
483+
let last = tt.right_delimiter_token().map(|it| it.kind()).unwrap_or(T![.]);
523484

524485
let mismatched_delimiters = !matches!(
525486
(first, last),
@@ -564,11 +525,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
564525
MacroCallKind::Derive { .. } => {
565526
unreachable!("`ExpandDatabase::macro_arg` called with `MacroCallKind::Derive`")
566527
}
567-
MacroCallKind::Attr {
568-
ast_id,
569-
invoc_attr_index,
570-
..
571-
} => {
528+
MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
572529
let node = ast_id.to_ptr(db).to_node(&root);
573530
let attr_source = attr_source(invoc_attr_index, &node);
574531

@@ -586,14 +543,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
586543
let censor_derive_input = censor_derive_input(invoc_attr_index, &adt);
587544
(censor_derive_input, node, span)
588545
} else {
589-
(
590-
attr_source
591-
.into_iter()
592-
.map(|it| it.syntax().clone().into())
593-
.collect(),
594-
node,
595-
span,
596-
)
546+
(attr_source.into_iter().map(|it| it.syntax().clone().into()).collect(), node, span)
597547
}
598548
}
599549
};
@@ -653,9 +603,7 @@ fn censor_derive_input(derive_attr_index: AttrId, node: &ast::Adt) -> FxHashSet<
653603
fn attr_source(invoc_attr_index: AttrId, node: &ast::Item) -> Option<ast::Attr> {
654604
// FIXME: handle `cfg_attr`
655605
cov_mark::hit!(attribute_macro_attr_censoring);
656-
collect_attrs(node)
657-
.nth(invoc_attr_index.ast_index())
658-
.and_then(|(_, attr)| Either::left(attr))
606+
collect_attrs(node).nth(invoc_attr_index.ast_index()).and_then(|(_, attr)| Either::left(attr))
659607
}
660608

661609
impl TokenExpander {
@@ -685,13 +633,7 @@ fn macro_expand(
685633
) -> ExpandResult<(CowArc<tt::TopSubtree>, MatchedArmIndex)> {
686634
let _p = tracing::info_span!("macro_expand").entered();
687635

688-
let (
689-
ExpandResult {
690-
value: (tt, matched_arm),
691-
err,
692-
},
693-
span,
694-
) = match loc.def.kind {
636+
let (ExpandResult { value: (tt, matched_arm), err }, span) = match loc.def.kind {
695637
MacroDefKind::ProcMacro(..) => {
696638
return db.expand_proc_macro(macro_call_id).map(CowArc::Arc).zip_val(None);
697639
}
@@ -705,14 +647,12 @@ fn macro_expand(
705647
MacroDefKind::Declarative(id) => db
706648
.decl_macro_expander(loc.def.krate, id)
707649
.expand(db, arg.clone(), macro_call_id, span),
708-
MacroDefKind::BuiltIn(_, it) => it
709-
.expand(db, macro_call_id, arg, span)
710-
.map_err(Into::into)
711-
.zip_val(None),
712-
MacroDefKind::BuiltInDerive(_, it) => it
713-
.expand(db, macro_call_id, arg, span)
714-
.map_err(Into::into)
715-
.zip_val(None),
650+
MacroDefKind::BuiltIn(_, it) => {
651+
it.expand(db, macro_call_id, arg, span).map_err(Into::into).zip_val(None)
652+
}
653+
MacroDefKind::BuiltInDerive(_, it) => {
654+
it.expand(db, macro_call_id, arg, span).map_err(Into::into).zip_val(None)
655+
}
716656
MacroDefKind::BuiltInEager(_, it) => {
717657
// This might look a bit odd, but we do not expand the inputs to eager macros here.
718658
// Eager macros inputs are expanded, well, eagerly when we collect the macro calls.
@@ -725,9 +665,7 @@ fn macro_expand(
725665
return ExpandResult::ok(CowArc::Arc(macro_arg.clone()))
726666
.zip_val(None);
727667
}
728-
MacroCallKind::FnLike {
729-
eager: Some(eager), ..
730-
} => Some(&**eager),
668+
MacroCallKind::FnLike { eager: Some(eager), .. } => Some(&**eager),
731669
_ => None,
732670
};
733671

@@ -746,13 +684,7 @@ fn macro_expand(
746684
}
747685
MacroDefKind::ProcMacro(_, _, _) => unreachable!(),
748686
};
749-
(
750-
ExpandResult {
751-
value: res.value,
752-
err: res.err,
753-
},
754-
span,
755-
)
687+
(ExpandResult { value: res.value, err: res.err }, span)
756688
}
757689
};
758690

@@ -766,10 +698,7 @@ fn macro_expand(
766698
}
767699
}
768700

769-
ExpandResult {
770-
value: (CowArc::Owned(tt), matched_arm),
771-
err,
772-
}
701+
ExpandResult { value: (CowArc::Owned(tt), matched_arm), err }
773702
}
774703

775704
fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
@@ -778,10 +707,8 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
778707
let span_map = &db.span_map(ast.file_id);
779708

780709
let node = ast_id_map.get(ast.value).to_node(&root);
781-
let range = ast::HasName::name(&node).map_or_else(
782-
|| node.syntax().text_range(),
783-
|name| name.syntax().text_range(),
784-
);
710+
let range = ast::HasName::name(&node)
711+
.map_or_else(|| node.syntax().text_range(), |name| name.syntax().text_range());
785712
span_map.span_for_range(range)
786713
}
787714

@@ -798,10 +725,7 @@ fn expand_proc_macro(
798725
};
799726

800727
let attr_arg = match &loc.kind {
801-
MacroCallKind::Attr {
802-
attr_args: Some(attr_args),
803-
..
804-
} => Some(&**attr_args),
728+
MacroCallKind::Attr { attr_args: Some(attr_args), .. } => Some(&**attr_args),
805729
_ => None,
806730
};
807731

@@ -826,10 +750,7 @@ fn expand_proc_macro(
826750

827751
fixup::reverse_fixups(&mut tt, &undo_info);
828752

829-
ExpandResult {
830-
value: Arc::new(tt),
831-
err,
832-
}
753+
ExpandResult { value: Arc::new(tt), err }
833754
}
834755

835756
pub(crate) fn token_tree_to_syntax_node(

Diff for: crates/ide-assists/src/assist_context.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ impl<'a> AssistContext<'a> {
6565
config: &'a AssistConfig,
6666
frange: FileRange,
6767
) -> AssistContext<'a> {
68-
let editioned_file_id = ide_db::base_db::EditionedFileId::new(
69-
sema.db.as_dyn_database(),
70-
frange.file_id,
71-
);
68+
let editioned_file_id =
69+
ide_db::base_db::EditionedFileId::new(sema.db.as_dyn_database(), frange.file_id);
7270

7371
let source_file = sema.parse(editioned_file_id);
7472

Diff for: crates/ide-assists/src/handlers/extract_module.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,8 @@ impl Module {
332332
let mut use_stmts_set = FxHashSet::default();
333333

334334
for (file_id, refs) in node_def.usages(&ctx.sema).all() {
335-
let editioned_file_id = ide_db::base_db::EditionedFileId::new(
336-
ctx.sema.db.as_dyn_database(),
337-
file_id,
338-
);
335+
let editioned_file_id =
336+
ide_db::base_db::EditionedFileId::new(ctx.sema.db.as_dyn_database(), file_id);
339337

340338
let source_file = ctx.sema.parse(editioned_file_id);
341339
let usages = refs.into_iter().filter_map(|FileReference { range, .. }| {
@@ -464,10 +462,8 @@ impl Module {
464462
let file_id = ctx.file_id();
465463
let usage_res = def.usages(&ctx.sema).in_scope(&SearchScope::single_file(file_id)).all();
466464

467-
let editioned_file_id = ide_db::base_db::EditionedFileId::new(
468-
ctx.sema.db.as_dyn_database(),
469-
file_id,
470-
);
465+
let editioned_file_id =
466+
ide_db::base_db::EditionedFileId::new(ctx.sema.db.as_dyn_database(), file_id);
471467

472468
let file = ctx.sema.parse(editioned_file_id);
473469

0 commit comments

Comments
 (0)