| 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#, 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/::{ |
| 12 | clonerust-analyzer cargo glib-macros 0.22.6 clone/::{Capturerust-analyzer cargo glib-macros 0.22.6 clone/Capture#, CaptureKindrust-analyzer cargo glib-macros 0.22.6 clone/CaptureKind#, UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#}, |
| 13 | utilsrust-analyzer cargo glib-macros 0.22.6 utils/::crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new()., |
| 14 | }; |
| 15 | |
| 16 | struct Closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure# { |
| 17 | capturesrust-analyzer cargo glib-macros 0.22.6 closure/Closure#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#>, |
| 18 | argsrust-analyzer cargo glib-macros 0.22.6 closure/Closure#args.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Identrust-analyzer cargo proc-macro2 1.0.106 Ident#>, |
| 19 | upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 closure/Closure#upgrade_behaviour.: UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#, |
| 20 | closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure#closure.: ExprClosurerust-analyzer cargo syn 2.0.117 expr/ExprClosure#, |
| 21 | constructorrust-analyzer cargo glib-macros 0.22.6 closure/Closure#constructor.: &'static str, |
| 22 | } |
| 23 | |
| 24 | impl Parserust-analyzer cargo syn 2.0.117 parse/Parse# for Closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure# { |
| 25 | fn parserust-analyzer cargo glib-macros 0.22.6 closure/impl#[Closure][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 closure/impl#[Closure][Parse]> { |
| 26 | if input.is_emptyrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]is_empty().() { |
| 27 | 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().(Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().(), "expected a closure")); |
| 28 | } |
| 29 | |
| 30 | 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!![]; |
| 31 | 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#; |
| 32 | |
| 33 | loop { |
| 34 | // There must either be one or no attributes here. Multiple attributes are not |
| 35 | // supported. |
| 36 | // |
| 37 | // If this is a capture attribute, it must be followed by an identifier. |
| 38 | // If this is an upgrade failure attribute, it might be followed by a closure. After the |
| 39 | // upgrade failure attribute there must not be any further attributes. |
| 40 | // |
| 41 | // If this is not an attribute then it is a closure, async closure or async block which |
| 42 | // is handled outside the loop |
| 43 | 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().; |
| 44 | if attrs.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 45 | break; |
| 46 | }; |
| 47 | |
| 48 | 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(). { |
| 49 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(capture) => { |
| 50 | 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# |
| 51 | && captures.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|c| c.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#) |
| 52 | { |
| 53 | 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().( |
| 54 | &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()., |
| 55 | "only one `watch` capture is allowed per closure", |
| 56 | )); |
| 57 | } |
| 58 | |
| 59 | captures.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(capture); |
| 60 | } |
| 61 | _ => 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(). { |
| 62 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(behaviour) => { |
| 63 | if upgrade_behaviour.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 64 | 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().( |
| 65 | &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()., |
| 66 | "multiple upgrade failure attributes are not supported", |
| 67 | )); |
| 68 | } |
| 69 | |
| 70 | 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().())); |
| 71 | break; |
| 72 | } |
| 73 | _ => { |
| 74 | 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().() { |
| 75 | 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().( |
| 76 | &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()., |
| 77 | formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 78 | "unsupported attribute `{ident}`: only `watch`, `strong`, `weak`, `weak_allow_none`, `to_owned`, `upgrade_or`, `upgrade_or_else`, `upgrade_or_default` and `upgrade_or_panic` are supported", |
| 79 | ), |
| 80 | )); |
| 81 | } else { |
| 82 | 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().( |
| 83 | &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()., |
| 84 | "unsupported attribute: only `strong`, `weak`, `weak_allow_none`, `to_owned`, `upgrade_or_else`, `upgrade_or_default` and `upgrade_or_panic` are supported", |
| 85 | )); |
| 86 | } |
| 87 | } |
| 88 | }, |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((_, ref span)) = upgrade_behaviour |
| 93 | && 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#) |
| 94 | { |
| 95 | 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().( |
| 96 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().span, |
| 97 | "upgrade failure attribute can only be used together with weak variable captures", |
| 98 | )); |
| 99 | } |
| 100 | |
| 101 | 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().(); |
| 102 | |
| 103 | let mut 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().; |
| 104 | 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().() { |
| 105 | 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().( |
| 106 | closure, |
| 107 | "async closures not supported", |
| 108 | )); |
| 109 | } |
| 110 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().captures.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() && 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().() { |
| 111 | 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().( |
| 112 | closure, |
| 113 | "closures need to capture variables by move. Please add the `move` keyword", |
| 114 | )); |
| 115 | } |
| 116 | closure.capturerust-analyzer cargo syn 2.0.117 expr/ExprClosure#capture. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 117 | |
| 118 | let args = closure |
| 119 | .inputsrust-analyzer cargo syn 2.0.117 expr/ExprClosure#inputs. |
| 120 | .iterrust-analyzer cargo syn 2.0.117 punctuated/impl#[`Punctuated<T, P>`]iter().() |
| 121 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 122 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, _)| Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("____value{i}"), Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().())) |
| 123 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 124 | |
| 125 | // Trailing comma, if any |
| 126 | if input.peekrust-analyzer cargo syn 2.0.117 parse/impl#[`ParseBuffer<'a>`]peek().(Tokenrust-analyzer cargo syn 2.0.117 token/Token!![,]) { |
| 127 | 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().; |
| 128 | } |
| 129 | |
| 130 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure# { |
| 131 | capturesrust-analyzer cargo glib-macros 0.22.6 closure/Closure#captures., |
| 132 | argsrust-analyzer cargo glib-macros 0.22.6 closure/Closure#args., |
| 133 | upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 closure/Closure#upgrade_behaviour., |
| 134 | closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure#closure., |
| 135 | constructorrust-analyzer cargo glib-macros 0.22.6 closure/Closure#constructor.: "new", |
| 136 | }) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | impl ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens# for Closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure# { |
| 141 | fn to_tokensrust-analyzer cargo glib-macros 0.22.6 closure/impl#[Closure][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.106 TokenStream#) { |
| 142 | let crate_ident = crate_ident_newrust-analyzer cargo glib-macros 0.22.6 utils/crate_ident_new().(); |
| 143 | |
| 144 | let closure_ident = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("____closure", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 145 | let values_ident = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("____values", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 146 | let upgrade_failure_closure_ident = |
| 147 | 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().()); |
| 148 | let upgrade_failure_closure_wrapped_ident = |
| 149 | Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().("____upgrade_failure_closure_wrapped", Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 150 | |
| 151 | let outer_before = self |
| 152 | .capturesrust-analyzer cargo glib-macros 0.22.6 closure/Closure#captures. |
| 153 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 154 | .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)); |
| 155 | let inner_before = self.capturesrust-analyzer cargo glib-macros 0.22.6 closure/Closure#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| { |
| 156 | c.inner_before_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]inner_before_tokens().( |
| 157 | &crate_ident, |
| 158 | &self.upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 closure/Closure#upgrade_behaviour., |
| 159 | &upgrade_failure_closure_wrapped_ident, |
| 160 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 161 | return #crate_ident::closure::IntoClosureReturnValue::into_closure_return_value(()); |
| 162 | }), |
| 163 | ) |
| 164 | }); |
| 165 | let outer_after = self |
| 166 | .capturesrust-analyzer cargo glib-macros 0.22.6 closure/Closure#captures. |
| 167 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 168 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| c.outer_after_tokensrust-analyzer cargo glib-macros 0.22.6 clone/impl#[Capture]outer_after_tokens().(&crate_ident, &closure_ident)); |
| 169 | |
| 170 | let arg_values = self.argsrust-analyzer cargo glib-macros 0.22.6 closure/Closure#args..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(index, arg)| { |
| 171 | let err_msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Wrong type for argument {index}: {{:?}}"); |
| 172 | quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 173 | let #arg = ::core::result::Result::unwrap_or_else( |
| 174 | #crate_ident::Value::get(&#values_ident[#index]), |
| 175 | |e| panic!(#err_msg, e), |
| 176 | ); |
| 177 | } |
| 178 | }); |
| 179 | let arg_names = &self.argsrust-analyzer cargo glib-macros 0.22.6 closure/Closure#args.; |
| 180 | let args_len = self.argsrust-analyzer cargo glib-macros 0.22.6 closure/Closure#args..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 181 | let closure = &self.closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure#closure.; |
| 182 | let constructor = Identrust-analyzer cargo proc-macro2 1.0.106 Ident#::newrust-analyzer cargo proc-macro2 1.0.106 impl#[Ident]new().(self.constructorrust-analyzer cargo glib-macros 0.22.6 closure/Closure#constructor., Spanrust-analyzer cargo proc-macro2 1.0.106 Span#::call_siterust-analyzer cargo proc-macro2 1.0.106 impl#[Span]call_site().()); |
| 183 | |
| 184 | let upgrade_failure_closure = match self.upgrade_behaviourrust-analyzer cargo glib-macros 0.22.6 closure/Closure#upgrade_behaviour. { |
| 185 | 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!! { |
| 186 | let #upgrade_failure_closure_ident = ::std::default::Default::default; |
| 187 | let #upgrade_failure_closure_wrapped_ident = || |
| 188 | #crate_ident::closure::IntoClosureReturnValue::into_closure_return_value( |
| 189 | (#upgrade_failure_closure_ident)() |
| 190 | ); |
| 191 | }), |
| 192 | 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!! { |
| 193 | let #upgrade_failure_closure_ident = move || { |
| 194 | #expr |
| 195 | }; |
| 196 | let #upgrade_failure_closure_wrapped_ident = || |
| 197 | #crate_ident::closure::IntoClosureReturnValue::into_closure_return_value( |
| 198 | (#upgrade_failure_closure_ident)() |
| 199 | ); |
| 200 | }), |
| 201 | UpgradeBehaviourrust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#::Closurerust-analyzer cargo glib-macros 0.22.6 clone/UpgradeBehaviour#Closure#(ref closure_2) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 202 | let #upgrade_failure_closure_ident = #closure_2; |
| 203 | let #upgrade_failure_closure_wrapped_ident = || |
| 204 | #crate_ident::closure::IntoClosureReturnValue::into_closure_return_value( |
| 205 | (#upgrade_failure_closure_ident)() |
| 206 | ); |
| 207 | }), |
| 208 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 209 | }; |
| 210 | |
| 211 | let assert_return_type = upgrade_failure_closure.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().().thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| { |
| 212 | quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 213 | fn ____same<T>(_a: &T, _b: impl Fn() -> T) {} |
| 214 | ____same(&____res, #upgrade_failure_closure_ident); |
| 215 | } |
| 216 | }); |
| 217 | |
| 218 | tokens.extendrust-analyzer cargo proc-macro2 1.0.106 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 219 | { |
| 220 | let #closure_ident = { |
| 221 | #(#outer_before)* |
| 222 | #crate_ident::closure::RustClosure::#constructor(move |#values_ident| { |
| 223 | assert_eq!( |
| 224 | #values_ident.len(), |
| 225 | #args_len, |
| 226 | "Expected {} arguments but got {}", |
| 227 | #args_len, |
| 228 | #values_ident.len(), |
| 229 | ); |
| 230 | #upgrade_failure_closure |
| 231 | #(#inner_before)* |
| 232 | #(#arg_values)* |
| 233 | #crate_ident::closure::IntoClosureReturnValue::into_closure_return_value({ |
| 234 | #[allow(clippy::redundant_closure)] |
| 235 | let ____res = (#closure)(#(#arg_names),*); |
| 236 | #assert_return_type |
| 237 | ____res |
| 238 | }) |
| 239 | } |
| 240 | ) |
| 241 | }; |
| 242 | #(#outer_after)* |
| 243 | #closure_ident |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn closure_innerrust-analyzer cargo glib-macros 0.22.6 closure/closure_inner().( |
| 250 | 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#, |
| 251 | constructor: &'static str, |
| 252 | ) -> 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# { |
| 253 | let mut closure = 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 Closurerust-analyzer cargo glib-macros 0.22.6 closure/Closure#); |
| 254 | closure.constructorrust-analyzer cargo glib-macros 0.22.6 closure/Closure#constructor. = constructor; |
| 255 | closure.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().() |
| 256 | } |