Skip to content

Commit e534702

Browse files
bors[bot]Veykril
andauthored
Merge #11511
11511: internal: Wrap MacroCallKind::Attr attr_args field in an Arc r=Veykril a=Veykril This is stored in `MacroCallLoc` which is returned from a query, so cloning should be made cheap. bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 1d53f69 + fbe787e commit e534702

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

crates/hir_def/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ fn attr_macro_as_call_id(
787787
MacroCallKind::Attr {
788788
ast_id: item_attr.ast_id,
789789
attr_name: last_segment.to_string().into_boxed_str(),
790-
attr_args: arg,
790+
attr_args: Arc::new(arg),
791791
invoc_attr_index: macro_attr.id.ast_index,
792792
},
793793
);

crates/hir_expand/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub enum MacroCallKind {
135135
Attr {
136136
ast_id: AstId<ast::Item>,
137137
attr_name: Box<str>,
138-
attr_args: (tt::Subtree, mbe::TokenMap),
138+
attr_args: Arc<(tt::Subtree, mbe::TokenMap)>,
139139
/// Syntactical index of the invoking `#[attribute]`.
140140
///
141141
/// Outer attributes are counted first, then inner attributes. This does not support
@@ -472,7 +472,7 @@ impl ExpansionInfo {
472472

473473
let token_range = token.value.text_range();
474474
match &loc.kind {
475-
MacroCallKind::Attr { attr_args: (_, map), invoc_attr_index, .. } => {
475+
MacroCallKind::Attr { attr_args, invoc_attr_index, .. } => {
476476
let attr = item
477477
.doc_comments_and_attrs()
478478
.nth(*invoc_attr_index as usize)
@@ -486,8 +486,9 @@ impl ExpansionInfo {
486486
let relative_range =
487487
token.value.text_range().checked_sub(attr_input_start)?;
488488
// shift by the item's tree's max id
489-
let token_id =
490-
self.macro_arg_shift.shift(map.token_by_range(relative_range)?);
489+
let token_id = self
490+
.macro_arg_shift
491+
.shift(attr_args.1.token_by_range(relative_range)?);
491492
Some(token_id)
492493
}
493494
_ => None,
@@ -535,13 +536,13 @@ impl ExpansionInfo {
535536

536537
// Attributes are a bit special for us, they have two inputs, the input tokentree and the annotated item.
537538
let (token_map, tt) = match &loc.kind {
538-
MacroCallKind::Attr { attr_args: (_, arg_token_map), .. } => {
539+
MacroCallKind::Attr { attr_args, .. } => {
539540
// try unshifting the the token id, if unshifting fails, the token resides in the non-item attribute input
540541
// note that the `TokenExpander::map_id_up` earlier only unshifts for declarative macros, so we don't double unshift with this
541542
match self.macro_arg_shift.unshift(token_id) {
542543
Some(unshifted) => {
543544
token_id = unshifted;
544-
(arg_token_map, self.attr_input_or_mac_def.clone()?.syntax().cloned())
545+
(&attr_args.1, self.attr_input_or_mac_def.clone()?.syntax().cloned())
545546
}
546547
None => (&self.macro_arg.1, self.arg.clone()),
547548
}

0 commit comments

Comments
 (0)