Debian Codegraph @

src/clone.rs

raw symbols SCIP
1 // Take a look at the license at the top of the repository in the LICENSE file.
2
3 use proc_macro2rust-analyzer cargo proc-macro2 1.0.106 crate/::{Identrust-analyzer cargo proc-macro2 1.0.106 Ident#, Spanrust-analyzer cargo proc-macro2 1.0.106 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#};
4 use quoterust-analyzer cargo quote 1.0.44 crate/::{ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#, quoterust-analyzer cargo quote 1.0.44 quote!};
5 use synrust-analyzer cargo syn 2.0.117 crate/::{
6 Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#, Exprrust-analyzer cargo syn 2.0.117 expr/Expr#, ExprAsyncrust-analyzer cargo syn 2.0.117 expr/ExprAsync#, ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure#, Tokenrust-analyzer cargo syn 2.0.117 token/Token!,
7 parserust-analyzer cargo syn 2.0.117 parse/::{Parserust-analyzer cargo syn 2.0.117 parse/Parse#, ParseStreamrust-analyzer cargo syn 2.0.117 parse/ParseStream#},
8 spannedrust-analyzer cargo syn 2.0.117 spanned/::Spannedrust-analyzer cargo syn 2.0.117 spanned/Spanned#,
9 };
10
11 use craterust-analyzer cargo glib-macros 0.22.6 crate/::utilsrust-analyzer cargo glib-macros 0.22.6 utils/::crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new().;
12
13 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
14 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) enum CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind# {
15 Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch#,
16 Weakrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Weak#,
17 WeakAllowNonerust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#WeakAllowNone#,
18 Strongrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Strong#,
19 ToOwnedrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#ToOwned#,
20 }
21
22 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<&'_ Identrust-analyzer cargo proc-macro2 1.0.106 Ident#> for CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind# {
23 type Errorrust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`TryFrom<&Ident>`]Error# = synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#;
24
25 fn try_fromrust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`TryFrom<&Ident>`]try_from().(s: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`TryFrom<&Ident>`], Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`TryFrom<&Ident>`]::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#Error#> {
26 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
27 "watch" => CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch#,
28 "strong" => CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Strongrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Strong#,
29 "weak" => CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Weakrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Weak#,
30 "weak_allow_none" => CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::WeakAllowNonerust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#WeakAllowNone#,
31 "to_owned" => CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::ToOwnedrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#ToOwned#,
32 _ => {
33 // This is actually never shown to the user but we need some kind of error type for
34 // TryFrom, () would be enough but then clippy complains.
35 //
36 // We'll keep it here in case it is useful somewhere at a later time.
37 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::newrust-analyzer cargo syn 2.0.117 error/impl#[Error]new().(
38 s.spanrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]span().(),
39 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("unknown capture type `{s}`"),
40 ));
41 }
42 })
43 }
44 }
45
46 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
47 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) enum UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour# {
48 #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:]
49 Unitrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Unit#,
50 Panicrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Panic#,
51 Defaultrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Default#,
52 Expressionrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Expression#(Exprrust-analyzer cargo syn 2.0.117 expr/Expr#),
53 Closurerust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Closure#(ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure#),
54 }
55
56 impl UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour# {
57 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn maybe_parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[UpgradeBehaviour]maybe_parse().(
58 attrs: &[Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#],
59 input: ParseStreamrust-analyzer cargo syn 2.0.117 parse/ParseStream#,
60 ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[UpgradeBehaviour]>> {
61 // Caller checked for empty
62 let attr = &attrs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
63 attr.metarust-analyzer cargo syn 2.0.117 attr/Attribute#meta..require_path_onlyrust-analyzer cargo syn 2.0.117 attr/impl#[Meta]require_path_only().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
64
65 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr_name) = attr.pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().() else {
66 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
67 };
68
69 let upgrade_behaviour = match attr_name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() {
70 "upgrade_or" => {
71 let expr = input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Exprrust-analyzer cargo syn 2.0.117 expr/Expr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
72 input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
73 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Expressionrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Expression#(expr)
74 }
75 "upgrade_or_else" => {
76 let closure = input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
77 if closure.asyncnessrust-analyzer cargo syn 2.0.117 expr/ExprClosure#asyncness..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
78 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
79 &closure,
80 "`upgrade_or_else` closure needs to be a non-async closure",
81 ));
82 }
83 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().closure.inputsrust-analyzer cargo syn 2.0.117 expr/ExprClosure#inputs..is_emptyrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]is_empty().() {
84 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
85 &closure,
86 "`upgrade_or_else` closure must not have any parameters",
87 ));
88 }
89
90 input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
91 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Closure#(closure)
92 }
93 "upgrade_or_default" => UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Defaultrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Default#,
94 "upgrade_or_panic" => UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Panicrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Panic#,
95 _ => {
96 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
97 }
98 };
99
100 if attrs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() 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().1 {
101 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
102 &attrs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
103 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
104 "upgrade failure attribute must not be followed by any other attributes. Found {} more attribute{}",
105 attrs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1,
106 if attrs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 2 { "s" } else { "" },
107 ),
108 ));
109 }
110
111 let next_attrs = &input.callrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]call().(Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#::parse_outerrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]parse_outer().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
112 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().next_attrs.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
113 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
114 &next_attrs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
115 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
116 "upgrade failure attribute must not be followed by any other attributes. Found {} more attribute{}",
117 next_attrs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
118 if next_attrs.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 1 { "s" } else { "" },
119 ),
120 ));
121 }
122
123 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(upgrade_behaviour))
124 }
125 }
126
127 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) struct Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture# {
128 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) namerust-analyzer cargo glib-macros 0.22.6 clone/Capture#name.: Exprrust-analyzer cargo syn 2.0.117 expr/Expr#,
129 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) aliasrust-analyzer cargo glib-macros 0.22.6 clone/Capture#alias.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Identrust-analyzer cargo proc-macro2 1.0.106 Ident#>,
130 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind.: CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#,
131 }
132
133 impl Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture# {
134 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn maybe_parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]maybe_parse().(
135 attrs: &[Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#],
136 input: ParseStreamrust-analyzer cargo syn 2.0.117 parse/ParseStream#,
137 ) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]>> {
138 // Caller checked for empty
139 let attr = &attrs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
140
141 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(attr_name) = attr.pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().() else {
142 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
143 };
144 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(kind) = CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::try_fromrust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`TryFrom<&Ident>`]try_from().(attr_name) else {
145 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
146 };
147
148 if attrs.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() 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().1 {
149 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
150 &attrs[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
151 "variable capture attributes must be followed by an identifier",
152 ));
153 }
154
155 let mut alias = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
156 if let synrust-analyzer cargo syn 2.0.117 crate/::Metarust-analyzer cargo syn 2.0.117 attr/Meta#::Listrust-analyzer cargo syn 2.0.117 attr/Meta#List#(ref list) = attr.metarust-analyzer cargo syn 2.0.117 attr/Attribute#meta. {
157 list.parse_nested_metarust-analyzer cargo syn 2.0.117 attr/impl#[MetaList]parse_nested_meta().(|meta| {
158 if meta.pathrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]is_ident().("rename_to") {
159 let value = meta.valuerust-analyzer cargo syn 2.0.117 meta/impl#[`ParseNestedMeta<'a>`]value().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
160 let id = value.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Identrust-analyzer cargo proc-macro2 1.0.106 Ident#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
161 if alias.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
162 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.117 meta/impl#[`ParseNestedMeta<'a>`]error().("multiple `rename_to` properties are not allowed"));
163 }
164 alias = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(id);
165 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = meta.pathrust-analyzer cargo syn 2.0.117 meta/ParseNestedMeta#path..get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().() {
166 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
167 meta.errorrust-analyzer cargo syn 2.0.117 meta/impl#[`ParseNestedMeta<'a>`]error().(
168 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
169 "unsupported capture attribute property `{ident}`: only `rename_to` is supported"
170 ),
171 ),
172 );
173 } else {
174 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(meta.errorrust-analyzer cargo syn 2.0.117 meta/impl#[`ParseNestedMeta<'a>`]error().("unsupported capture attribute property"));
175 }
176 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
177 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
178 }
179
180 let name = input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Exprrust-analyzer cargo syn 2.0.117 expr/Expr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
181 match name {
182 Exprrust-analyzer cargo syn 2.0.117 expr/Expr#::Pathrust-analyzer cargo syn 2.0.117 expr/Expr#Path#(ref p) if p.pathrust-analyzer cargo syn 2.0.117 expr/ExprPath#path..get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() => {
183 if p.pathrust-analyzer cargo syn 2.0.117 expr/ExprPath#path..get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."self" && alias.is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
184 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
185 attr,
186 "capture attribute for `self` requires usage of the `rename_to` attribute property",
187 ));
188 }
189 // Nothing to do, it's just an identifier
190 }
191 _ if alias.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() => {
192 // Nothing to do, it's an alias
193 }
194 _ => {
195 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
196 attr,
197 "capture attribute for an expression requires usage of the `rename_to` attribute property",
198 ));
199 }
200 }
201
202 input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
203
204 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture# { namerust-analyzer cargo glib-macros 0.22.6 clone/Capture#name., aliasrust-analyzer cargo glib-macros 0.22.6 clone/Capture#alias., kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. }))
205 }
206
207 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn aliasrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]alias().(&self) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
208 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref alias) = self.aliasrust-analyzer cargo glib-macros 0.22.6 clone/Capture#alias. {
209 alias.to_token_streamrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#to_token_stream().()
210 } else {
211 self.namerust-analyzer cargo glib-macros 0.22.6 clone/Capture#name..to_token_streamrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#to_token_stream().()
212 }
213 }
214
215 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn outer_before_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]outer_before_tokens().(&self, crate_ident: &TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
216 let alias = self.aliasrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]alias().();
217 let name = &self.namerust-analyzer cargo glib-macros 0.22.6 clone/Capture#name.;
218 match self.kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. {
219 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch# => quoterust-analyzer cargo quote 1.0.44 quote!! {
220 let #alias = #crate_ident::object::Watchable::watched_object(&#name);
221 },
222 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Weakrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Weak# | CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::WeakAllowNonerust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#WeakAllowNone# => quoterust-analyzer cargo quote 1.0.44 quote!! {
223 let #alias = #crate_ident::clone::Downgrade::downgrade(&#name);
224 },
225 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Strongrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Strong# => quoterust-analyzer cargo quote 1.0.44 quote!! {
226 let #alias = #name.clone();
227 },
228 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::ToOwnedrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#ToOwned# => quoterust-analyzer cargo quote 1.0.44 quote!! {
229 let #alias = ::std::borrow::ToOwned::to_owned(&*#name);
230 },
231 }
232 }
233
234 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn outer_after_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]outer_after_tokens().(
235 &self,
236 crate_ident: &TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#,
237 closure_ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#,
238 ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
239 let name = &self.namerust-analyzer cargo glib-macros 0.22.6 clone/Capture#name.;
240 match self.kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. {
241 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch# => quoterust-analyzer cargo quote 1.0.44 quote!! {
242 #crate_ident::object::Watchable::watch_closure(&#name, &#closure_ident);
243 },
244 _ => Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo proc-macro2 1.0.106 impl#[TokenStream][Default]default().(),
245 }
246 }
247
248 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn inner_before_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]inner_before_tokens().(
249 &self,
250 crate_ident: &TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#,
251 weak_upgrade_failure_kind: &UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#,
252 upgrade_failure_closure_ident: &Identrust-analyzer cargo proc-macro2 1.0.106 Ident#,
253 unit_return: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#>,
254 ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream# {
255 let alias = self.aliasrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]alias().();
256 match self.kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. {
257 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch# => {
258 quoterust-analyzer cargo quote 1.0.44 quote!! {
259 let #alias = unsafe { #alias.borrow() };
260 let #alias = ::core::convert::AsRef::as_ref(&#alias);
261 }
262 }
263 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Weakrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Weak# => match weak_upgrade_failure_kind {
264 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Panicrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Panic# => {
265 let err_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
266 "Failed to upgrade `{alias}`. If you don't want to panic, use `#[upgrade_or]`, `#[upgrade_or_else]` or `#[upgrade_or_default]`",
267 );
268 quoterust-analyzer cargo quote 1.0.44 quote!! {
269 let Some(#alias) = #crate_ident::clone::Upgrade::upgrade(&#alias) else {
270 panic!(#err_msg);
271 };
272 }
273 }
274 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Defaultrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Default#
275 | UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Expressionrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Expression#(_)
276 | UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Closure#(_) => {
277 let err_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to upgrade `{alias}`");
278 quoterust-analyzer cargo quote 1.0.44 quote!! {
279 let Some(#alias) = #crate_ident::clone::Upgrade::upgrade(&#alias) else {
280 #crate_ident::g_debug!(
281 #crate_ident::CLONE_MACRO_LOG_DOMAIN,
282 #err_msg,
283 );
284 return (#upgrade_failure_closure_ident)();
285 };
286 }
287 }
288 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Unitrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Unit# => {
289 let err_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to upgrade `{alias}`");
290 let unit_return = unit_return.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| {
291 quoterust-analyzer cargo quote 1.0.44 quote!! { return; }
292 });
293 quoterust-analyzer cargo quote 1.0.44 quote!! {
294 let Some(#alias) = #crate_ident::clone::Upgrade::upgrade(&#alias) else {
295 #crate_ident::g_debug!(
296 #crate_ident::CLONE_MACRO_LOG_DOMAIN,
297 #err_msg,
298 );
299 #unit_return
300 };
301 }
302 }
303 },
304 CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::WeakAllowNonerust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#WeakAllowNone# => quoterust-analyzer cargo quote 1.0.44 quote!! {
305 let #alias = #crate_ident::clone::Upgrade::upgrade(&#alias);
306 },
307 _ => Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo proc-macro2 1.0.106 impl#[TokenStream][Default]default().(),
308 }
309 }
310 }
311
312 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
313 enum ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync# {
314 Closurerust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Closure#(ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure#),
315 Asyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Async#(ExprAsyncrust-analyzer cargo syn 2.0.117 expr/ExprAsync#),
316 }
317
318 impl Parserust-analyzer cargo syn 2.0.117 parse/Parse# for ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync# {
319 fn parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[ClosureOrAsync][Parse]parse().(input: ParseStreamrust-analyzer cargo syn 2.0.117 parse/ParseStream#) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[ClosureOrAsync][Parse]> {
320 let expr = input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Exprrust-analyzer cargo syn 2.0.117 expr/Expr#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
321 match expr {
322 Exprrust-analyzer cargo syn 2.0.117 expr/Expr#::Asyncrust-analyzer cargo syn 2.0.117 expr/Expr#Async#(async_) => {
323 if async_.capturerust-analyzer cargo syn 2.0.117 expr/ExprAsync#capture..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
324 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
325 async_,
326 "async blocks need to capture variables by move. Please add the `move` keyword",
327 ));
328 }
329
330 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Asyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Async#(async_))
331 }
332 Exprrust-analyzer cargo syn 2.0.117 expr/Expr#::Closurerust-analyzer cargo syn 2.0.117 expr/Expr#Closure#(closure) => {
333 if closure.capturerust-analyzer cargo syn 2.0.117 expr/ExprClosure#capture..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
334 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
335 closure,
336 "closures need to capture variables by move. Please add the `move` keyword",
337 ));
338 }
339
340 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Closure#(closure))
341 }
342 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
343 expr,
344 "only closures and async blocks are supported",
345 )),
346 }
347 }
348 }
349
350 impl ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens# for ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync# {
351 fn to_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[ClosureOrAsync][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#) {
352 match self {
353 ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Closure#(c) => c.to_tokensrust-analyzer cargo syn 2.0.117 expr/printing/impl#[ExprClosure][ToTokens]to_tokens().(tokens),
354 ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Asyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Async#(a) => a.to_tokensrust-analyzer cargo syn 2.0.117 expr/printing/impl#[ExprAsync][ToTokens]to_tokens().(tokens),
355 }
356 }
357 }
358
359 struct Clonerust-analyzer cargo glib-macros 0.22.6 clone/Clone# {
360 capturesrust-analyzer cargo glib-macros 0.22.6 clone/Clone#captures.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture#>,
361 upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 clone/Clone#upgrade_behaviour.: UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#,
362 bodyrust-analyzer cargo glib-macros 0.22.6 clone/Clone#body.: ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#,
363 }
364
365 impl Parserust-analyzer cargo syn 2.0.117 parse/Parse# for Clonerust-analyzer cargo glib-macros 0.22.6 clone/Clone# {
366 fn parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[Clone][Parse]parse().(input: ParseStreamrust-analyzer cargo syn 2.0.117 parse/ParseStream#) -> synrust-analyzer cargo syn 2.0.117 crate/::Resultrust-analyzer cargo syn 2.0.117 error/Result#<Selfrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Clone][Parse]> {
367 if input.is_emptyrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]is_empty().() {
368 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::newrust-analyzer cargo syn 2.0.117 error/impl#[Error]new().(
369 Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().(),
370 "expected a closure or async block",
371 ));
372 }
373
374 let mut captures: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture#> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
375 let mut upgrade_behaviour: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#, Spanrust-analyzer cargo proc-macro2 1.0.106 Span#)> = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
376
377 loop {
378 // There must either be one or no attributes here. Multiple attributes are not
379 // supported.
380 //
381 // If this is a capture attribute, it must be followed by an identifier.
382 // If this is an upgrade failure attribute, it might be followed by a closure. After the
383 // upgrade failure attribute there must not be any further attributes.
384 //
385 // If this is not an attribute then it is a closure, async closure or async block which
386 // is handled outside the loop
387 let attrs = input.callrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]call().(Attributerust-analyzer cargo syn 2.0.117 attr/Attribute#::parse_outerrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]parse_outer().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
388 if attrs.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
389 break;
390 };
391
392 match Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture#::maybe_parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]maybe_parse().(&attrs, input)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
393 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(capture) => {
394 if capture.kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. rust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`PartialEq<Self>`]eq().==rust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`PartialEq<Self>`]eq(). rust-analyzer cargo glib-macros 0.22.6 clone/impl#[CaptureKind][`PartialEq<Self>`]eq().CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Watchrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Watch# {
395 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
396 &attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().,
397 "watch variable captures are not supported",
398 ));
399 }
400
401 captures.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(capture);
402 }
403 _ => match UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::maybe_parserust-analyzer cargo glib-macros 0.22.6 clone/impl#[UpgradeBehaviour]maybe_parse().(&attrs, input)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
404 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(behaviour) => {
405 if upgrade_behaviour.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
406 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
407 &attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().,
408 "multiple upgrade failure attributes are not supported",
409 ));
410 }
411
412 upgrade_behaviour = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((behaviour, attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..spanrust-analyzer cargo syn 2.0.117 spanned/impl#[T][Spanned]span().()));
413 break;
414 }
415 _ => {
416 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) = attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..pathrust-analyzer cargo syn 2.0.117 attr/impl#[Attribute]path().().get_identrust-analyzer cargo syn 2.0.117 path/impl#[Path]get_ident().() {
417 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
418 &attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().,
419 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
420 "unsupported attribute `{ident}`: only `strong`, `weak`, `weak_allow_none`, `to_owned`, `upgrade_or`, `upgrade_or_else`, `upgrade_or_default` and `upgrade_or_panic` are supported",
421 ),
422 ));
423 } else {
424 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().(
425 &attrs[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().,
426 "unsupported attribute: only `strong`, `weak`, `weak_allow_none`, `to_owned`, `upgrade_or_else`, `upgrade_or_default` and `upgrade_or_panic` are supported",
427 ));
428 }
429 }
430 },
431 }
432 }
433
434 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, ref span)) = upgrade_behaviour
435 && captures.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|c| c.kindrust-analyzer cargo glib-macros 0.22.6 clone/Capture#kind. 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().CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#::Weakrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#Weak#)
436 {
437 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::newrust-analyzer cargo syn 2.0.117 error/impl#[Error]new().(
438 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().span,
439 "upgrade failure attribute can only be used together with weak variable captures",
440 ));
441 }
442
443 let upgrade_behaviour = upgrade_behaviour.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|x| x.0).unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().();
444
445 // Following is a closure or async block
446 let body = input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
447
448 // Trailing comma, if any
449 if input.peekrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]peek().(Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]) {
450 input.parserust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]parse().::<Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
451 }
452
453 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Clonerust-analyzer cargo glib-macros 0.22.6 clone/Clone# {
454 capturesrust-analyzer cargo glib-macros 0.22.6 clone/Clone#captures.,
455 upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 clone/Clone#upgrade_behaviour.,
456 bodyrust-analyzer cargo glib-macros 0.22.6 clone/Clone#body.,
457 })
458 }
459 }
460
461 impl ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens# for Clonerust-analyzer cargo glib-macros 0.22.6 clone/Clone# {
462 fn to_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Clone][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#) {
463 let crate_ident = crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new().();
464
465 let upgrade_failure_closure_ident =
466 Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("____upgrade_failure_closure", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().());
467
468 let outer_before = self
469 .capturesrust-analyzer cargo glib-macros 0.22.6 clone/Clone#captures.
470 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
471 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.outer_before_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]outer_before_tokens().(&crate_ident));
472 let inner_before = self.capturesrust-analyzer cargo glib-macros 0.22.6 clone/Clone#captures..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| {
473 c.inner_before_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]inner_before_tokens().(
474 &crate_ident,
475 &self.upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 clone/Clone#upgrade_behaviour.,
476 &upgrade_failure_closure_ident,
477 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
478 )
479 });
480
481 let upgrade_failure_closure = match self.upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 clone/Clone#upgrade_behaviour. {
482 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Defaultrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Default# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.44 quote!! {
483 let #upgrade_failure_closure_ident = ::std::default::Default::default;
484 }),
485 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Expressionrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Expression#(ref expr) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.44 quote!! {
486 let #upgrade_failure_closure_ident = move || {
487 #expr
488 };
489 }),
490 UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Closure#(ref closure) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.44 quote!! {
491 let #upgrade_failure_closure_ident = #closure;
492 }),
493 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
494 };
495
496 let body = match self.bodyrust-analyzer cargo glib-macros 0.22.6 clone/Clone#body. {
497 ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Closure#(ref c) => {
498 let ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure# {
499 attrsrust-analyzer cargo syn 2.0.117 expr/ExprClosure#attrs.,
500 lifetimesrust-analyzer cargo syn 2.0.117 expr/ExprClosure#lifetimes.,
501 constnessrust-analyzer cargo syn 2.0.117 expr/ExprClosure#constness.,
502 movabilityrust-analyzer cargo syn 2.0.117 expr/ExprClosure#movability.,
503 asyncnessrust-analyzer cargo syn 2.0.117 expr/ExprClosure#asyncness.,
504 capturerust-analyzer cargo syn 2.0.117 expr/ExprClosure#capture.,
505 or1_tokenrust-analyzer cargo syn 2.0.117 expr/ExprClosure#or1_token.,
506 inputsrust-analyzer cargo syn 2.0.117 expr/ExprClosure#inputs.,
507 or2_tokenrust-analyzer cargo syn 2.0.117 expr/ExprClosure#or2_token.,
508 outputrust-analyzer cargo syn 2.0.117 expr/ExprClosure#output.,
509 bodyrust-analyzer cargo syn 2.0.117 expr/ExprClosure#body.,
510 } = c;
511
512 quoterust-analyzer cargo quote 1.0.44 quote!! {
513 #(#attrs)*
514 #lifetimes
515 #constness
516 #movability
517 #asyncness
518 #capture
519 #or1_token
520 #inputs
521 #or2_token
522 #output
523 {
524 #upgrade_failure_closure
525 #(#inner_before)*
526 #body
527 }
528 }
529 }
530 ClosureOrAsyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#::Asyncrust-analyzer cargo glib-macros 0.22.6 clone/ClosureOrAsync#Async#(ref a) => {
531 let ExprAsyncrust-analyzer cargo syn 2.0.117 expr/ExprAsync# {
532 attrsrust-analyzer cargo syn 2.0.117 expr/ExprAsync#attrs.,
533 async_tokenrust-analyzer cargo syn 2.0.117 expr/ExprAsync#async_token.,
534 capturerust-analyzer cargo syn 2.0.117 expr/ExprAsync#capture.,
535 blockrust-analyzer cargo syn 2.0.117 expr/ExprAsync#block.,
536 } = a;
537
538 // Directly output the statements instead of the whole block including braces as we
539 // already produce a block with braces below and otherwise a compiler warning about
540 // unnecessary braces is wrongly emitted.
541 let stmts = &block.stmtsrust-analyzer cargo syn 2.0.117 stmt/Block#stmts.;
542
543 quoterust-analyzer cargo quote 1.0.44 quote!! {
544 #(#attrs)*
545 #async_token
546 #capture
547 {
548 #upgrade_failure_closure
549 #(#inner_before)*
550 #(#stmts)*
551 }
552 }
553 }
554 };
555
556 tokens.extendrust-analyzer cargo proc-macro2 1.0.106 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.44 quote!! {
557 {
558 #(#outer_before)*
559 #body
560 }
561 });
562 }
563 }
564
565 pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn clone_innerrust-analyzer cargo glib-macros 0.22.6 clone/clone_inner().(input: proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
566 let clone = synrust-analyzer cargo syn 2.0.117 crate/::parse_macro_inputrust-analyzer cargo syn 2.0.117 parse_macro_input/parse_macro_input!!(input as Clonerust-analyzer cargo glib-macros 0.22.6 clone/Clone#);
567 clone.into_token_streamrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#into_token_stream().().intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
568 }