Skip to content

Commit d7ec69a

Browse files
committed
Rollup merge of #28526 - Manishearth:expand-clone, r=eddyb
This reduces some clones of `Vec`s. These are not deep copies since the token tree is made using `Rc`s, so this won't be a major improvement. r? @eddyb
2 parents 8f8fe81 + 8aef16c commit d7ec69a

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

src/libsyntax/ext/expand.rs

+25-24
Original file line numberDiff line numberDiff line change
@@ -684,15 +684,15 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool
684684
// logic as for expression-position macro invocations.
685685
pub fn expand_item_mac(it: P<ast::Item>,
686686
fld: &mut MacroExpander) -> SmallVector<P<ast::Item>> {
687-
let (extname, path_span, tts) = match it.node {
687+
let (extname, path_span, tts, span, attrs, ident) = it.and_then(|it| { match it.node {
688688
ItemMac(codemap::Spanned {
689-
node: MacInvocTT(ref pth, ref tts, _),
689+
node: MacInvocTT(pth, tts, _),
690690
..
691691
}) => {
692-
(pth.segments[0].identifier.name, pth.span, (*tts).clone())
692+
(pth.segments[0].identifier.name, pth.span, tts, it.span, it.attrs, it.ident)
693693
}
694694
_ => fld.cx.span_bug(it.span, "invalid item macro invocation")
695-
};
695+
}});
696696

697697
let fm = fresh_mark();
698698
let items = {
@@ -706,56 +706,56 @@ pub fn expand_item_mac(it: P<ast::Item>,
706706
}
707707

708708
Some(rc) => match *rc {
709-
NormalTT(ref expander, span, allow_internal_unstable) => {
710-
if it.ident.name != parse::token::special_idents::invalid.name {
709+
NormalTT(ref expander, tt_span, allow_internal_unstable) => {
710+
if ident.name != parse::token::special_idents::invalid.name {
711711
fld.cx
712712
.span_err(path_span,
713713
&format!("macro {}! expects no ident argument, given '{}'",
714714
extname,
715-
it.ident));
715+
ident));
716716
return SmallVector::zero();
717717
}
718718
fld.cx.bt_push(ExpnInfo {
719-
call_site: it.span,
719+
call_site: span,
720720
callee: NameAndSpan {
721721
format: MacroBang(extname),
722-
span: span,
722+
span: tt_span,
723723
allow_internal_unstable: allow_internal_unstable,
724724
}
725725
});
726726
// mark before expansion:
727727
let marked_before = mark_tts(&tts[..], fm);
728-
expander.expand(fld.cx, it.span, &marked_before[..])
728+
expander.expand(fld.cx, span, &marked_before[..])
729729
}
730-
IdentTT(ref expander, span, allow_internal_unstable) => {
731-
if it.ident.name == parse::token::special_idents::invalid.name {
730+
IdentTT(ref expander, tt_span, allow_internal_unstable) => {
731+
if ident.name == parse::token::special_idents::invalid.name {
732732
fld.cx.span_err(path_span,
733733
&format!("macro {}! expects an ident argument",
734734
extname));
735735
return SmallVector::zero();
736736
}
737737
fld.cx.bt_push(ExpnInfo {
738-
call_site: it.span,
738+
call_site: span,
739739
callee: NameAndSpan {
740740
format: MacroBang(extname),
741-
span: span,
741+
span: tt_span,
742742
allow_internal_unstable: allow_internal_unstable,
743743
}
744744
});
745745
// mark before expansion:
746746
let marked_tts = mark_tts(&tts[..], fm);
747-
expander.expand(fld.cx, it.span, it.ident, marked_tts)
747+
expander.expand(fld.cx, span, ident, marked_tts)
748748
}
749749
MacroRulesTT => {
750-
if it.ident.name == parse::token::special_idents::invalid.name {
750+
if ident.name == parse::token::special_idents::invalid.name {
751751
fld.cx.span_err(path_span,
752752
&format!("macro_rules! expects an ident argument")
753753
);
754754
return SmallVector::zero();
755755
}
756756

757757
fld.cx.bt_push(ExpnInfo {
758-
call_site: it.span,
758+
call_site: span,
759759
callee: NameAndSpan {
760760
format: MacroBang(extname),
761761
span: None,
@@ -767,7 +767,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
767767
});
768768
// DON'T mark before expansion.
769769

770-
let allow_internal_unstable = attr::contains_name(&it.attrs,
770+
let allow_internal_unstable = attr::contains_name(&attrs,
771771
"allow_internal_unstable");
772772

773773
// ensure any #[allow_internal_unstable]s are
@@ -777,18 +777,19 @@ pub fn expand_item_mac(it: P<ast::Item>,
777777
feature_gate::emit_feature_err(
778778
&fld.cx.parse_sess.span_diagnostic,
779779
"allow_internal_unstable",
780-
it.span,
780+
span,
781781
feature_gate::GateIssue::Language,
782782
feature_gate::EXPLAIN_ALLOW_INTERNAL_UNSTABLE)
783783
}
784784

785+
let export = attr::contains_name(&attrs, "macro_export");
785786
let def = ast::MacroDef {
786-
ident: it.ident,
787-
attrs: it.attrs.clone(),
787+
ident: ident,
788+
attrs: attrs,
788789
id: ast::DUMMY_NODE_ID,
789-
span: it.span,
790+
span: span,
790791
imported_from: None,
791-
export: attr::contains_name(&it.attrs, "macro_export"),
792+
export: export,
792793
use_locally: true,
793794
allow_internal_unstable: allow_internal_unstable,
794795
body: tts,
@@ -800,7 +801,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
800801
return SmallVector::zero();
801802
}
802803
_ => {
803-
fld.cx.span_err(it.span,
804+
fld.cx.span_err(span,
804805
&format!("{}! is not legal in item position",
805806
extname));
806807
return SmallVector::zero();

0 commit comments

Comments
 (0)