pastey/lib.rs
1#![doc = include_str!("../README.md")]
2#![allow(
3 clippy::derive_partial_eq_without_eq,
4 clippy::doc_markdown,
5 clippy::match_same_arms,
6 clippy::module_name_repetitions,
7 clippy::needless_doctest_main,
8 clippy::too_many_lines
9)]
10#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
11
12extern crate proc_macro;
13
14mod attr;
15mod error;
16mod segment;
17#[cfg(coverage_nightly)]
18mod test_helpers;
19
20use crate::attr::expand_attr;
21use crate::error::{Error, Result};
22use crate::segment::Segment;
23use proc_macro::{
24 Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
25};
26use std::char;
27use std::iter;
28use std::panic;
29use std::str::FromStr;
30
31#[proc_macro]
32pub fn paste(input: TokenStream) -> TokenStream {
33 let mut contains_paste = false;
34 let flatten_single_interpolation = true;
35 match expand(
36 input.clone(),
37 &mut contains_paste,
38 flatten_single_interpolation,
39 ) {
40 Ok(expanded) => {
41 if contains_paste {
42 expanded
43 } else {
44 input
45 }
46 }
47 Err(err) => err.to_compile_error(),
48 }
49}
50
51#[doc(hidden)]
52#[proc_macro]
53pub fn item(input: TokenStream) -> TokenStream {
54 paste(input)
55}
56
57#[doc(hidden)]
58#[proc_macro]
59pub fn expr(input: TokenStream) -> TokenStream {
60 paste(input)
61}
62
63fn expand(
64 input: TokenStream,
65 contains_paste: &mut bool,
66 flatten_single_interpolation: bool,
67) -> Result<TokenStream> {
68 let mut expanded = TokenStream::new();
69 let mut lookbehind = Lookbehind::Other;
70 let mut prev_none_group = None::<Group>;
71 let mut tokens = input.into_iter().peekable();
72 loop {
73 let token = tokens.next();
74 if let Some(group) = prev_none_group.take() {
75 if match (&token, tokens.peek()) {
76 (Some(TokenTree::Punct(fst)), Some(TokenTree::Punct(snd))) => {
77 fst.as_char() == ':' && snd.as_char() == ':' && fst.spacing() == Spacing::Joint
78 }
79 _ => false,
80 } {
81 expanded.extend(group.stream());
82 *contains_paste = true;
83 } else {
84 expanded.extend(iter::once(TokenTree::Group(group)));
85 }
86 }
87 match token {
88 Some(TokenTree::Group(group)) => {
89 let delimiter = group.delimiter();
90 let content = group.stream();
91 let span = group.span();
92 if delimiter == Delimiter::Bracket && is_paste_operation(&content) {
93 let segments = parse_bracket_as_segments(content, span)?;
94 let pasted = segment::paste(&segments)?;
95 let tokens = pasted_to_tokens(pasted, span)?;
96 expanded.extend(tokens);
97 *contains_paste = true;
98 } else if flatten_single_interpolation
99 && delimiter == Delimiter::None
100 && is_single_interpolation_group(&content)
101 {
102 expanded.extend(content);
103 *contains_paste = true;
104 } else {
105 let mut group_contains_paste = false;
106 let is_attribute = delimiter == Delimiter::Bracket
107 && (lookbehind == Lookbehind::Pound || lookbehind == Lookbehind::PoundBang);
108 let mut nested = expand(
109 content,
110 &mut group_contains_paste,
111 flatten_single_interpolation && !is_attribute,
112 )?;
113 if is_attribute {
114 nested = expand_attr(nested, span, &mut group_contains_paste)?;
115 }
116 let group = if group_contains_paste {
117 let mut group = Group::new(delimiter, nested);
118 group.set_span(span);
119 *contains_paste = true;
120 group
121 } else {
122 group.clone()
123 };
124 if delimiter != Delimiter::None {
125 expanded.extend(iter::once(TokenTree::Group(group)));
126 } else if lookbehind == Lookbehind::DoubleColon {
127 expanded.extend(group.stream());
128 *contains_paste = true;
129 } else {
130 prev_none_group = Some(group);
131 }
132 }
133 lookbehind = Lookbehind::Other;
134 }
135 Some(TokenTree::Punct(punct)) => {
136 lookbehind = match punct.as_char() {
137 ':' if lookbehind == Lookbehind::JointColon => Lookbehind::DoubleColon,
138 ':' if punct.spacing() == Spacing::Joint => Lookbehind::JointColon,
139 '#' => Lookbehind::Pound,
140 '!' if lookbehind == Lookbehind::Pound => Lookbehind::PoundBang,
141 _ => Lookbehind::Other,
142 };
143 expanded.extend(iter::once(TokenTree::Punct(punct)));
144 }
145 Some(other) => {
146 lookbehind = Lookbehind::Other;
147 expanded.extend(iter::once(other));
148 }
149 None => return Ok(expanded),
150 }
151 }
152}
153
154#[derive(PartialEq)]
155enum Lookbehind {
156 JointColon,
157 DoubleColon,
158 Pound,
159 PoundBang,
160 Other,
161}
162
163// https://github.com/dtolnay/paste/issues/26
164fn is_single_interpolation_group(input: &TokenStream) -> bool {
165 #[derive(PartialEq)]
166 enum State {
167 Init,
168 Ident,
169 Literal,
170 Apostrophe,
171 Lifetime,
172 Colon1,
173 Colon2,
174 }
175
176 let mut state = State::Init;
177 for tt in input.clone() {
178 state = match (state, &tt) {
179 (State::Init, TokenTree::Ident(_)) => State::Ident,
180 (State::Init, TokenTree::Literal(_)) => State::Literal,
181 (State::Init, TokenTree::Punct(punct)) if punct.as_char() == '\'' => State::Apostrophe,
182 (State::Apostrophe, TokenTree::Ident(_)) => State::Lifetime,
183 (State::Ident, TokenTree::Punct(punct))
184 if punct.as_char() == ':' && punct.spacing() == Spacing::Joint =>
185 {
186 State::Colon1
187 }
188 (State::Colon1, TokenTree::Punct(punct))
189 if punct.as_char() == ':' && punct.spacing() == Spacing::Alone =>
190 {
191 State::Colon2
192 }
193 (State::Colon2, TokenTree::Ident(_)) => State::Ident,
194 _ => return false,
195 };
196 }
197
198 state == State::Ident || state == State::Literal || state == State::Lifetime
199}
200
201fn is_paste_operation(input: &TokenStream) -> bool {
202 let mut tokens = input.clone().into_iter();
203
204 match &tokens.next() {
205 Some(TokenTree::Punct(punct)) if punct.as_char() == '<' => {}
206 _ => return false,
207 }
208
209 let mut has_token = false;
210 loop {
211 match &tokens.next() {
212 Some(TokenTree::Punct(punct)) if punct.as_char() == '>' => {
213 return has_token && tokens.next().is_none();
214 }
215 Some(_) => has_token = true,
216 None => return false,
217 }
218 }
219}
220
221// Coverage note:
222// Uncovered line -Some(wrong) => return Err(Error::new(wrong.span(), "expected `>`")),
223//
224// This line can never be reached because segment::parse stops only when it
225// sees `>` or runs out of tokens. So the very next token after parse() is
226// always either `>` or None — never any other token.
227//
228// coverage(off) cannot be placed on a single match arm, only on a whole
229// function. So the match was moved into this helper function so the
230// attribute can be applied here.
231#[cfg_attr(coverage_nightly, coverage(off))]
232fn check_close_angle_token(token: Option<TokenTree>, scope: Span) -> Result<()> {
233 match token {
234 Some(TokenTree::Punct(punct)) if punct.as_char() == '>' => Ok(()),
235 Some(wrong) => Err(Error::new(wrong.span(), "expected `>`")),
236 None => Err(Error::new(scope, "expected `[< ... >]`")),
237 }
238}
239
240// Coverage note:
241// Uncovered lines (the fallthrough/else paths of the two if-let checks):
242// if let Ok(unsigned) = u32::from_str_radix(hex, 16) {
243// if let Some(ch) = char::from_u32(unsigned) {
244// ...
245// }// None path never covered
246// }// Err path never covered
247//
248// These paths can never be reached because:
249// - The hex string comes from a Literal that the Rust compiler already parsed.
250// The compiler rejects any non-hex characters in \u{...} at compile time,
251// so from_str_radix will always succeed (never Err).
252// - The compiler also rejects surrogate codepoints like \u{D800} at compile
253// time, so char::from_u32 will always succeed (never None).
254//
255// The defensive checks are kept in case this code is called with manually
256// constructed TokenStreams in the future. The block is moved into this helper
257// so coverage(off) can be applied at function scope (the only level the
258// attribute supports). The call site becomes a simple bool check with no
259// uncoverable branches.
260//
261// Returns true if the value was converted (caller should `continue`), false otherwise.
262#[cfg_attr(coverage_nightly, coverage(off))]
263fn try_convert_unicode_escape(value: &mut String) -> bool {
264 if value.starts_with("'\\u{") {
265 let hex = &value[4..value.len() - 2];
266 if let Ok(unsigned) = u32::from_str_radix(hex, 16) {
267 if let Some(ch) = char::from_u32(unsigned) {
268 value.clear();
269 value.push(ch);
270 return true;
271 }
272 }
273 }
274 false
275}
276
277fn parse_bracket_as_segments(input: TokenStream, scope: Span) -> Result<Vec<Segment>> {
278 let mut tokens = input.into_iter().peekable();
279
280 match &tokens.next() {
281 Some(TokenTree::Punct(punct)) if punct.as_char() == '<' => {}
282 Some(wrong) => return Err(Error::new(wrong.span(), "expected `<`")),
283 None => return Err(Error::new(scope, "expected `[< ... >]`")),
284 }
285
286 let mut segments = segment::parse(&mut tokens)?;
287
288 check_close_angle_token(tokens.next(), scope)?;
289
290 if let Some(unexpected) = tokens.next() {
291 return Err(Error::new(
292 unexpected.span(),
293 "unexpected input, expected `[< ... >]`",
294 ));
295 }
296
297 for segment in &mut segments {
298 if let Segment::String(string) = segment {
299 if try_convert_unicode_escape(&mut string.value) {
300 continue;
301 }
302 if string.value.contains(&['\\', '.', '+'][..])
303 || string.value.starts_with("b'")
304 || string.value.starts_with("b\"")
305 || string.value.starts_with("br\"")
306 {
307 return Err(Error::new(string.span, "unsupported literal"));
308 }
309 let mut range = 0..string.value.len();
310 if string.value.starts_with("r\"") {
311 range.start += 2;
312 range.end -= 1;
313 } else if string.value.starts_with(&['"', '\''][..]) {
314 range.start += 1;
315 range.end -= 1;
316 }
317 string.value = string.value[range].replace('-', "_");
318 }
319 }
320
321 Ok(segments)
322}
323
324fn pasted_to_tokens(mut pasted: String, span: Span) -> Result<TokenStream> {
325 let mut raw_mode = false;
326 let mut tokens = TokenStream::new();
327
328 if pasted.starts_with(|ch: char| ch.is_ascii_digit()) {
329 let literal = match panic::catch_unwind(|| Literal::from_str(&pasted)) {
330 Ok(Ok(literal)) => TokenTree::Literal(literal),
331 Ok(Err(LexError { .. })) | Err(_) => {
332 return Err(Error::new(
333 span,
334 &format!("`{:?}` is not a valid literal", pasted),
335 ));
336 }
337 };
338 tokens.extend(iter::once(literal));
339 return Ok(tokens);
340 }
341
342 if pasted.starts_with('\'') {
343 let mut apostrophe = TokenTree::Punct(Punct::new('\'', Spacing::Joint));
344 apostrophe.set_span(span);
345 tokens.extend(iter::once(apostrophe));
346 pasted.remove(0);
347 }
348
349 if pasted.starts_with("r#") {
350 raw_mode = true;
351 }
352
353 let ident = match panic::catch_unwind(|| {
354 if raw_mode {
355 let mut spasted = pasted.clone();
356 spasted.remove(0);
357 spasted.remove(0);
358 Ident::new_raw(&spasted, span)
359 } else {
360 Ident::new(&pasted, span)
361 }
362 }) {
363 Ok(ident) => TokenTree::Ident(ident),
364 Err(_) => {
365 return Err(Error::new(
366 span,
367 &format!("`{:?}` is not a valid identifier", pasted),
368 ));
369 }
370 };
371
372 tokens.extend(iter::once(ident));
373 Ok(tokens)
374}
375
376// Below functions and macro is just for testing the internal functions that are not directly exposed
377// and can not be tested through public paste macro because of pre-validation of most error cases in it,
378// so we can not cover those error cases through it.
379// Also some of the inputs for testing those functions can not be constructed directly in tests because of TokenStream,
380// so we need to construct them using proc_macro functions and then call the functions we want to test.
381#[cfg(coverage_nightly)]
382#[coverage(off)]
383#[proc_macro]
384#[doc(hidden)]
385pub fn paste_test(input: TokenStream) -> TokenStream {
386 let scope = Span::call_site();
387 test_helpers::expand_attr_test(scope);
388 test_helpers::parse_bracket_as_segments_test(scope);
389
390 {
391 let mut multi_inner = TokenStream::new();
392 multi_inner.extend([TokenTree::Ident(Ident::new("a", scope))]);
393 multi_inner.extend([TokenTree::Ident(Ident::new("b", scope))]);
394 let multi_none = TokenTree::Group(Group::new(Delimiter::None, multi_inner));
395 let _ = segment::get_token_tree_string_value(&multi_none);
396 }
397
398 {
399 let empty_none = TokenTree::Group(Group::new(Delimiter::None, TokenStream::new()));
400 let _ = segment::get_token_tree_string_value(&empty_none);
401 }
402
403 // Emit compile_error! unconditionally into the output so any call site that
404 // reaches the compiler gets the intended error message directly.
405 let mut out = TokenStream::from_str(
406 "compile_error!(\"paste_test! is for internal coverage testing only and must not be called outside of test context\");",
407 )
408 .unwrap();
409 out.extend(input);
410 out
411}
412
413#[cfg(doctest)]
414#[doc(hidden)]
415mod doc_tests {
416 /// ```compile_fail
417 /// use pastey::paste_test;
418 /// paste_test!("test");
419 /// ```
420 fn paste_test_macro_for_internal_coverage() {}
421
422 /// ```
423 /// use pastey::paste;
424 /// let arr: [u8; 3] = paste!([1u8, 2, 3]);
425 /// ```
426 fn test_non_paste_bracket_returns_input() {}
427
428 /// ```
429 /// use pastey::paste;
430 /// macro_rules! m {
431 /// ($id:ident) => { paste! { fn $id() {} } }
432 /// }
433 /// m!(doc_flatten_fn);
434 /// doc_flatten_fn();
435 /// ```
436 fn test_flatten_single_ident_group() {}
437
438 /// ```
439 /// use pastey::paste;
440 /// macro_rules! m {
441 /// ($life:lifetime) => {
442 /// paste! { struct DocRef<$life>(pub &$life ()); }
443 /// }
444 /// }
445 /// m!('a);
446 /// ```
447 fn test_flatten_lifetime_group() {}
448
449 /// ```
450 /// use pastey::paste;
451 /// macro_rules! m {
452 /// ($t:path) => { paste! { type DocPathAlias = $t; } }
453 /// }
454 /// m!(std::string::String);
455 /// let _: DocPathAlias = String::new();
456 /// ```
457 fn test_flatten_path_group() {}
458
459 /// ```
460 /// use pastey::paste;
461 /// macro_rules! m {
462 /// ($lit:literal) => { paste! { const DOC_LIT: u8 = $lit; } }
463 /// }
464 /// m!(99u8);
465 /// ```
466 fn test_flatten_literal_group() {}
467
468 /// ```
469 /// use pastey::paste;
470 /// paste! { let _: std::string::String = String::new(); }
471 /// ```
472 fn test_double_colon_none_group() {}
473
474 /// ```
475 /// use pastey::paste;
476 /// macro_rules! m {
477 /// ($t:ty) => {
478 /// paste! {
479 /// pub const NONE_GROUP_TY_STR: &str = stringify!($t::method);
480 /// }
481 /// }
482 /// }
483 /// m!(Vec<u8>);
484 /// ```
485 fn test_none_group_complex_type_before_double_colon() {}
486
487 /// ```
488 /// use pastey::paste;
489 /// paste! {
490 /// mod doc_inner_mod {
491 /// #![allow(dead_code)]
492 /// pub struct DocInner;
493 /// }
494 /// }
495 /// ```
496 fn test_inner_mod() {}
497
498 /// ```
499 /// use pastey::paste;
500 /// macro_rules! allow_lint {
501 /// ($lint:ident) => {
502 /// paste! {
503 /// #[allow(clippy::$lint)]
504 /// pub struct DocLintStruct;
505 /// }
506 /// }
507 /// }
508 /// allow_lint!(pedantic);
509 /// ```
510 fn test_double_colon_none_group_in_attr() {}
511
512 /// ```
513 /// use pastey::paste;
514 /// paste! { const _: &str = stringify!([<'\u{48}' ello>]); }
515 /// ```
516 fn test_char_unicode_escape_in_paste() {}
517
518 /// ```
519 /// use pastey::paste;
520 /// paste! { const _: &str = stringify!([<r"hel" lo>]); }
521 /// ```
522 fn test_raw_string_in_paste() {}
523
524 /// ```
525 /// use pastey::paste;
526 /// paste! { struct DocLifeRef<[<'a>]>(pub &[<'a>] ()); }
527 /// ```
528 fn test_lifetime_paste_tokens() {}
529
530 /// ```
531 /// use pastey::paste;
532 /// paste! { #[allow(non_camel_case_types)] struct [<# loop>]; }
533 /// ```
534 fn test_raw_mode_paste_tokens() {}
535
536 /// ```
537 /// use pastey::paste;
538 /// paste! { const _: &str = stringify!([<'\u{41}' bcde>]); }
539 /// ```
540 fn test_char_unicode_paste_tokens() {}
541
542 /// ```
543 /// use pastey::paste;
544 /// macro_rules! m {
545 /// ($t:ty) => {
546 /// paste! { let _: $t = std::string::String::new(); }
547 /// }
548 /// }
549 /// m!(String);
550 /// ```
551 fn test_none_group_not_followed_by_double_colon() {}
552
553 /// ```compile_fail
554 /// use pastey::paste;
555 /// paste! { const _: u32 = [<99 invalid>]; }
556 /// ```
557 fn test_error_invalid_literal_with_trailing_tokens() {}
558
559 /// ```compile_fail
560 /// use pastey::paste;
561 /// paste! { const _: &str = [<@invalid>]; }
562 /// ```
563 fn test_error_invalid_identifier_special_char() {}
564
565 /// ```compile_fail
566 /// use pastey::paste;
567 /// paste! { const _: &str = [identifier]; }
568 /// ```
569 fn test_error_expected_bracket_with_angle() {}
570
571 /// ```compile_fail
572 /// use pastey::paste;
573 /// paste! { const _: &str = [<identifier]; }
574 /// ```
575 fn test_error_expected_closing_angle() {}
576
577 /// ```compile_fail
578 /// use pastey::paste;
579 /// paste! { const _: &str = [<identifier> extra]; }
580 /// ```
581 fn test_error_unexpected_token_after_closing_angle() {}
582
583 /// ```compile_fail
584 /// use pastey::paste;
585 /// paste! { const _: &str = [<"byte\\string">]; }
586 /// ```
587 fn test_error_unsupported_escaped_string() {}
588
589 /// ```compile_fail
590 /// use pastey::paste;
591 /// paste! { const _: &str = [<b"byte_string">]; }
592 /// ```
593 fn test_error_unsupported_byte_string() {}
594
595 /// ```compile_fail
596 /// use pastey::paste;
597 /// paste! { fn [<x b'y'>]() {} }
598 /// ```
599 fn test_error_unsupported_byte_char_literal() {}
600
601 /// ```compile_fail
602 /// use pastey::paste;
603 /// paste! { const _: &str = [<br"raw_byte">]; }
604 /// ```
605 fn test_error_unsupported_raw_byte_string() {}
606
607 /// ```compile_fail
608 /// use pastey::paste;
609 /// paste! { const _: &str = [<"string.with.dots">]; }
610 /// ```
611 fn test_error_unsupported_string_with_dots() {}
612
613 /// ```compile_fail
614 /// use pastey::paste;
615 /// paste! { const _: &str = [<"string+plus">]; }
616 /// ```
617 fn test_error_unsupported_string_with_plus() {}
618
619 /// ```compile_fail
620 /// use pastey::paste;
621 /// paste! { const _: &str = [<>]; }
622 /// ```
623 fn test_error_expected_content_in_brackets() {}
624
625 /// ```compile_fail
626 /// use pastey::paste;
627 /// paste! { const _: &str = [<a..b>]; }
628 /// ```
629 fn test_error_invalid_numeric_literal() {}
630
631 /// ```compile_fail
632 /// use pastey::paste;
633 /// paste! { const _: &str = [< >]; }
634 /// ```
635 fn test_error_no_tokens_in_paste() {}
636
637 /// ```compile_fail
638 /// use pastey::paste;
639 /// paste! { const _: &str = [<'static>]; }
640 /// ```
641 fn test_error_lifetime_without_identifier() {}
642
643 /// ```compile_fail
644 /// use pastey::paste;
645 /// macro_rules! m {
646 /// ($x:ident) => {
647 /// paste! { const _: u32 = [<$x>]; }
648 /// }
649 /// }
650 /// m!(123);
651 /// ```
652 fn test_error_invalid_ident_starting_with_number() {}
653
654 /// ```compile_fail
655 /// use pastey::paste;
656 /// paste! { const _: &str = [<"terminated>]; }
657 /// ```
658 fn test_error_terminated_string_literal() {}
659
660 /// ```compile_fail
661 /// use pastey::paste;
662 /// paste! { let x = [<y z>]; }
663 /// ```
664 fn test_error_multiple_tokens_non_paste() {}
665
666 /// ```compile_fail
667 /// use pastey::paste;
668 /// paste! { let x: i32 = [<not_a_number>]; }
669 /// ```
670 fn test_error_paste_result_type_mismatch() {}
671
672 /// ```compile_fail
673 /// use pastey::paste;
674 /// paste! { const _: &str = [<'a 'b>]; }
675 /// ```
676 fn test_error_multiple_lifetimes() {}
677
678 /// ```compile_fail
679 /// use pastey::paste;
680 /// paste! { const _: &str = [<42 56>]; }
681 /// ```
682 fn test_error_multiple_numeric_tokens() {}
683
684 /// ```compile_fail
685 /// use pastey::paste;
686 /// macro_rules! concat_idents {
687 /// ($a:ident, $b:ident) => { paste! { const TEST: u32 = [<method_ $a>](); } }
688 /// }
689 /// concat_idents!(test, func);
690 /// ```
691 fn test_error_method_call_on_paste_result() {}
692
693 /// ```compile_fail
694 /// use pastey::paste;
695 /// paste! { const _ : &str = [<r# if>]; }
696 /// ```
697 fn test_error_raw_keyword_identifier() {}
698
699 /// ```compile_fail
700 /// use pastey::paste;
701 /// macro_rules! m {
702 /// () => { paste! { const _: u32 = [<>]; } }
703 /// }
704 /// m!();
705 /// ```
706 fn test_error_empty_macro_result() {}
707
708 /// ```compile_fail
709 /// use pastey::paste;
710 /// paste! { const _: &str = [<-identifier>]; }
711 /// ```
712 fn test_error_hyphen_at_start() {}
713
714 /// ```compile_fail
715 /// use pastey::paste;
716 /// paste! { const _: &str = [<'123>]; }
717 /// ```
718 fn test_error_apostrophe_with_number() {}
719
720 /// ```compile_fail
721 /// use pastey::paste;
722 /// macro_rules! m {
723 /// ($lit:literal) => {
724 /// paste! { const _: &str = stringify!([<$lit>]); }
725 /// }
726 /// }
727 /// m!("both" "strings");
728 /// ```
729 fn test_error_invalid_literal_argument() {}
730
731 /// ```compile_fail
732 /// use pastey::paste;
733 /// paste! { const _: &str = [<'\u{D800}>]; }
734 /// ```
735 fn test_error_invalid_unicode_escape() {}
736
737 /// ```compile_fail
738 /// use pastey::paste;
739 /// paste! { const _: u32 = [<0x>]; }
740 /// ```
741 fn test_error_incomplete_hex_literal() {}
742
743 /// ```compile_fail
744 /// use pastey::paste;
745 /// paste! { const _: u32 = [<0b>]; }
746 /// ```
747 fn test_error_incomplete_binary_literal() {}
748
749 /// ```compile_fail
750 /// use pastey::paste;
751 /// paste! { const _: f64 = [<1..5>]; }
752 /// ```
753 fn test_error_range_literal_invalid() {}
754
755 /// ```compile_fail
756 /// use pastey::paste;
757 /// paste! { const _: &str = [<if>]; }
758 /// ```
759 fn test_error_keyword_as_identifier() {}
760
761 /// ```compile_fail
762 /// use pastey::paste;
763 /// paste! { const _: &str = [<fn>]; }
764 /// ```
765 fn test_error_fn_keyword() {}
766
767 /// ```compile_fail
768 /// use pastey::paste;
769 /// paste! { const _: &str = [<match>]; }
770 /// ```
771 fn test_error_match_keyword() {}
772
773 /// ```compile_fail
774 /// use pastey::paste;
775 /// paste! { const _: &str = [<{inner}>]; }
776 /// ```
777 fn test_error_brace_group_in_paste() {}
778
779 /// ```compile_fail
780 /// use pastey::paste;
781 /// paste! { const _: &str = [<(parts)>]; }
782 /// ```
783 fn test_error_paren_group_in_paste() {}
784
785 /// ```compile_fail
786 /// use pastey::paste;
787 /// macro_rules! test {
788 /// () => { paste! { const _: &str = [<&&invalid>]; } }
789 /// }
790 /// test!();
791 /// ```
792 fn test_error_double_ampersand() {}
793
794 /// ```compile_fail
795 /// use pastey::paste;
796 /// macro_rules! test {
797 /// () => { paste! { const _: &str = [<||invalid>]; } }
798 /// }
799 /// test!();
800 /// ```
801 fn test_error_double_pipe() {}
802
803 /// ```compile_fail
804 /// use pastey::paste;
805 /// paste! { const _: &str = [<@#$>]; }
806 /// ```
807 fn test_error_random_special_chars() {}
808
809 /// ```compile_fail
810 /// use pastey::paste;
811 /// paste! { let value: i32 = [<test>]; }
812 /// ```
813 fn test_error_undefined_identifier_value() {}
814
815 /// ```compile_fail
816 /// use pastey::paste;
817 /// paste! { fn doc_err_in_brace() { let _ = [<@>]; } }
818 /// ```
819 fn test_error_invalid_paste_inside_brace_group() {}
820
821 /// ```compile_fail
822 /// use pastey::paste;
823 /// paste! { const _: u32 = [<0 x>]; }
824 /// ```
825 fn test_error_pasted_incomplete_hex_literal() {}
826
827 /// ```compile_fail
828 /// use pastey::paste;
829 /// paste! { #[cfg(test) trailing_token] fn f() {} }
830 /// ```
831 fn test_error_attr_trailing_tokens_after_paren_group() {}
832
833 /// ```compile_fail
834 /// use pastey::paste;
835 /// paste! { struct [<Foo::+Bar>]; }
836 /// ```
837 fn test_error_invalid_colon_sequence() {}
838
839 /// ```compile_fail
840 /// use pastey::paste;
841 /// paste! { fn [<Bar:::Test>]() {} }
842 /// ```
843 fn test_error_invalid_colon_patterns() {}
844
845 /// ```compile_fail
846 /// use pastey::paste;
847 /// paste! { fn [*invalid>]() {} }
848 /// ```
849 fn test_error_bracket_first_token_not_less_than() {}
850
851 /// ```compile_fail
852 /// use pastey::paste;
853 /// paste! { fn [<test]() {} }
854 /// ```
855 fn test_error_bracket_closing_token_not_greater_than() {}
856
857 /// ```compile_fail
858 /// use pastey::paste;
859 /// paste! { fn [<test>extra]() {} }
860 /// ```
861 fn test_error_extra_tokens_after_bracket() {}
862
863 /// ```compile_fail
864 /// use pastey::paste;
865 /// paste! { fn [<test:replace('\u{XY}', 'A')>]() {} }
866 /// ```
867 fn test_error_invalid_hex_unicode() {}
868
869 /// ```
870 /// use pastey::paste;
871 /// macro_rules! test_replace {
872 /// ($a:expr, $b:expr) => {
873 /// paste! { concat!(stringify!($a), stringify!($b)) }
874 /// }
875 /// }
876 /// let result = test_replace!(x, "y");
877 /// ```
878 fn test_macro_group_flattening() {}
879
880 /// ```
881 /// use pastey::paste;
882 /// paste! { fn [<foo_bar>]() {} }
883 /// foo_bar();
884 /// ```
885 fn test_valid_paste_operation() {}
886
887 /// ```
888 /// use pastey::paste;
889 /// paste! { use std::[<vec>]; }
890 /// let v = Vec::<i32>::new();
891 /// assert_eq!(v.len(), 0);
892 /// ```
893 fn test_valid_path_with_double_colon() {}
894
895 /// ```
896 /// use pastey::paste;
897 /// macro_rules! concat_name {
898 /// ($name:ident) => {
899 /// paste! { const [<$name:lower>]: &str = stringify!($name); }
900 /// }
901 /// }
902 /// concat_name!(TEST);
903 /// ```
904 fn test_valid_modifiers() {}
905
906 /// ```
907 /// use pastey::paste;
908 /// macro_rules! test_ident_colon {
909 /// ($param:ident: $ty:ident) => {
910 /// paste! { fn [<test_$param>]($param: $ty) {} }
911 /// }
912 /// }
913 /// test_ident_colon!(x: i32);
914 /// test_x(42i32);
915 /// ```
916 fn test_type_annotation() {}
917}