Debian Codegraph @

src/cstnode.rs

raw symbols SCIP
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
2 //
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the root directory of this source tree
5
6 use 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#;
7 use quoterust-analyzer cargo quote 1.0.40 crate/::{format_identrust-analyzer cargo quote 1.0.40 format/format_ident!, quoterust-analyzer cargo quote 1.0.40 quote!, quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!, ToTokensrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens#};
8 use synrust-analyzer cargo syn 2.0.101 crate/::{
9 selfrust-analyzer cargo syn 2.0.101 crate/,
10 parserust-analyzer cargo syn 2.0.101 parse/::{Parserust-analyzer cargo syn 2.0.101 parse/Parse#, ParseStreamrust-analyzer cargo syn 2.0.101 parse/ParseStream#},
11 parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/,
12 punctuatedrust-analyzer cargo syn 2.0.101 punctuated/::{Pairrust-analyzer cargo syn 2.0.101 punctuated/Pair#, Punctuatedrust-analyzer cargo syn 2.0.101 punctuated/Punctuated#},
13 spannedrust-analyzer cargo syn 2.0.101 spanned/::Spannedrust-analyzer cargo syn 2.0.101 spanned/Spanned#,
14 tokenrust-analyzer cargo syn 2.0.101 token/::Commarust-analyzer cargo syn 2.0.101 token/Comma#,
15 AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments#, Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#, Datarust-analyzer cargo syn 2.0.101 derive/Data#, DataEnumrust-analyzer cargo syn 2.0.101 derive/DataEnum#, DataStructrust-analyzer cargo syn 2.0.101 derive/DataStruct#, DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput#, Fieldrust-analyzer cargo syn 2.0.101 data/Field#,
16 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#, FieldsNamedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#, FieldsUnnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#, GenericArgumentrust-analyzer cargo syn 2.0.101 path/GenericArgument#, Genericsrust-analyzer cargo syn 2.0.101 generics/Generics#, Identrust-analyzer cargo proc-macro2 1.0.95 Ident#, Metarust-analyzer cargo syn 2.0.101 attr/Meta#, Pathrust-analyzer cargo syn 2.0.101 path/Path#,
17 PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#, PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#, Tokenrust-analyzer cargo syn 2.0.101 token/Token!, Typerust-analyzer cargo syn 2.0.101 ty/Type#, TypePathrust-analyzer cargo syn 2.0.101 ty/TypePath#, Visibilityrust-analyzer cargo syn 2.0.101 restriction/Visibility#,
18 };
19
20 pub(craterust-analyzer cargo libcst_derive 1.8.6 crate/) struct CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams# {
21 traitsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#traits.: Punctuatedrust-analyzer cargo syn 2.0.101 punctuated/Punctuated#<SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#, Tokenrust-analyzer cargo syn 2.0.101 token/Token!![,]>,
22 }
23
24 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
25 enum SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait# {
26 ParenthesizedNoderust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#ParenthesizedNode#,
27 Codegenrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Codegen#,
28 Inflaterust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Inflate#,
29 NoIntoPyrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#NoIntoPy#,
30 Defaultrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Default#,
31 }
32
33 pub(craterust-analyzer cargo libcst_derive 1.8.6 crate/) fn impl_cst_noderust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_cst_node().(ast: DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput#, args: CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
34 match ast.datarust-analyzer cargo syn 2.0.101 derive/DeriveInput#data. {
35 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Enumrust-analyzer cargo syn 2.0.101 derive/Data#Enum#(e) => impl_enumrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_enum().(args, ast.attrsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#attrs., ast.visrust-analyzer cargo syn 2.0.101 derive/DeriveInput#vis., ast.identrust-analyzer cargo syn 2.0.101 derive/DeriveInput#ident., ast.genericsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#generics., e),
36 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Structrust-analyzer cargo syn 2.0.101 derive/Data#Struct#(s) => impl_structrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_struct().(args, ast.attrsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#attrs., ast.visrust-analyzer cargo syn 2.0.101 derive/DeriveInput#vis., ast.identrust-analyzer cargo syn 2.0.101 derive/DeriveInput#ident., ast.genericsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#generics., s),
37 Datarust-analyzer cargo syn 2.0.101 derive/Data#::Unionrust-analyzer cargo syn 2.0.101 derive/Data#Union#(u) => quote_spannedrust-analyzer cargo quote 1.0.40 quote_spanned!! {
38 u.union_tokenrust-analyzer cargo syn 2.0.101 derive/DataUnion#union_token..spanrust-analyzer cargo syn 2.0.101 spanned/impl#[T][Spanned]span().() =>
39 compile_error!("Union type is not supported")
40 }
41 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
42 }
43 }
44
45 impl CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams# {
46 fn has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&self, treyt: &SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#) -> bool {
47 self.traitsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#traits..iterrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|x| x 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().treyt)
48 }
49 }
50
51 impl Parserust-analyzer cargo syn 2.0.101 parse/Parse# for SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait# {
52 fn parserust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]parse().(input: ParseStreamrust-analyzer cargo syn 2.0.101 parse/ParseStream#) -> synrust-analyzer cargo syn 2.0.101 crate/::Resultrust-analyzer cargo syn 2.0.101 error/Result#<Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]> {
53 if input.peekrust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]peek().(Identrust-analyzer cargo syn 2.0.101 ident/Ident().) {
54 let id: Identrust-analyzer cargo proc-macro2 1.0.95 Ident# = input.parserust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
55 return match id.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().() {
56 "ParenthesizedNode" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]::ParenthesizedNoderust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#ParenthesizedNode#),
57 "Codegen" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]::Codegenrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Codegen#),
58 "Inflate" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]::Inflaterust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Inflate#),
59 "NoIntoPy" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]::NoIntoPyrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#NoIntoPy#),
60 "Default" => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]::Defaultrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Default#),
61 _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(input.errorrust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]error().("Not a supported trait to derive for cst_node")),
62 };
63 }
64 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(input.errorrust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]error().("Pass in trait names to be derived"))
65 }
66 }
67
68 impl Parserust-analyzer cargo syn 2.0.101 parse/Parse# for CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams# {
69 fn parserust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams][Parse]parse().(input: ParseStreamrust-analyzer cargo syn 2.0.101 parse/ParseStream#) -> synrust-analyzer cargo syn 2.0.101 crate/::Resultrust-analyzer cargo syn 2.0.101 error/Result#<Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams][Parse]> {
70 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams][Parse] {
71 traitsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#traits.: input.parse_terminatedrust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse_terminated().(SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::parserust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[SupportedTrait][Parse]parse()., Tokenrust-analyzer cargo syn 2.0.101 token/Token!![,])?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
72 })
73 }
74 }
75
76 // enum Foo<'a> {
77 // Variant(Box<Variant<'a>>),
78 // }
79 // =>
80 // enum Foo<'a> {
81 // Variant(Box<Variant<'a>>),
82 // }
83 // enum DeflatedFoo<'r, 'a> {
84 // Variant(Box<DeflatedVariant<'r, 'a>>),
85 // }
86
87 fn impl_enumrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_enum().(
88 args: CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#,
89 mut attrs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#>,
90 vis: Visibilityrust-analyzer cargo syn 2.0.101 restriction/Visibility#,
91 ident: Identrust-analyzer cargo proc-macro2 1.0.95 Ident#,
92 generics: Genericsrust-analyzer cargo syn 2.0.101 generics/Generics#,
93 mut e: DataEnumrust-analyzer cargo syn 2.0.101 derive/DataEnum#,
94 ) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
95 let deflated_vis = vis.clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::Visibility`][Clone]clone().();
96 let deflated_ident = format_identrust-analyzer cargo quote 1.0.40 format/format_ident!!("Deflated{}", &ident);
97 let deflated_generics: Genericsrust-analyzer cargo syn 2.0.101 generics/Generics# = parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(<'r, 'a>);
98 let mut deflated_variant_tokens = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
99
100 for var in e.variantsrust-analyzer cargo syn 2.0.101 derive/DataEnum#variants..iter_mutrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]iter_mut().() {
101 let (inflated_fields, deflated_fields) = impl_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_fields().(var.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields..clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::Fields`][Clone]clone().());
102 var.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields. = deflated_fields;
103 deflated_variant_tokens.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(var.to_token_streamrust-analyzer cargo quote 1.0.40 to_tokens/ToTokens#to_token_stream().());
104 var.fieldsrust-analyzer cargo syn 2.0.101 data/Variant#fields. = inflated_fields;
105 }
106 add_inflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/add_inflated_attrs().(&args, &mut attrs);
107 let inflated = DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput# {
108 attrsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#attrs.,
109 visrust-analyzer cargo syn 2.0.101 derive/DeriveInput#vis.,
110 identrust-analyzer cargo syn 2.0.101 derive/DeriveInput#ident.,
111 genericsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#generics.,
112 datarust-analyzer cargo syn 2.0.101 derive/DeriveInput#data.: Datarust-analyzer cargo syn 2.0.101 derive/Data#::Enumrust-analyzer cargo syn 2.0.101 derive/Data#Enum#(e),
113 };
114
115 let deflated_attrs = get_deflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_deflated_attrs().(&args);
116
117 let gen = quoterust-analyzer cargo quote 1.0.40 quote!! {
118 #[derive(Debug, PartialEq, Eq, Clone)]
119 #inflated
120
121 #[derive(Debug, PartialEq, Eq, Clone)]
122 #(#deflated_attrs)*
123 #deflated_vis enum #deflated_ident#deflated_generics {
124 #(#deflated_variant_tokens,)*
125 }
126 };
127 gen.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
128 }
129
130 fn get_deflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_deflated_attrs().(args: &CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#> {
131 let mut deflated_attrs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
132 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::Inflaterust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Inflate#) {
133 deflated_attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(Inflate)]));
134 }
135 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::ParenthesizedNoderust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#ParenthesizedNode#) {
136 deflated_attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(ParenthesizedDeflatedNode)]))
137 }
138 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::Defaultrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Default#) {
139 deflated_attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(Default)]));
140 }
141 deflated_attrs
142 }
143
144 fn add_inflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/add_inflated_attrs().(args: &CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#, attrs: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#>) {
145 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::Codegenrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Codegen#) {
146 attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(Codegen)]));
147 }
148 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::ParenthesizedNoderust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#ParenthesizedNode#) {
149 attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(ParenthesizedNode)]));
150 }
151 if args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::Defaultrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#Default#) {
152 attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[derive(Default)]));
153 }
154 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().args.has_traitrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl#[CSTNodeParams]has_trait().(&SupportedTraitrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#::NoIntoPyrust-analyzer cargo libcst_derive 1.8.6 cstnode/SupportedTrait#NoIntoPy#) {
155 attrs.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[cfg_attr(feature = "py", derive(TryIntoPy))]));
156 }
157 }
158
159 // pub struct Foo<'a> {
160 // pub bar: Bar<'a>,
161 // pub value: &'a str,
162 // pub whitespace_after: SimpleWhitespace<'a>,
163 // pub(crate) tok: Option<TokenRef>,
164 // }
165 // =>
166 // pub struct Foo<'a> {
167 // pub bar: Bar<'a>,
168 // pub value: &'a str,
169 // pub whitespace_after: SimpleWhitespace<'a>,
170 // }
171 // struct DeflatedFoo<'r, 'a> {
172 // pub bar: DeflatedBar<'r, 'a>,
173 // pub value: &'a str,
174 // pub tok: Option<TokenRef<'r, 'a>>
175 // }
176
177 fn impl_structrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_struct().(
178 args: CSTNodeParamsrust-analyzer cargo libcst_derive 1.8.6 cstnode/CSTNodeParams#,
179 mut attrs: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#>,
180 vis: Visibilityrust-analyzer cargo syn 2.0.101 restriction/Visibility#,
181 ident: Identrust-analyzer cargo proc-macro2 1.0.95 Ident#,
182 generics: Genericsrust-analyzer cargo syn 2.0.101 generics/Generics#,
183 mut s: DataStructrust-analyzer cargo syn 2.0.101 derive/DataStruct#,
184 ) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
185 let deflated_vis = vis.clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::Visibility`][Clone]clone().();
186 let deflated_ident = format_identrust-analyzer cargo quote 1.0.40 format/format_ident!!("Deflated{}", &ident);
187 let deflated_generics: Genericsrust-analyzer cargo syn 2.0.101 generics/Generics# = parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(<'r, 'a>);
188
189 let (inflated_fields, deflated_fields) = impl_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_fields().(s.fieldsrust-analyzer cargo syn 2.0.101 derive/DataStruct#fields.);
190 s.fieldsrust-analyzer cargo syn 2.0.101 derive/DataStruct#fields. = inflated_fields;
191
192 add_inflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/add_inflated_attrs().(&args, &mut attrs);
193
194 let inflated = DeriveInputrust-analyzer cargo syn 2.0.101 derive/DeriveInput# {
195 attrsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#attrs.,
196 visrust-analyzer cargo syn 2.0.101 derive/DeriveInput#vis.,
197 identrust-analyzer cargo syn 2.0.101 derive/DeriveInput#ident.,
198 genericsrust-analyzer cargo syn 2.0.101 derive/DeriveInput#generics.,
199 datarust-analyzer cargo syn 2.0.101 derive/DeriveInput#data.: Datarust-analyzer cargo syn 2.0.101 derive/Data#::Structrust-analyzer cargo syn 2.0.101 derive/Data#Struct#(s),
200 };
201
202 let deflated_attrs = get_deflated_attrsrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_deflated_attrs().(&args);
203
204 let gen = quoterust-analyzer cargo quote 1.0.40 quote!! {
205 #[derive(Debug, PartialEq, Eq, Clone)]
206 #inflated
207
208 #[derive(Debug, PartialEq, Eq, Clone)]
209 #(#deflated_attrs)*
210 #deflated_vis struct #deflated_ident#deflated_generics
211 #deflated_fields
212
213 };
214 gen.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
215 }
216
217 fn impl_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_fields().(fields: Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#) -> (Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#, Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#) {
218 match &fields {
219 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.101 data/Fields#Unnamed#(fs) => {
220 let deflated_fields = impl_unnamed_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_unnamed_fields().(fs.clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::FieldsUnnamed`][Clone]clone().());
221 (fields, Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.101 data/Fields#Unnamed#(deflated_fields))
222 }
223 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Namedrust-analyzer cargo syn 2.0.101 data/Fields#Named#(fs) => impl_named_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_named_fields().(fs.clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::FieldsNamed`][Clone]clone().()),
224 Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unitrust-analyzer cargo syn 2.0.101 data/Fields#Unit# => (Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unitrust-analyzer cargo syn 2.0.101 data/Fields#Unit#, Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Unitrust-analyzer cargo syn 2.0.101 data/Fields#Unit#),
225 }
226 }
227
228 fn impl_unnamed_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_unnamed_fields().(mut deflated_fields: FieldsUnnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#) -> FieldsUnnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed# {
229 let mut added_lifetime = false;
230 deflated_fields.unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed. = deflated_fields
231 .unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed.
232 .into_pairsrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]into_pairs().()
233 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|pair| {
234 let (deflated, lifetime) = make_into_deflatedrust-analyzer cargo libcst_derive 1.8.6 cstnode/make_into_deflated().(pair);
235 added_lifetime rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().lifetime;
236 deflated
237 })
238 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
239
240 // Make sure all Deflated* types have 'r 'a lifetime params
241 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().added_lifetime {
242 deflated_fields.unnamedrust-analyzer cargo syn 2.0.101 data/FieldsUnnamed#unnamed..pushrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!! {
243 std::marker::PhantomData<&'r &'a ()>
244 });
245 }
246 deflated_fields
247 }
248
249 fn impl_named_fieldsrust-analyzer cargo libcst_derive 1.8.6 cstnode/impl_named_fields().(mut fields: FieldsNamedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#) -> (Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#, Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#) {
250 let mut deflated_fields = fields.clonerust-analyzer cargo syn 2.0.101 gen/clone/impl#[`crate::FieldsNamed`][Clone]clone().();
251 let mut added_lifetime = false;
252 // Drop whitespace fields from deflated fields
253 // And add lifetimes to tokenref fields
254 deflated_fields.namedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#named. = deflated_fields
255 .namedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#named.
256 .into_pairsrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]into_pairs().()
257 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|pair| {
258 let id = pair.valuerust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]value().().identrust-analyzer cargo syn 2.0.101 data/Field#ident..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
259 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().id.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("whitespace")
260 && id rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne()."footer"
261 && id rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne()."header"
262 && id rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne()."leading_lines"
263 && id rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne()."lines_after_decorators"
264 })
265 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|pair| {
266 if is_builtinrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_builtin().(pair.valuerust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]value().()) {
267 pair
268 } else {
269 let (deflated, lifetime) = make_into_deflatedrust-analyzer cargo libcst_derive 1.8.6 cstnode/make_into_deflated().(pair);
270 added_lifetime rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().|=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitOrAssign<Self>`]bitor_assign().lifetime;
271 deflated
272 }
273 })
274 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|pair| {
275 let (mut val, punct) = pair.into_tuplerust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]into_tuple().();
276 val.attrsrust-analyzer cargo syn 2.0.101 data/Field#attrs. = val.attrsrust-analyzer cargo syn 2.0.101 data/Field#attrs..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
277 Pairrust-analyzer cargo syn 2.0.101 punctuated/Pair#::newrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]new().(val, punct)
278 })
279 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
280
281 // Make sure all Deflated* types have 'r 'a lifetime params
282 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().added_lifetime {
283 deflated_fields.namedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#named..pushrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]push().(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!! {
284 _phantom: std::marker::PhantomData<&'r &'a ()>
285 });
286 }
287
288 // Drop tokenref fields from inflated fields
289 fields.namedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#named. = fields
290 .namedrust-analyzer cargo syn 2.0.101 data/FieldsNamed#named.
291 .into_pairsrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]into_pairs().()
292 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|pair| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_token_refrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_token_ref().(pair.valuerust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]value().()))
293 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
294
295 (Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Namedrust-analyzer cargo syn 2.0.101 data/Fields#Named#(fields), Fieldsrust-analyzer cargo syn 2.0.101 data/Fields#::Namedrust-analyzer cargo syn 2.0.101 data/Fields#Named#(deflated_fields))
296 }
297
298 fn is_builtinrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_builtin().(field: &Fieldrust-analyzer cargo syn 2.0.101 data/Field#) -> bool {
299 get_pathsegrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg().(&field.tyrust-analyzer cargo syn 2.0.101 data/Field#ty.)
300 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|seg| {
301 let segstr = seg.identrust-analyzer cargo syn 2.0.101 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
302 segstr rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."str" || segstr rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."bool" || segstr rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."String"
303 })
304 .unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().()
305 }
306
307 fn is_token_refrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_token_ref().(field: &Fieldrust-analyzer cargo syn 2.0.101 data/Field#) -> bool {
308 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seg) = rightmost_path_segmentrust-analyzer cargo libcst_derive 1.8.6 cstnode/rightmost_path_segment().(&field.tyrust-analyzer cargo syn 2.0.101 data/Field#ty.) {
309 return formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", seg.identrust-analyzer cargo syn 2.0.101 path/PathSegment#ident.) rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."TokenRef";
310 }
311 false
312 }
313
314 // foo::bar -> foo::Deflatedbar<'r, 'a>
315 fn make_into_deflatedrust-analyzer cargo libcst_derive 1.8.6 cstnode/make_into_deflated().(mut pair: Pairrust-analyzer cargo syn 2.0.101 punctuated/Pair#<Fieldrust-analyzer cargo syn 2.0.101 data/Field#, Commarust-analyzer cargo syn 2.0.101 token/Comma#>) -> (Pairrust-analyzer cargo syn 2.0.101 punctuated/Pair#<Fieldrust-analyzer cargo syn 2.0.101 data/Field#, Commarust-analyzer cargo syn 2.0.101 token/Comma#>, bool) {
316 let mut added_lifetime = true;
317 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(seg) = rightmost_path_segment_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/rightmost_path_segment_mut().(&mut pair.value_mutrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Pair<T, P>`]value_mut().().tyrust-analyzer cargo syn 2.0.101 data/Field#ty.) {
318 let seg_name = seg.identrust-analyzer cargo syn 2.0.101 path/PathSegment#ident..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
319 if seg_name rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]ne()."TokenRef" {
320 seg.identrust-analyzer cargo syn 2.0.101 path/PathSegment#ident. = format_identrust-analyzer cargo quote 1.0.40 format/format_ident!!("Deflated{}", seg_name);
321 }
322 match seg.argumentsrust-analyzer cargo syn 2.0.101 path/PathSegment#arguments. {
323 PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::Nonerust-analyzer cargo syn 2.0.101 path/PathArguments#None# => {
324 seg.argumentsrust-analyzer cargo syn 2.0.101 path/PathSegment#arguments. = PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.101 path/PathArguments#AngleBracketed#(parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(<'r, 'a>));
325 }
326 PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.101 path/PathArguments#AngleBracketed#(AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments# {
327 ref mut argsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments#args., ..
328 }) => {
329 args.insertrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]insert().(0, parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!('r));
330 }
331 _ => todorust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/todo!!(),
332 }
333 } else {
334 added_lifetime = false;
335 }
336 (pair, added_lifetime)
337 }
338
339 // foo::bar::baz<quux<'a>> -> baz<quux<'a>>
340 fn get_pathsegrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg().(ty: &Typerust-analyzer cargo syn 2.0.101 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#> {
341 match ty {
342 Typerust-analyzer cargo syn 2.0.101 ty/Type#::Pathrust-analyzer cargo syn 2.0.101 ty/Type#Path#(TypePathrust-analyzer cargo syn 2.0.101 ty/TypePath# { pathrust-analyzer cargo syn 2.0.101 ty/TypePath#path., .. }) => path.segmentsrust-analyzer cargo syn 2.0.101 path/Path#segments..lastrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]last().(),
343 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
344 }
345 }
346
347 // foo::bar::baz<quux<'a>> -> quux<'a>
348 fn rightmost_path_segmentrust-analyzer cargo libcst_derive 1.8.6 cstnode/rightmost_path_segment().(ty: &Typerust-analyzer cargo syn 2.0.101 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#> {
349 let mut candidate = get_pathsegrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg().(ty);
350 loop {
351 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pathseg) = candidate {
352 if let PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.101 path/PathArguments#AngleBracketed#(AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments# { argsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments#args., .. }) =
353 &pathseg.argumentsrust-analyzer cargo syn 2.0.101 path/PathSegment#arguments.
354 {
355 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GenericArgumentrust-analyzer cargo syn 2.0.101 path/GenericArgument#::Typerust-analyzer cargo syn 2.0.101 path/GenericArgument#Type#(t)) = args.lastrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]last().() {
356 candidate = get_pathsegrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg().(t);
357 continue;
358 }
359 }
360 }
361 break;
362 }
363 candidate
364 }
365
366 fn get_pathseg_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg_mut().(ty: &mut Typerust-analyzer cargo syn 2.0.101 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#> {
367 match ty {
368 Typerust-analyzer cargo syn 2.0.101 ty/Type#::Pathrust-analyzer cargo syn 2.0.101 ty/Type#Path#(TypePathrust-analyzer cargo syn 2.0.101 ty/TypePath# { pathrust-analyzer cargo syn 2.0.101 ty/TypePath#path., .. }) => path.segmentsrust-analyzer cargo syn 2.0.101 path/Path#segments..last_mutrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]last_mut().(),
369 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
370 }
371 }
372
373 fn has_more_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/has_more_mut().(candidate: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#>) -> bool {
374 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.101 path/PathArguments#AngleBracketed#(AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments# {
375 ref argsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments#args., ..
376 })) = candidate.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|c| &c.argumentsrust-analyzer cargo syn 2.0.101 path/PathSegment#arguments.)
377 {
378 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(args.lastrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]last().(), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GenericArgumentrust-analyzer cargo syn 2.0.101 path/GenericArgument#::Typerust-analyzer cargo syn 2.0.101 path/GenericArgument#Type#(_)))
379 } else {
380 false
381 }
382 }
383
384 fn rightmost_path_segment_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/rightmost_path_segment_mut().(ty: &mut Typerust-analyzer cargo syn 2.0.101 ty/Type#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut PathSegmentrust-analyzer cargo syn 2.0.101 path/PathSegment#> {
385 let mut candidate = get_pathseg_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg_mut().(ty);
386
387 while has_more_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/has_more_mut().(&candidate) {
388 candidate = match candidate.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().argumentsrust-analyzer cargo syn 2.0.101 path/PathSegment#arguments. {
389 PathArgumentsrust-analyzer cargo syn 2.0.101 path/PathArguments#::AngleBracketedrust-analyzer cargo syn 2.0.101 path/PathArguments#AngleBracketed#(AngleBracketedGenericArgumentsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments# {
390 ref mut argsrust-analyzer cargo syn 2.0.101 path/AngleBracketedGenericArguments#args., ..
391 }) => {
392 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GenericArgumentrust-analyzer cargo syn 2.0.101 path/GenericArgument#::Typerust-analyzer cargo syn 2.0.101 path/GenericArgument#Type#(t)) = args.last_mutrust-analyzer cargo syn 2.0.101 punctuated/impl#[`Punctuated<T, P>`]last_mut().() {
393 get_pathseg_mutrust-analyzer cargo libcst_derive 1.8.6 cstnode/get_pathseg_mut().(t)
394 } else {
395 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!();
396 }
397 }
398 _ => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(),
399 };
400 }
401
402 candidate
403 }
404
405 fn is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(attr: &Attributerust-analyzer cargo syn 2.0.101 attr/Attribute#) -> bool {
406 let path = attr.pathrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]path().();
407 // support #[cfg_attr(feature = "py", skip_py)]
408 if path.is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().("cfg_attr") {
409 return match attr.parse_args_withrust-analyzer cargo syn 2.0.101 attr/impl#[Attribute]parse_args_with().(|input: ParseStreamrust-analyzer cargo syn 2.0.101 parse/ParseStream#| {
410 let _: Metarust-analyzer cargo syn 2.0.101 attr/Meta# = input.parserust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
411 let _: Tokenrust-analyzer cargo syn 2.0.101 token/Token!![,] = input.parserust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
412 let nested_path: Pathrust-analyzer cargo syn 2.0.101 path/Path# = input.parserust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
413 let _: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Tokenrust-analyzer cargo syn 2.0.101 token/Token!![,]> = input.parserust-analyzer cargo syn 2.0.101 parse/impl#[`ParseBuffer<'a>`]parse().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
414 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(nested_path)
415 }) {
416 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(nested_path) => !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_intopy_attr_pathrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_intopy_attr_path().(&nested_path),
417 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => false,
418 };
419 }
420 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_intopy_attr_pathrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_intopy_attr_path().(path)
421 }
422
423 fn is_intopy_attr_pathrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_intopy_attr_path().(path: &Pathrust-analyzer cargo syn 2.0.101 path/Path#) -> bool {
424 path.is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().("skip_py") || path.is_identrust-analyzer cargo syn 2.0.101 path/impl#[Path]is_ident().("no_py_default")
425 }
426
427 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
428 fn trybuildrust-analyzer cargo libcst_derive 1.8.6 cstnode/trybuild().() {
429 let t = trybuildrust-analyzer cargo trybuild 1.0.105 crate/::TestCasesrust-analyzer cargo trybuild 1.0.105 TestCases#::newrust-analyzer cargo trybuild 1.0.105 impl#[TestCases]new().();
430 t.passrust-analyzer cargo trybuild 1.0.105 impl#[TestCases]pass().("tests/pass/*.rs");
431 }
432
433 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
434 fn test_is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/test_is_not_intopy_attr().() {
435 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(&parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[skip_py])));
436 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(&parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[no_py_default])));
437 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(
438 &parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[cfg_attr(foo="bar",skip_py)])
439 ));
440 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(
441 &parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[cfg_attr(foo="bar",no_py_default)])
442 ));
443 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(&parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[skippy])));
444 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_not_intopy_attrrust-analyzer cargo libcst_derive 1.8.6 cstnode/is_not_intopy_attr().(
445 &parse_quoterust-analyzer cargo syn 2.0.101 parse_quote/parse_quote!!(#[cfg_attr(foo="bar",skippy)])
446 ));
447 }