| 1 | use craterust-analyzer cargo inherent 1.0.13 crate/::parserust-analyzer cargo inherent 1.0.13 parse/::TraitImplrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#; |
| 2 | use craterust-analyzer cargo inherent 1.0.13 crate/::verbatimrust-analyzer cargo inherent 1.0.13 verbatim/::VerbatimFnrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#; |
| 3 | use proc_macro2rust-analyzer cargo proc-macro2 1.0.101 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.101 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.101 TokenStream#}; |
| 4 | use quoterust-analyzer cargo quote 1.0.40 crate/::{quoterust-analyzer cargo quote 1.0.40 quote!, quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!}; |
| 5 | use synrust-analyzer cargo syn 2.0.106 crate/::{Attributerust-analyzer cargo syn 2.0.106 attr/Attribute#, FnArgrust-analyzer cargo syn 2.0.106 item/FnArg#, Identrust-analyzer cargo proc-macro2 1.0.101 Ident#, ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#, Patrust-analyzer cargo syn 2.0.106 pat/Pat#, Pathrust-analyzer cargo syn 2.0.106 path/Path#, Signaturerust-analyzer cargo syn 2.0.106 item/Signature#, Visibilityrust-analyzer cargo syn 2.0.106 restriction/Visibility#}; |
| 6 | |
| 7 | pub fn inherentrust-analyzer cargo inherent 1.0.13 expand/inherent().(mut input: TraitImplrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.101 TokenStream# { |
| 8 | let impl_token = &input.impl_tokenrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#impl_token.; |
| 9 | let generics = &input.genericsrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#generics.; |
| 10 | let where_clause = &input.genericsrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#generics..where_clauserust-analyzer cargo syn 2.0.106 generics/Generics#where_clause.; |
| 11 | let trait_ = &input.trait_rust-analyzer cargo inherent 1.0.13 parse/TraitImpl#trait_.; |
| 12 | let ty = &input.self_tyrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#self_ty.; |
| 13 | |
| 14 | let fwd_methods: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = input |
| 15 | .itemsrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#items. |
| 16 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 17 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|item| match item { |
| 18 | ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Fnrust-analyzer cargo syn 2.0.106 item/ImplItem#Fn#(method) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fwd_methodrust-analyzer cargo inherent 1.0.13 expand/fwd_method().( |
| 19 | trait_, |
| 20 | &method.attrsrust-analyzer cargo syn 2.0.106 item/ImplItemFn#attrs., |
| 21 | &method.visrust-analyzer cargo syn 2.0.106 item/ImplItemFn#vis., |
| 22 | &method.sigrust-analyzer cargo syn 2.0.106 item/ImplItemFn#sig., |
| 23 | method.blockrust-analyzer cargo syn 2.0.106 item/ImplItemFn#block..brace_tokenrust-analyzer cargo syn 2.0.106 stmt/Block#brace_token..spanrust-analyzer cargo syn 2.0.106 token/Brace#span..joinrust-analyzer cargo proc-macro2 1.0.101 extra/impl#[DelimSpan]join().(), |
| 24 | )), |
| 25 | ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Verbatimrust-analyzer cargo syn 2.0.106 item/ImplItem#Verbatim#(tokens) => { |
| 26 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(method) = synrust-analyzer cargo syn 2.0.106 crate/::parse2rust-analyzer cargo syn 2.0.106 parse2().::<VerbatimFnrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#>(tokens.clonerust-analyzer cargo proc-macro2 1.0.101 impl#[TokenStream][Clone]clone().()) { |
| 27 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fwd_methodrust-analyzer cargo inherent 1.0.13 expand/fwd_method().( |
| 28 | trait_, |
| 29 | &method.attrsrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#attrs., |
| 30 | &method.visrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#vis., |
| 31 | &method.sigrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#sig., |
| 32 | method.semi_tokenrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#semi_token..spanrust-analyzer cargo syn 2.0.106 token/private/WithSpan#span., |
| 33 | )) |
| 34 | } else { |
| 35 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 36 | } |
| 37 | } |
| 38 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 39 | }) |
| 40 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 41 | |
| 42 | input.itemsrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#items. = input |
| 43 | .itemsrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#items. |
| 44 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 45 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|item| match item { |
| 46 | ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Fnrust-analyzer cargo syn 2.0.106 item/ImplItem#Fn#(mut method) => { |
| 47 | method.visrust-analyzer cargo syn 2.0.106 item/ImplItemFn#vis. = Visibilityrust-analyzer cargo syn 2.0.106 restriction/Visibility#::Inheritedrust-analyzer cargo syn 2.0.106 restriction/Visibility#Inherited#; |
| 48 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Fnrust-analyzer cargo syn 2.0.106 item/ImplItem#Fn#(method)) |
| 49 | } |
| 50 | ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Verbatimrust-analyzer cargo syn 2.0.106 item/ImplItem#Verbatim#(tokens) => { |
| 51 | if synrust-analyzer cargo syn 2.0.106 crate/::parse2rust-analyzer cargo syn 2.0.106 parse2().::<VerbatimFnrust-analyzer cargo inherent 1.0.13 verbatim/VerbatimFn#>(tokens.clonerust-analyzer cargo proc-macro2 1.0.101 impl#[TokenStream][Clone]clone().()).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() { |
| 52 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 53 | } else { |
| 54 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ImplItemrust-analyzer cargo syn 2.0.106 item/ImplItem#::Verbatimrust-analyzer cargo syn 2.0.106 item/ImplItem#Verbatim#(tokens)) |
| 55 | } |
| 56 | } |
| 57 | item => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item), |
| 58 | }) |
| 59 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 60 | |
| 61 | let body = quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!!(input.brace_tokenrust-analyzer cargo inherent 1.0.13 parse/TraitImpl#brace_token..spanrust-analyzer cargo syn 2.0.106 token/Brace#span.=> { #(#fwd_methods)* }); |
| 62 | |
| 63 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 64 | #impl_token #generics #ty #where_clause #body |
| 65 | |
| 66 | #input |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | fn fwd_methodrust-analyzer cargo inherent 1.0.13 expand/fwd_method().( |
| 71 | trait_: &Pathrust-analyzer cargo syn 2.0.106 path/Path#, |
| 72 | attrs: &[Attributerust-analyzer cargo syn 2.0.106 attr/Attribute#], |
| 73 | vis: &Visibilityrust-analyzer cargo syn 2.0.106 restriction/Visibility#, |
| 74 | sig: &Signaturerust-analyzer cargo syn 2.0.106 item/Signature#, |
| 75 | body_span: Spanrust-analyzer cargo proc-macro2 1.0.101 Span#, |
| 76 | ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.101 TokenStream# { |
| 77 | let constness = &sig.constnessrust-analyzer cargo syn 2.0.106 item/Signature#constness.; |
| 78 | let asyncness = &sig.asyncnessrust-analyzer cargo syn 2.0.106 item/Signature#asyncness.; |
| 79 | let unsafety = &sig.unsafetyrust-analyzer cargo syn 2.0.106 item/Signature#unsafety.; |
| 80 | let abi = &sig.abirust-analyzer cargo syn 2.0.106 item/Signature#abi.; |
| 81 | let fn_token = sig.fn_tokenrust-analyzer cargo syn 2.0.106 item/Signature#fn_token.; |
| 82 | let ident = &sig.identrust-analyzer cargo syn 2.0.106 item/Signature#ident.; |
| 83 | let generics = &sig.genericsrust-analyzer cargo syn 2.0.106 item/Signature#generics.; |
| 84 | let output = &sig.outputrust-analyzer cargo syn 2.0.106 item/Signature#output.; |
| 85 | let where_clause = &sig.genericsrust-analyzer cargo syn 2.0.106 item/Signature#generics..where_clauserust-analyzer cargo syn 2.0.106 generics/Generics#where_clause.; |
| 86 | |
| 87 | let (arg_pat, arg_val): (Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>) = sig |
| 88 | .inputsrust-analyzer cargo syn 2.0.106 item/Signature#inputs. |
| 89 | .pairsrust-analyzer cargo syn 2.0.106 punctuated/impl#[`Punctuated<T, P>`]pairs().() |
| 90 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 91 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, pair)| { |
| 92 | let (input, comma_token) = pair.into_tuplerust-analyzer cargo syn 2.0.106 punctuated/impl#[`Pair<T, P>`]into_tuple().(); |
| 93 | match input { |
| 94 | FnArgrust-analyzer cargo syn 2.0.106 item/FnArg#::Receiverrust-analyzer cargo syn 2.0.106 item/FnArg#Receiver#(receiver) => { |
| 95 | let self_token = receiver.self_tokenrust-analyzer cargo syn 2.0.106 item/Receiver#self_token.; |
| 96 | if receiver.referencerust-analyzer cargo syn 2.0.106 item/Receiver#reference..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 97 | (quoterust-analyzer cargo quote 1.0.40 quote!!(#receiver #comma_token), quoterust-analyzer cargo quote 1.0.40 quote!!(#self_token)) |
| 98 | } else { |
| 99 | (quoterust-analyzer cargo quote 1.0.40 quote!!(#self_token #comma_token), quoterust-analyzer cargo quote 1.0.40 quote!!(#self_token)) |
| 100 | } |
| 101 | } |
| 102 | FnArgrust-analyzer cargo syn 2.0.106 item/FnArg#::Typedrust-analyzer cargo syn 2.0.106 item/FnArg#Typed#(arg) => { |
| 103 | let var = match arg.patrust-analyzer cargo syn 2.0.106 pat/PatType#pat..as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T, A>`][`AsRef<T>`]as_ref().() { |
| 104 | Patrust-analyzer cargo syn 2.0.106 pat/Pat#::Identrust-analyzer cargo syn 2.0.106 pat/Pat#Ident#(pat) => pat.identrust-analyzer cargo syn 2.0.106 pat/PatIdent#ident..clonerust-analyzer cargo proc-macro2 1.0.101 impl#[Ident][Clone]clone().(), |
| 105 | _ => Identrust-analyzer cargo proc-macro2 1.0.101 Ident#::newrust-analyzer cargo proc-macro2 1.0.101 impl#[Ident]new().(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("__arg{}", i), Spanrust-analyzer cargo proc-macro2 1.0.101 Span#::call_siterust-analyzer cargo proc-macro2 1.0.101 impl#[Span]call_site().()), |
| 106 | }; |
| 107 | let colon_token = arg.colon_tokenrust-analyzer cargo syn 2.0.106 pat/PatType#colon_token.; |
| 108 | let ty = &arg.tyrust-analyzer cargo syn 2.0.106 pat/PatType#ty.; |
| 109 | (quoterust-analyzer cargo quote 1.0.40 quote!!(#var #colon_token #ty #comma_token), quoterust-analyzer cargo quote 1.0.40 quote!!(#var)) |
| 110 | } |
| 111 | } |
| 112 | }) |
| 113 | .unziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#unzip().(); |
| 114 | |
| 115 | let types = generics.type_paramsrust-analyzer cargo syn 2.0.106 generics/impl#[Generics]type_params().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|param| ¶m.identrust-analyzer cargo syn 2.0.106 generics/TypeParam#ident.); |
| 116 | let wait = asyncness.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|_| quoterust-analyzer cargo quote 1.0.40 quote!!(.await)); |
| 117 | let body = quoterust-analyzer cargo quote 1.0.40 quote!!(<Self as #trait_>::#ident::<#(#types,)*>(#(#arg_val,)*) #wait); |
| 118 | let block = quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!!(body_span=> { #body }); |
| 119 | let args = quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!!(sig.paren_tokenrust-analyzer cargo syn 2.0.106 item/Signature#paren_token..spanrust-analyzer cargo syn 2.0.106 token/Paren#span.=> (#(#arg_pat)*)); |
| 120 | |
| 121 | let has_doc = attrs.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().(|attr| attr.pathrust-analyzer cargo syn 2.0.106 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.106 path/impl#[Path]is_ident().("doc")); |
| 122 | let default_doc = if has_doc { |
| 123 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 124 | } else { |
| 125 | let mut link = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 126 | for segment in &trait_.segmentsrust-analyzer cargo syn 2.0.106 path/Path#segments. { |
| 127 | link rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#add_assign().&segment.identrust-analyzer cargo syn 2.0.106 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 128 | link rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign().+=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`AddAssign<&str>`]add_assign()."::"; |
| 129 | } |
| 130 | let msg = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("See [`{}{}`]", link, ident); |
| 131 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(quoterust-analyzer cargo quote 1.0.40 quote!!(#[doc = #msg])) |
| 132 | }; |
| 133 | |
| 134 | quoterust-analyzer cargo quote 1.0.40 quote!! { |
| 135 | #(#attrs)* |
| 136 | #default_doc |
| 137 | #vis #constness #asyncness #unsafety #abi #fn_token #ident #generics #args #output #where_clause #block |
| 138 | } |
| 139 | } |