Skip to content

Commit

Permalink
avoid extra copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-i-m committed May 7, 2019
1 parent 6d26c5f commit 606bb6f
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/libsyntax/ext/tt/transcribe.rs
Expand Up @@ -98,26 +98,27 @@ pub fn transcribe(
};

match tree {
quoted::TokenTree::Sequence(sp, seq) => {
// FIXME(pcwalton): Bad copy.
match lockstep_iter_size(
&quoted::TokenTree::Sequence(sp, seq.clone()),
&interpolations,
&repeats,
) {
seq @ quoted::TokenTree::Sequence(..) => {
match lockstep_iter_size(&seq, interp, &repeats) {
LockstepIterSize::Unconstrained => {
cx.span_fatal(
sp.entire(), /* blame macro writer */
seq.span(), /* blame macro writer */
"attempted to repeat an expression \
containing no syntax \
variables matched as repeating at this depth",
);
}
LockstepIterSize::Contradiction(ref msg) => {
// FIXME #2887 blame macro invoker instead
cx.span_fatal(sp.entire(), &msg[..]);
cx.span_fatal(seq.span(), &msg[..]);
}
LockstepIterSize::Constraint(len, _) => {
let (sp, seq) = if let quoted::TokenTree::Sequence(sp, seq) = seq {
(sp, seq)
} else {
unreachable!()
};

if len == 0 {
if seq.op == quoted::KleeneOp::OneOrMore {
// FIXME #2887 blame invoker
Expand Down Expand Up @@ -201,10 +202,8 @@ enum LockstepIterSize {
Contradiction(String),
}

impl Add for LockstepIterSize {
type Output = LockstepIterSize;

fn add(self, other: LockstepIterSize) -> LockstepIterSize {
impl LockstepIterSize {
fn with(self, other: LockstepIterSize) -> LockstepIterSize {
match self {
LockstepIterSize::Unconstrained => other,
LockstepIterSize::Contradiction(_) => self,
Expand Down

0 comments on commit 606bb6f

Please sign in to comment.