Skip to content

Commit 606bb6f

Browse files
committed
avoid extra copy
1 parent 6d26c5f commit 606bb6f

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,27 @@ pub fn transcribe(
9898
};
9999

100100
match tree {
101-
quoted::TokenTree::Sequence(sp, seq) => {
102-
// FIXME(pcwalton): Bad copy.
103-
match lockstep_iter_size(
104-
&quoted::TokenTree::Sequence(sp, seq.clone()),
105-
&interpolations,
106-
&repeats,
107-
) {
101+
seq @ quoted::TokenTree::Sequence(..) => {
102+
match lockstep_iter_size(&seq, interp, &repeats) {
108103
LockstepIterSize::Unconstrained => {
109104
cx.span_fatal(
110-
sp.entire(), /* blame macro writer */
105+
seq.span(), /* blame macro writer */
111106
"attempted to repeat an expression \
112107
containing no syntax \
113108
variables matched as repeating at this depth",
114109
);
115110
}
116111
LockstepIterSize::Contradiction(ref msg) => {
117112
// FIXME #2887 blame macro invoker instead
118-
cx.span_fatal(sp.entire(), &msg[..]);
113+
cx.span_fatal(seq.span(), &msg[..]);
119114
}
120115
LockstepIterSize::Constraint(len, _) => {
116+
let (sp, seq) = if let quoted::TokenTree::Sequence(sp, seq) = seq {
117+
(sp, seq)
118+
} else {
119+
unreachable!()
120+
};
121+
121122
if len == 0 {
122123
if seq.op == quoted::KleeneOp::OneOrMore {
123124
// FIXME #2887 blame invoker
@@ -201,10 +202,8 @@ enum LockstepIterSize {
201202
Contradiction(String),
202203
}
203204

204-
impl Add for LockstepIterSize {
205-
type Output = LockstepIterSize;
206-
207-
fn add(self, other: LockstepIterSize) -> LockstepIterSize {
205+
impl LockstepIterSize {
206+
fn with(self, other: LockstepIterSize) -> LockstepIterSize {
208207
match self {
209208
LockstepIterSize::Unconstrained => other,
210209
LockstepIterSize::Contradiction(_) => self,

0 commit comments

Comments
 (0)