Debian Codegraph @

src/attr.rs

raw symbols SCIP
1 use craterust-analyzer cargo pastey 0.2.3 crate/::errorrust-analyzer cargo pastey 0.2.3 error/::Resultrust-analyzer cargo pastey 0.2.3 error/Result#;
2 use craterust-analyzer cargo pastey 0.2.3 crate/::segmentrust-analyzer cargo pastey 0.2.3 segment/::{selfrust-analyzer cargo pastey 0.2.3 segment/, Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#};
3 use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::{Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#, Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Group#, Spacingrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#, Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#};
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/;
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
7
8 pub fn expand_attrrust-analyzer cargo pastey 0.2.3 attr/expand_attr().(
9 attr: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#,
10 span: Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#,
11 contains_paste: &mut bool,
12 ) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#> {
13 let mut tokens = attr.clonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][Clone]clone().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().();
14 let mut leading_colons = 0; // $(::)?
15 let mut leading_path = 0; // $($ident)::+
16
17 let mut token;
18 let group = loop {
19 token = tokens.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().();
20 match token {
21 // colon after `$(:)?`
22 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(ref punct))
23 if punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().':' && leading_colons rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().2 && leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 =>
24 {
25 leading_colons rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
26 }
27 // ident after `$(::)? $($ident ::)*`
28 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Ident#(_)) if leading_colons rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().1 && leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 => {
29 leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
30 }
31 // colon after `$(::)? $($ident ::)* $ident $(:)?`
32 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(ref punct)) if punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().':' && leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 => {
33 leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
34 }
35 // eq+value after `$(::)? $($ident)::+`
36 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(ref punct))
37 if punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'=' && leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 =>
38 {
39 let mut count = 0;
40 if tokens.inspectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#inspect().(|_| count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1).allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|tt| is_stringlikerust-analyzer cargo pastey 0.2.3 attr/is_stringlike().(&tt)) && count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().1 {
41 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().contains_paste = true;
42 let leading = leading_colons rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().leading_path;
43 return do_paste_name_value_attrrust-analyzer cargo pastey 0.2.3 attr/do_paste_name_value_attr().(attr, span, leading);
44 }
45 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(attr);
46 }
47 // parens after `$(::)? $($ident)::+`
48 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(ref group))
49 if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Parenthesisrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#Parenthesis# && leading_path rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 =>
50 {
51 break group;
52 }
53 // bail out
54 _ => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(attr),
55 }
56 };
57
58 // There can't be anything else after the first group in a valid attribute.
59 if tokens.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
60 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(attr);
61 }
62
63 let mut group_contains_paste = false;
64 let mut expanded = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().();
65 let mut nested_attr = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().();
66 for tt in group.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().() {
67 match &tt {
68 TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct) if punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().',' => {
69 expanded.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(expand_attrrust-analyzer cargo pastey 0.2.3 attr/expand_attr().(
70 nested_attr,
71 group.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(),
72 &mut group_contains_paste,
73 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
74 expanded.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(tt));
75 nested_attr = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().();
76 }
77 _ => nested_attr.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(tt)),
78 }
79 }
80
81 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().nested_attr.is_emptyrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]is_empty().() {
82 expanded.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(expand_attrrust-analyzer cargo pastey 0.2.3 attr/expand_attr().(
83 nested_attr,
84 group.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(),
85 &mut group_contains_paste,
86 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
87 }
88
89 if group_contains_paste {
90 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().contains_paste = true;
91 let mut group = Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Group#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]new().(Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Parenthesisrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#Parenthesis#, expanded);
92 group.set_spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]set_span().(span);
93 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(attr
94 .into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().()
95 // Just keep the initial ident in `#[ident(...)]`.
96 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(leading_colons rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().leading_path)
97 .chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group)))
98 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().())
99 } else {
100 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(attr)
101 }
102 }
103
104 fn do_paste_name_value_attrrust-analyzer cargo pastey 0.2.3 attr/do_paste_name_value_attr().(attr: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, span: Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, leading: usize) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#> {
105 let mut expanded = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().();
106 let mut tokens = attr.into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
107 expanded.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(tokens.by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#by_ref().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(leading rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1)); // `doc =`
108
109 let mut segments = segmentrust-analyzer cargo pastey 0.2.3 segment/::parserust-analyzer cargo pastey 0.2.3 segment/parse().(&mut tokens)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
110
111 for segment in &mut segments {
112 if let Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(string) = segment {
113 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(open_quote) = string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('"') {
114 if open_quote rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
115 string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]truncate().(string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1);
116 string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]remove().(0);
117 } else {
118 let begin = open_quote rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
119 let end = string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().('"').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
120 let raw_string = memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.);
121 for ch in raw_string[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().begin..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()..charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
122 string.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Extend<char>`]extend().(ch.escape_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]escape_default().());
123 }
124 }
125 }
126 }
127 }
128
129 let mut lit = segmentrust-analyzer cargo pastey 0.2.3 segment/::pasterust-analyzer cargo pastey 0.2.3 segment/paste().(&segments)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
130
131 if lit.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("r#") {
132 // Raw mode doesn't have any impact when using in attribute
133 lit.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]remove().(0);
134 lit.removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]remove().(0);
135 }
136
137 lit.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]insert().(0, '"');
138 lit.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('"');
139
140 let mut lit = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::from_strrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][FromStr]from_str().(&lit)
141 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
142 .into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().()
143 .nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().()
144 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
145 lit.set_spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]set_span().(span);
146 expanded.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(lit));
147 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(expanded)
148 }
149
150 fn is_stringlikerust-analyzer cargo pastey 0.2.3 attr/is_stringlike().(token: &TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#) -> bool {
151 match token {
152 TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Ident#(_) => true,
153 TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Literal#(literal) => {
154 let repr = literal.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
155 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repr.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('b') && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().repr.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('\'')
156 }
157 TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group) => {
158 if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Nonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#None# {
159 return false;
160 }
161 let mut inner = group.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().();
162 match inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().() {
163 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) => inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() && is_stringlikerust-analyzer cargo pastey 0.2.3 attr/is_stringlike().(&first),
164 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => false,
165 }
166 }
167 TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct) => {
168 punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\'' || punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().':' && punct.spacingrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]spacing().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Spacing][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Spacing][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Spacing][`PartialEq<Self>`]eq().Spacingrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#::Alonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Spacing#Alone#
169 }
170 }
171 }
172
173 #[cfg(doctest)]
174 #[doc(hidden)]
175 mod doc_tests {
176 /// ```
177 /// use pastey::paste;
178 /// paste! {
179 /// #[doc = "Hello " "World"]
180 /// pub struct DocStringPaste;
181 /// }
182 /// ```
183 fn test_doc_string_paste() {}
184
185 /// ```
186 /// use pastey::paste;
187 /// paste! {
188 /// #[doc = "hello"]
189 /// pub struct DocSingleToken;
190 /// }
191 /// ```
192 fn test_doc_single_token() {}
193
194 /// ```
195 /// use pastey::paste;
196 /// paste! {
197 /// #[derive(Clone, Copy)]
198 /// struct DocDeriveAttr(u8);
199 /// }
200 /// ```
201 fn test_derive_attr_in_paste() {}
202
203 /// ```
204 /// use pastey::paste;
205 /// paste! {
206 /// #[cfg_attr(not(all()), allow([<foo bar>]))]
207 /// pub struct DocPasteInAttr;
208 /// }
209 /// ```
210 fn test_paste_in_attr_paren() {}
211
212 /// ```
213 /// use pastey::paste;
214 /// paste! {
215 /// #[cfg_attr(not(all()), ::foo::bar(baz))]
216 /// pub struct DocAbsPath;
217 /// }
218 /// ```
219 fn test_absolute_path_attr() {}
220
221 /// ```
222 /// use pastey::paste;
223 /// paste! {
224 /// #[doc = r"Hello " "World"]
225 /// pub struct DocRawStr;
226 /// }
227 /// ```
228 fn test_raw_str_doc_attr() {}
229
230 /// ```
231 /// use pastey::paste;
232 /// macro_rules! m {
233 /// ($val:ident) => {
234 /// paste! {
235 /// #[cfg_attr(not(all()), allow(ident = $val "world"))]
236 /// pub struct DocNoneGroupStringlike;
237 /// }
238 /// }
239 /// }
240 /// m!(hello);
241 /// ```
242 fn test_none_group_stringlike() {}
243
244 /// ```
245 /// use pastey::paste;
246 /// macro_rules! with_doc_path {
247 /// ($m:ident) => {
248 /// paste! {
249 /// #[doc = stringify!($m::Item)]
250 /// pub fn doc_none_group_before_double_colon() {}
251 /// }
252 /// }
253 /// }
254 /// ///
255 /// with_doc_path!(my_mod);
256 /// doc_none_group_before_double_colon();
257 /// ```
258 fn test_none_group_before_double_colon_in_attr_context() {}
259 }