Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #86 from dtolnay/clone
Browse files Browse the repository at this point in the history
Produce clone of input tokenstream if contains no paste
  • Loading branch information
dtolnay authored Aug 31, 2022
2 parents 55380e3 + 25960a4 commit 671460b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,18 @@ use std::panic;
pub fn paste(input: TokenStream) -> TokenStream {
let mut contains_paste = false;
let flatten_single_interpolation = true;
match expand(input, &mut contains_paste, flatten_single_interpolation) {
Ok(expanded) => expanded,
match expand(
input.clone(),
&mut contains_paste,
flatten_single_interpolation,
) {
Ok(expanded) => {
if contains_paste {
expanded
} else {
input
}
}
Err(err) => err.to_compile_error(),
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,26 @@ mod test_local_setter {
assert_eq!(a.val, 42);
}
}

// https://github.com/dtolnay/paste/issues/85
#[test]
fn test_top_level_none_delimiter() {
macro_rules! clone {
($val:expr) => {
paste! {
$val.clone()
}
};
}

#[derive(Clone)]
struct A;

impl A {
fn consume_self(self) {
let _ = self;
}
}

clone!(&A).consume_self();
}

0 comments on commit 671460b

Please sign in to comment.