diff --git a/crates/core/cgp-field/src/traits/mod.rs b/crates/core/cgp-field/src/traits/mod.rs index 6ab96625e..cc0edbfb8 100644 --- a/crates/core/cgp-field/src/traits/mod.rs +++ b/crates/core/cgp-field/src/traits/mod.rs @@ -12,6 +12,7 @@ mod map_field; mod map_fields; mod map_type; mod map_type_ref; +mod option_as_ref; mod partial_data; mod static_string; mod take_field; @@ -33,6 +34,7 @@ pub use map_field::*; pub use map_fields::*; pub use map_type::*; pub use map_type_ref::*; +pub use option_as_ref::*; pub use partial_data::*; pub use static_string::*; pub use take_field::*; diff --git a/crates/core/cgp-field/src/traits/option_as_ref.rs b/crates/core/cgp-field/src/traits/option_as_ref.rs new file mode 100644 index 000000000..a7753a2c1 --- /dev/null +++ b/crates/core/cgp-field/src/traits/option_as_ref.rs @@ -0,0 +1,19 @@ +/// Borrows the value inside an `Option` as a `&T`. +/// +/// The blanket impl covers any `Option` whose `U` implements `AsRef`, so an +/// `#[implicit] nickname: Option<&str>` argument reads an `Option`, an +/// `Option>`, or an `Option>` field without needing an allocator +/// of its own. +pub trait OptionAsRef { + /// Borrows the contained value, or `None` when the option is empty. + fn option_as_ref(&self) -> Option<&T>; +} + +impl OptionAsRef for Option +where + U: AsRef, +{ + fn option_as_ref(&self) -> Option<&T> { + self.as_ref().map(|value| value.as_ref()) + } +} diff --git a/crates/macros/cgp-macro-core/src/exports.rs b/crates/macros/cgp-macro-core/src/exports.rs index 07eb527f2..726aeeb6f 100644 --- a/crates/macros/cgp-macro-core/src/exports.rs +++ b/crates/macros/cgp-macro-core/src/exports.rs @@ -28,6 +28,7 @@ export_constructs! { HasFields, HasFieldsRef, HasFieldMut, + OptionAsRef, FieldGetter, MutFieldGetter, FromFields, diff --git a/crates/macros/cgp-macro-core/src/functions/field/parse.rs b/crates/macros/cgp-macro-core/src/functions/field/parse.rs index 0006a9d1b..e70fa3e5c 100644 --- a/crates/macros/cgp-macro-core/src/functions/field/parse.rs +++ b/crates/macros/cgp-macro-core/src/functions/field/parse.rs @@ -15,6 +15,18 @@ use crate::types::getter::FieldMode; pub fn parse_field_type( return_type: &Type, receiver_mut: &Option, +) -> syn::Result<(Type, FieldMode, Option)> { + parse_field_type_with(return_type, receiver_mut, false) +} + +/// Like [`parse_field_type`], but `borrow_str` decides how a `&str` is read. An +/// `#[implicit]` argument sets it, so the field may be any `AsRef` and needs no +/// allocator; a getter leaves it off, because its `HasField` bound is also used by +/// the `WithProvider` adapter, which expects the field type itself. +pub fn parse_field_type_with( + return_type: &Type, + receiver_mut: &Option, + borrow_str: bool, ) -> syn::Result<(Type, FieldMode, Option)> { match &return_type { Type::Reference(type_ref) => { @@ -23,11 +35,21 @@ pub fn parse_field_type( let field_mut = type_ref.mutability; if type_ref.elem.as_ref() == &parse_internal! { str } { - // Special case to handle &str as String field + if borrow_str { + // A `&str` reads any `AsRef` field with `.as_ref()`, so a + // `String`, a `Cow`, or a `Box` field all work, and + // none of them needs an allocator. + let field_type: Type = parse_internal! { str }; - let field_type: Type = parse_internal! { String }; + Ok((field_type, FieldMode::Str, field_mut)) + } else { + // A getter's `HasField` bound is also used by the `WithProvider` + // adapter, which expects the field type itself, so it keeps the + // `String` field. + let field_type: Type = parse_internal! { String }; - Ok((field_type, FieldMode::Str, field_mut)) + Ok((field_type, FieldMode::Str, field_mut)) + } } else if let Type::Slice(slice) = type_ref.elem.as_ref() { // A shared `&[T]` reads any `AsRef<[T]>` field with `.as_ref()`; a // `&mut [T]` reads any `AsMut<[T]>` field with `.as_mut()`. Both use @@ -56,14 +78,21 @@ pub fn parse_field_type( let field_type = type_ref.elem.as_ref(); if field_type == &parse_internal! { str } { - // `Option<&str>` is backed by an `Option` field and read - // with `.as_deref()` (or `.as_deref_mut()` for `Option<&mut str>`), - // mirroring the `&str`/`String` special case for a plain reference. - Ok(( - parse_internal! { Option< String > }, - FieldMode::OptionStr, - field_mut, - )) + if borrow_str { + // An `#[implicit]` argument reads any `Option` whose `U` + // implements `AsRef` through `OptionAsRef`, so a + // `String`, a `Cow`, or a `Box` field all work and + // none needs an allocator. + Ok((parse_internal! { str }, FieldMode::OptionStr, field_mut)) + } else { + // A getter keeps the `Option` field, because its bound + // is also used by the `WithProvider` adapter. + Ok(( + parse_internal! { Option< String > }, + FieldMode::OptionStr, + field_mut, + )) + } } else { Ok(( parse_internal! { Option< #field_type > }, diff --git a/crates/macros/cgp-macro-core/src/functions/implicits/parse.rs b/crates/macros/cgp-macro-core/src/functions/implicits/parse.rs index b0a6153b9..b6b9ded1b 100644 --- a/crates/macros/cgp-macro-core/src/functions/implicits/parse.rs +++ b/crates/macros/cgp-macro-core/src/functions/implicits/parse.rs @@ -5,7 +5,7 @@ use syn::token::Comma; use syn::visit::{self, Visit}; use syn::{Attribute, FnArg, Meta, Pat, PatIdent, PatType, Receiver}; -use crate::functions::parse_field_type; +use crate::functions::parse_field_type_with; use crate::types::implicits::{ImplicitArgField, ImplicitArgFields}; pub fn extract_and_parse_implicit_args( @@ -68,7 +68,8 @@ pub fn parse_implicit_arg(receiver: &Receiver, arg: &PatType) -> syn::Result` — and rejects a mutable read without a `&mut // self` receiver. The receiver's own mutability never forces a mutable read of // an immutably-typed argument. - let (field_type, field_mode, field_mut) = parse_field_type(&arg_type, &receiver.mutability)?; + let (field_type, field_mode, field_mut) = + parse_field_type_with(&arg_type, &receiver.mutability, true)?; let spec = ImplicitArgField { field_name: pat_ident.ident.clone(), diff --git a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_enum.rs b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_enum.rs index 77d115956..26f26a8b1 100644 --- a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_enum.rs +++ b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_enum.rs @@ -45,13 +45,13 @@ pub fn derive_to_fields_match_arms( let constructor = derive_to_fields_constructor(&variant.fields, |label| match label { FieldLabel::Named(label) => quote! { - #label .into() + ::core::convert::Into::into(#label) }, FieldLabel::Unnamed(label) => { let field_name = Ident::new(&format!("field_{label}"), label.span()); quote! { - #field_name .into() + ::core::convert::Into::into(#field_name) } } FieldLabel::None => quote! { field }, @@ -60,7 +60,7 @@ pub fn derive_to_fields_match_arms( let variant_args = extract_variant_args(&variant.fields)?; let inject_variant = inject_prefix(quote! { - #Either::Left( #constructor .into() ) + #Either::Left( ::core::convert::Into::into(#constructor) ) }); inject_prefix = Box::new(move |inner| { diff --git a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_ref_struct.rs b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_ref_struct.rs index ba8e2518e..447c52ded 100644 --- a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_ref_struct.rs +++ b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_ref_struct.rs @@ -15,7 +15,7 @@ pub fn derive_to_fields_ref_for_struct(item_struct: &ItemStruct) -> syn::Result< &self.0 }, _ => quote! { - ( &self #field_name ) .into() + ::core::convert::Into::into(&self #field_name) }, })?; diff --git a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_struct.rs b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_struct.rs index 68ac4435c..725fc1e3c 100644 --- a/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_struct.rs +++ b/crates/macros/cgp-macro-core/src/types/cgp_data/derive_has_fields/to_fields_struct.rs @@ -16,7 +16,7 @@ pub fn derive_to_fields_for_struct(item_struct: &ItemStruct) -> syn::Result quote! { - self #field_name .into() + ::core::convert::Into::into(self #field_name) }, })?; diff --git a/crates/macros/cgp-macro-core/src/types/field/has_field_bound.rs b/crates/macros/cgp-macro-core/src/types/field/has_field_bound.rs index 796cf8810..e41244b3d 100644 --- a/crates/macros/cgp-macro-core/src/types/field/has_field_bound.rs +++ b/crates/macros/cgp-macro-core/src/types/field/has_field_bound.rs @@ -3,7 +3,7 @@ use quote::{ToTokens, quote}; use syn::Type; use syn::token::Mut; -use crate::exports::{HasField, HasFieldMut}; +use crate::exports::{HasField, HasFieldMut, OptionAsRef}; use crate::types::getter::FieldMode; pub struct HasFieldBound { @@ -25,19 +25,56 @@ impl ToTokens for HasFieldBound { let output = if field_mut.is_none() { if let FieldMode::Slice = field_mode { quote! { - #HasField< #tag_type, Value: AsRef< [ #field_type ] > + 'static > + #HasField< #tag_type, Value: ::core::convert::AsRef< [ #field_type ] > + 'static > + } + } else if let FieldMode::OptionStr = field_mode { + if field_type.to_token_stream().to_string() == "str" { + quote! { + #HasField< #tag_type, Value: #OptionAsRef< str > + 'static > + } + } else { + quote! { + #HasField< #tag_type, Value = #field_type > + } + } + } else if let FieldMode::Str = field_mode { + if field_type.to_token_stream().to_string() == "str" { + // An `#[implicit]` argument borrows any `AsRef` field, so a + // `String`, a `Cow`, or a `Box` field all work. The + // `'static` bound mirrors the slice case: the generated impl + // names the associated type in a `where` clause, which needs it + // to outlive the impl. + quote! { + #HasField< #tag_type, Value: ::core::convert::AsRef< str > + 'static > + } + } else { + // A getter keeps the field type itself, because its bound is also + // used by the `WithProvider` adapter. + quote! { + #HasField< #tag_type, Value = #field_type > + } } } else { quote! { #HasField< #tag_type, Value = #field_type > } } + } else if let FieldMode::Str = field_mode { + if field_type.to_token_stream().to_string() == "str" { + quote! { + #HasFieldMut< #tag_type, Value: ::core::convert::AsMut< str > + 'static > + } + } else { + quote! { + #HasFieldMut< #tag_type, Value = #field_type > + } + } } else if let FieldMode::Slice = field_mode { // A mutable slice reads through `.as_mut()`, so the field's value must // implement `AsMut<[T]>` — the mutable mirror of the shared slice's // `AsRef<[T]>` bound. quote! { - #HasFieldMut< #tag_type, Value: AsMut< [ #field_type ] > + 'static > + #HasFieldMut< #tag_type, Value: ::core::convert::AsMut< [ #field_type ] > + 'static > } } else { quote! { diff --git a/crates/macros/cgp-macro-core/src/types/getter/field_mode.rs b/crates/macros/cgp-macro-core/src/types/getter/field_mode.rs index 941673687..bbc65fc83 100644 --- a/crates/macros/cgp-macro-core/src/types/getter/field_mode.rs +++ b/crates/macros/cgp-macro-core/src/types/getter/field_mode.rs @@ -2,7 +2,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::token::Mut; -use crate::exports::MRef; +use crate::exports::{MRef, OptionAsRef}; /// The conversion a getter body applies to a raw field read, chosen from the /// getter method's return type by [`parse_field_type`](crate::functions::parse_field_type). @@ -23,36 +23,40 @@ impl FieldMode { /// truth shared by the getter-method body and the `#[implicit]` argument /// binding, so both families convert a given field identically. pub fn apply(&self, call_expr: TokenStream, field_mut: &Option) -> TokenStream { + // Every conversion is a fully qualified trait call, so an inherent method of + // the same name on the field's type cannot capture it. match self { FieldMode::Reference => call_expr, FieldMode::OptionRef => { + // The field is an `Option`, so the read is `Option`'s own inherent + // method, not the `AsRef`/`AsMut` conversion. if field_mut.is_none() { - quote! { #call_expr .as_ref() } + quote! { ::core::option::Option::as_ref( #call_expr ) } } else { - quote! { #call_expr .as_mut() } + quote! { ::core::option::Option::as_mut( #call_expr ) } } } FieldMode::OptionStr => { if field_mut.is_none() { - quote! { #call_expr .as_deref() } + quote! { #OptionAsRef::option_as_ref( #call_expr ) } } else { - quote! { #call_expr .as_deref_mut() } + quote! { ::core::option::Option::as_deref_mut( #call_expr ) } } } FieldMode::MRef => quote! { #MRef::Ref( #call_expr ) }, FieldMode::Str => { if field_mut.is_none() { - quote! { #call_expr .as_str() } + quote! { ::core::convert::AsRef::as_ref( #call_expr ) } } else { - quote! { #call_expr .as_mut_str() } + quote! { ::core::convert::AsMut::as_mut( #call_expr ) } } } - FieldMode::Copy => quote! { #call_expr .clone() }, + FieldMode::Copy => quote! { ::core::clone::Clone::clone( #call_expr ) }, FieldMode::Slice => { if field_mut.is_none() { - quote! { #call_expr .as_ref() } + quote! { ::core::convert::AsRef::as_ref( #call_expr ) } } else { - quote! { #call_expr .as_mut() } + quote! { ::core::convert::AsMut::as_mut( #call_expr ) } } } } diff --git a/crates/macros/cgp-macro-core/src/types/getter/get_field_expr.rs b/crates/macros/cgp-macro-core/src/types/getter/get_field_expr.rs index 97a6e3b82..5f23a68d1 100644 --- a/crates/macros/cgp-macro-core/src/types/getter/get_field_expr.rs +++ b/crates/macros/cgp-macro-core/src/types/getter/get_field_expr.rs @@ -3,6 +3,7 @@ use quote::{ToTokens, quote}; use syn::Expr; use syn::token::Mut; +use crate::exports::{HasField, HasFieldMut}; use crate::types::field::FieldName; pub struct GetFieldExpr { @@ -16,14 +17,17 @@ impl ToTokens for GetFieldExpr { let receiver = &self.receiver; let field_name = &self.field_name; - let method = if self.field_mut.is_none() { - quote!(get_field) + // A fully qualified trait call, so an inherent method of the same name on the + // context cannot capture the read. + let (field_trait, method) = if self.field_mut.is_none() { + (quote!(#HasField), quote!(get_field)) } else { - quote!(get_field_mut) + (quote!(#HasFieldMut), quote!(get_field_mut)) }; tokens.extend(quote! { - #receiver.#method( + #field_trait::#method( + #receiver, ::core::marker::PhantomData::<#field_name> ) }) diff --git a/crates/macros/cgp-macro-core/src/types/getter/method.rs b/crates/macros/cgp-macro-core/src/types/getter/method.rs index 4ab835043..70ac17edd 100644 --- a/crates/macros/cgp-macro-core/src/types/getter/method.rs +++ b/crates/macros/cgp-macro-core/src/types/getter/method.rs @@ -2,6 +2,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{Ident, ImplItemFn, Type}; +use crate::exports::{HasField, HasFieldMut}; use crate::functions::parse_internal; use crate::types::cgp_getter::GetterField; use crate::types::getter::ContextArg; @@ -71,6 +72,14 @@ impl GetterMethod { quote! { get_field_mut } }; + // The context read is a fully qualified trait call, so an inherent method of + // the same name on the context cannot capture it. + let get_field_trait = if getter_field.receiver_mut.is_none() { + quote! { #HasField } + } else { + quote! { #HasFieldMut } + }; + let context_var = match &context_arg { ContextArg::SelfArg => { quote! { self } @@ -88,7 +97,7 @@ impl GetterMethod { } None => { quote! { - #context_var . #get_field_method ( ::core::marker::PhantomData::< #tag_type > ) + #get_field_trait :: #get_field_method ( #context_var, ::core::marker::PhantomData::< #tag_type > ) } } }; diff --git a/crates/main/cgp-core/src/prelude.rs b/crates/main/cgp-core/src/prelude.rs index 43727da3c..49e6d30fe 100644 --- a/crates/main/cgp-core/src/prelude.rs +++ b/crates/main/cgp-core/src/prelude.rs @@ -11,8 +11,8 @@ pub use cgp_field::impls::{IsMut, IsNothing, IsPresent, IsRef, IsVoid, UseField} pub use cgp_field::traits::{ BuildField, ExtractField, FieldGetter, FinalizeBuild, FinalizeExtract, FromFields, FromVariant, HasBuilder, HasExtractor, HasExtractorMut, HasExtractorRef, HasField, HasFieldMut, HasFields, - HasFieldsRef, IntoBuilder, MapType, MapTypeRef, MutFieldGetter, PartialData, ToFields, - ToFieldsRef, UpdateField, + HasFieldsRef, IntoBuilder, MapType, MapTypeRef, MutFieldGetter, OptionAsRef, PartialData, + ToFields, ToFieldsRef, UpdateField, }; pub use cgp_field::types::{Chars, Cons, Either, Field, Index, Life, MRef, Nil, Symbol, Void}; pub use cgp_macro::{ diff --git a/crates/tests/cgp-no-std-tests/src/lib.rs b/crates/tests/cgp-no-std-tests/src/lib.rs index da49322f1..7a0089e64 100644 --- a/crates/tests/cgp-no-std-tests/src/lib.rs +++ b/crates/tests/cgp-no-std-tests/src/lib.rs @@ -35,14 +35,25 @@ impl Greeter { } /// A function-style trait, so the build exercises `#[cgp_fn]`. -/// -/// The implicit argument is a `u32` rather than a `&str`, because the `&str` form -/// lowers to a `String` field bound, which needs `alloc`. #[cgp_fn] pub fn double_count(&self, #[implicit] count: u32) -> u32 { count * 2 } +/// A `&str` implicit argument, which reads any `AsRef` field and so needs no +/// allocator. +#[cgp_fn] +pub fn greet_name(&self, #[implicit] name: &str) -> &str { + name +} + +/// An `Option<&str>` implicit argument, which reads any `Option` whose `U` +/// implements `AsRef` through `OptionAsRef`, so it needs no allocator either. +#[cgp_fn] +pub fn greet_nickname(&self, #[implicit] nickname: Option<&str>) -> Option<&str> { + nickname +} + /// A context that wires the component. pub struct App; diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_alias.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_alias.rs index 4f997f8b9..8bcc8aa44 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_alias.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_alias.rs @@ -60,18 +60,20 @@ snapshot_cgp_fn! { Self: HasScalarType, { fn rectangle_area(&self) -> ::Scalar { - let width: ::Scalar = self - .get_field( + let width: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: ::Scalar = self - .get_field( + ), + ); + let height: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -84,8 +86,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); let res: ::Scalar = width * height; res } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality.rs index a1ba1bb19..efa7096d8 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality.rs @@ -52,18 +52,20 @@ snapshot_cgp_fn! { Self: HasScalarType, { fn rectangle_area(&self) -> ::Scalar { - let width: ::Scalar = self - .get_field( + let width: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: ::Scalar = self - .get_field( + ), + ); + let height: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -76,8 +78,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); let res: f64 = width * height; res } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality_cross_trait.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality_cross_trait.rs index 996476952..9c882d3b0 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality_cross_trait.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_equality_cross_trait.rs @@ -115,18 +115,18 @@ snapshot_cgp_fn! { Self: HasFooType, { fn return_foo_or_bar(&self, flag: bool) -> ::Foo { - let foo: &::Foo = self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - >, - ); - let bar: &::Bar = self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, - >, - ); + let foo: &::Foo = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, + >, + ); + let bar: &::Bar = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, + >, + ); if flag { let res: ::Foo = self.do_foo(); if &res < foo { res } else { foo.clone() } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_expr_path.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_expr_path.rs index acaa27a5e..593c0853f 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_expr_path.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_expr_path.rs @@ -91,10 +91,10 @@ snapshot_cgp_fn! { Self: HasTransactionType, { fn begin_transaction(&self) -> ::Transaction { - let db: &Pool<::Db> = self - .get_field( - ::core::marker::PhantomData::>>>, - ); + let db: &Pool<::Db> = HasField::get_field( + self, + ::core::marker::PhantomData::>>>, + ); let started: ::Transaction = <::Transaction>::begin_from( db, ); @@ -167,10 +167,10 @@ snapshot_cgp_fn! { Self: HasTransactionType, { fn tagged_transaction(&self) -> ::Transaction { - let db: &Pool<::Db> = self - .get_field( - ::core::marker::PhantomData::>>>, - ); + let db: &Pool<::Db> = HasField::get_field( + self, + ::core::marker::PhantomData::>>>, + ); <::Transaction>::tagged::< ::Db, >(db) @@ -206,10 +206,10 @@ snapshot_cgp_fn! { Self: HasDbType, { fn unit_struct_untouched(&self) -> Marker2 { - let db: &Pool<::Db> = self - .get_field( - ::core::marker::PhantomData::>>>, - ); + let db: &Pool<::Db> = HasField::get_field( + self, + ::core::marker::PhantomData::>>>, + ); let _ = db; Marker.into() } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_extend.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_extend.rs index ca7d2f4b9..82af281cd 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_extend.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_extend.rs @@ -60,18 +60,20 @@ snapshot_cgp_fn! { >, { fn rectangle_area(&self) -> Self::Scalar { - let width: Self::Scalar = self - .get_field( + let width: Self::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: Self::Scalar = self - .get_field( + ), + ); + let height: Self::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -84,8 +86,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); width * height } } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign.rs index d2d9d3759..a76c2c107 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign.rs @@ -70,18 +70,20 @@ snapshot_cgp_fn! { Types: HasScalarType, { fn rectangle_area(&self) -> ::Scalar { - let width: ::Scalar = self - .get_field( + let width: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: ::Scalar = self - .get_field( + ), + ); + let height: ::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -94,8 +96,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); let res: ::Scalar = width * height; res } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality.rs index bc0cac2f4..d8d37bbe4 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality.rs @@ -66,18 +66,20 @@ snapshot_cgp_fn! { ::Types: HasScalarType, { fn rectangle_area(&self) -> <::Types as HasScalarType>::Scalar { - let width: <::Types as HasScalarType>::Scalar = self - .get_field( + let width: <::Types as HasScalarType>::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: <::Types as HasScalarType>::Scalar = self - .get_field( + ), + ); + let height: <::Types as HasScalarType>::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -90,8 +92,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); let res: f64 = width * height; res } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality_cross_trait.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality_cross_trait.rs index 9487a1783..79bcdecb5 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality_cross_trait.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_foreign_equality_cross_trait.rs @@ -124,18 +124,18 @@ snapshot_cgp_fn! { ::Bar: HasFooType::Foo>, { fn return_foo_or_bar(&self, flag: bool) -> ::Foo { - let foo: &::Foo = self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - >, - ); - let bar: &<::Bar as HasFooType>::Foo = self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, - >, - ); + let foo: &::Foo = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, + >, + ); + let bar: &<::Bar as HasFooType>::Foo = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, + >, + ); if flag { let res: ::Foo = self.do_foo(); if &res < foo { res } else { foo.clone() } diff --git a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_nested_foreign.rs b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_nested_foreign.rs index 70fef4870..5ddc98c64 100644 --- a/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_nested_foreign.rs +++ b/crates/tests/cgp-tests/tests/abstract_types/use_type_fn_nested_foreign.rs @@ -78,18 +78,20 @@ snapshot_cgp_fn! { ::Types: HasScalarType, { fn rectangle_area(&self) -> <::Types as HasScalarType>::Scalar { - let width: <::Types as HasScalarType>::Scalar = self - .get_field( + let width: <::Types as HasScalarType>::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: <::Types as HasScalarType>::Scalar = self - .get_field( + ), + ); + let height: <::Types as HasScalarType>::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -102,8 +104,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); let res: <::Types as HasScalarType>::Scalar = width * height; res } diff --git a/crates/tests/cgp-tests/tests/async_and_send/cgp_fn_async.rs b/crates/tests/cgp-tests/tests/async_and_send/cgp_fn_async.rs index 963bafc11..526e31689 100644 --- a/crates/tests/cgp-tests/tests/async_and_send/cgp_fn_async.rs +++ b/crates/tests/cgp-tests/tests/async_and_send/cgp_fn_async.rs @@ -31,17 +31,18 @@ snapshot_cgp_fn! { where Self: HasField< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - Value = String, + Value: ::core::convert::AsRef + 'static, >, { async fn greet(&self) -> String { - let name: &str = self - .get_field( + let name: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .as_str(); + ), + ); format!("Hello, {}!", name) } } diff --git a/crates/tests/cgp-tests/tests/dispatching/use_delegate_getter.rs b/crates/tests/cgp-tests/tests/dispatching/use_delegate_getter.rs index 38ef7919e..34627697c 100644 --- a/crates/tests/cgp-tests/tests/dispatching/use_delegate_getter.rs +++ b/crates/tests/cgp-tests/tests/dispatching/use_delegate_getter.rs @@ -370,21 +370,18 @@ snapshot_cgp_getter! { __context__: &__Context__, _phantom: PhantomData<(I, J)>, ) -> &__Context__::Foo { - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol< - 6, - Chars< - 'f', - Chars< - 'o', - Chars<'o', Chars<'_', Chars<'a', Chars<'t', Nil>>>>, - >, - >, + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol< + 6, + Chars< + 'f', + Chars<'o', Chars<'o', Chars<'_', Chars<'a', Chars<'t', Nil>>>>>, >, >, - ) + >, + ) } } impl<__Context__, I, J> IsProviderFor @@ -408,7 +405,7 @@ snapshot_cgp_getter! { __context__: &__Context__, _phantom: PhantomData<(I, J)>, ) -> &__Context__::Foo { - __context__.get_field(::core::marker::PhantomData::<__Tag__>) + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>) } } impl<__Context__, I, J, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/extensible_records/generic_record.rs b/crates/tests/cgp-tests/tests/extensible_records/generic_record.rs index 8fd520c07..9518ee253 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/generic_record.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/generic_record.rs @@ -155,7 +155,13 @@ snapshot_derive_cgp_data! { Foo: Clone, { fn to_fields(self) -> Self::Fields { - Cons(self.foo.into(), Cons(self.bar.into(), Cons(self.baz.into(), Nil))) + Cons( + ::core::convert::Into::into(self.foo), + Cons( + ::core::convert::Into::into(self.bar), + Cons(::core::convert::Into::into(self.baz), Nil), + ), + ) } } impl ToFieldsRef for Context @@ -166,7 +172,13 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.foo).into(), Cons((&self.bar).into(), Cons((&self.baz).into(), Nil))) + Cons( + ::core::convert::Into::into(&self.foo), + Cons( + ::core::convert::Into::into(&self.bar), + Cons(::core::convert::Into::into(&self.baz), Nil), + ), + ) } } ///The partial builder for [`Context`]. diff --git a/crates/tests/cgp-tests/tests/extensible_records/optional_builder.rs b/crates/tests/cgp-tests/tests/extensible_records/optional_builder.rs index be735b212..dbc7f0a8e 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/optional_builder.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/optional_builder.rs @@ -95,7 +95,10 @@ snapshot_derive_cgp_data! { } impl ToFields for Context { fn to_fields(self) -> Self::Fields { - Cons(self.foo.into(), Cons(self.bar.into(), Nil)) + Cons( + ::core::convert::Into::into(self.foo), + Cons(::core::convert::Into::into(self.bar), Nil), + ) } } impl ToFieldsRef for Context { @@ -103,7 +106,10 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.foo).into(), Cons((&self.bar).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.foo), + Cons(::core::convert::Into::into(&self.bar), Nil), + ) } } ///The partial builder for [`Context`]. diff --git a/crates/tests/cgp-tests/tests/extensible_records/person_record.rs b/crates/tests/cgp-tests/tests/extensible_records/person_record.rs index dd19a37b8..7e5d3eaad 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/person_record.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/person_record.rs @@ -351,7 +351,10 @@ snapshot_derive_cgp_data! { } impl ToFields for Person { fn to_fields(self) -> Self::Fields { - Cons(self.first_name.into(), Cons(self.last_name.into(), Nil)) + Cons( + ::core::convert::Into::into(self.first_name), + Cons(::core::convert::Into::into(self.last_name), Nil), + ) } } impl ToFieldsRef for Person { @@ -359,7 +362,10 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.first_name).into(), Cons((&self.last_name).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.first_name), + Cons(::core::convert::Into::into(&self.last_name), Nil), + ) } } ///The partial builder for [`Person`]. diff --git a/crates/tests/cgp-tests/tests/extensible_records/point_cast.rs b/crates/tests/cgp-tests/tests/extensible_records/point_cast.rs index d23215161..f00af4176 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/point_cast.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/point_cast.rs @@ -78,7 +78,10 @@ snapshot_derive_cgp_data! { } impl ToFields for Point2d { fn to_fields(self) -> Self::Fields { - Cons(self.x.into(), Cons(self.y.into(), Nil)) + Cons( + ::core::convert::Into::into(self.x), + Cons(::core::convert::Into::into(self.y), Nil), + ) } } impl ToFieldsRef for Point2d { @@ -86,7 +89,10 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.x).into(), Cons((&self.y).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.x), + Cons(::core::convert::Into::into(&self.y), Nil), + ) } } ///The partial builder for [`Point2d`]. diff --git a/crates/tests/cgp-tests/tests/extensible_records/record_derive.rs b/crates/tests/cgp-tests/tests/extensible_records/record_derive.rs index 80a5b39ec..478224948 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/record_derive.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/record_derive.rs @@ -127,7 +127,13 @@ snapshot_derive_cgp_data! { } impl ToFields for FooBarBaz { fn to_fields(self) -> Self::Fields { - Cons(self.foo.into(), Cons(self.bar.into(), Cons(self.baz.into(), Nil))) + Cons( + ::core::convert::Into::into(self.foo), + Cons( + ::core::convert::Into::into(self.bar), + Cons(::core::convert::Into::into(self.baz), Nil), + ), + ) } } impl ToFieldsRef for FooBarBaz { @@ -135,7 +141,13 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.foo).into(), Cons((&self.bar).into(), Cons((&self.baz).into(), Nil))) + Cons( + ::core::convert::Into::into(&self.foo), + Cons( + ::core::convert::Into::into(&self.bar), + Cons(::core::convert::Into::into(&self.baz), Nil), + ), + ) } } ///The partial builder for [`FooBarBaz`]. diff --git a/crates/tests/cgp-tests/tests/extensible_records/struct_generic.rs b/crates/tests/cgp-tests/tests/extensible_records/struct_generic.rs index 50cca9aea..c617aa11d 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/struct_generic.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/struct_generic.rs @@ -63,7 +63,10 @@ snapshot_derive_has_fields! { Name: Display, { fn to_fields(self) -> Self::Fields { - Cons(self.name.into(), Cons(self.age.into(), Nil)) + Cons( + ::core::convert::Into::into(self.name), + Cons(::core::convert::Into::into(self.age), Nil), + ) } } impl ToFieldsRef for Person @@ -74,7 +77,10 @@ snapshot_derive_has_fields! { where Self: '__a, { - Cons((&self.name).into(), Cons((&self.age).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.name), + Cons(::core::convert::Into::into(&self.age), Nil), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/extensible_records/struct_generic_lifetime.rs b/crates/tests/cgp-tests/tests/extensible_records/struct_generic_lifetime.rs index ce6cd5e84..cd7f0a35a 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/struct_generic_lifetime.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/struct_generic_lifetime.rs @@ -67,7 +67,10 @@ snapshot_derive_has_fields! { Name: Display, { fn to_fields(self) -> Self::Fields { - Cons(self.name.into(), Cons(self.age.into(), Nil)) + Cons( + ::core::convert::Into::into(self.name), + Cons(::core::convert::Into::into(self.age), Nil), + ) } } impl<'a, Name> ToFieldsRef for Person<'a, Name> @@ -78,7 +81,10 @@ snapshot_derive_has_fields! { where Self: '__a, { - Cons((&self.name).into(), Cons((&self.age).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.name), + Cons(::core::convert::Into::into(&self.age), Nil), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/extensible_records/struct_single_named_field.rs b/crates/tests/cgp-tests/tests/extensible_records/struct_single_named_field.rs index 6841487dc..d61c9f5a6 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/struct_single_named_field.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/struct_single_named_field.rs @@ -46,7 +46,7 @@ snapshot_derive_has_fields! { } impl ToFields for Person { fn to_fields(self) -> Self::Fields { - Cons(self.name.into(), Nil) + Cons(::core::convert::Into::into(self.name), Nil) } } impl ToFieldsRef for Person { @@ -54,7 +54,7 @@ snapshot_derive_has_fields! { where Self: '__a, { - Cons((&self.name).into(), Nil) + Cons(::core::convert::Into::into(&self.name), Nil) } } ") diff --git a/crates/tests/cgp-tests/tests/extensible_records/struct_tuple_fields.rs b/crates/tests/cgp-tests/tests/extensible_records/struct_tuple_fields.rs index 4c5c5a608..3d73b397f 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/struct_tuple_fields.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/struct_tuple_fields.rs @@ -34,7 +34,10 @@ snapshot_derive_has_fields! { } impl ToFields for Person { fn to_fields(self) -> Self::Fields { - Cons(self.0.into(), Cons(self.1.into(), Nil)) + Cons( + ::core::convert::Into::into(self.0), + Cons(::core::convert::Into::into(self.1), Nil), + ) } } impl ToFieldsRef for Person { @@ -42,7 +45,10 @@ snapshot_derive_has_fields! { where Self: '__a, { - Cons((&self.0).into(), Cons((&self.1).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.0), + Cons(::core::convert::Into::into(&self.1), Nil), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/extensible_records/struct_two_named_fields.rs b/crates/tests/cgp-tests/tests/extensible_records/struct_two_named_fields.rs index 2e298576e..101da6833 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/struct_two_named_fields.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/struct_two_named_fields.rs @@ -46,7 +46,10 @@ snapshot_derive_has_fields! { } impl ToFields for Person { fn to_fields(self) -> Self::Fields { - Cons(self.name.into(), Cons(self.age.into(), Nil)) + Cons( + ::core::convert::Into::into(self.name), + Cons(::core::convert::Into::into(self.age), Nil), + ) } } impl ToFieldsRef for Person { @@ -54,7 +57,10 @@ snapshot_derive_has_fields! { where Self: '__a, { - Cons((&self.name).into(), Cons((&self.age).into(), Nil)) + Cons( + ::core::convert::Into::into(&self.name), + Cons(::core::convert::Into::into(&self.age), Nil), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/extensible_records/tuple_record.rs b/crates/tests/cgp-tests/tests/extensible_records/tuple_record.rs index 53c322da6..cb22d1c54 100644 --- a/crates/tests/cgp-tests/tests/extensible_records/tuple_record.rs +++ b/crates/tests/cgp-tests/tests/extensible_records/tuple_record.rs @@ -80,7 +80,13 @@ snapshot_derive_cgp_data! { } impl ToFields for Context { fn to_fields(self) -> Self::Fields { - Cons(self.0.into(), Cons(self.1.into(), Cons(self.2.into(), Nil))) + Cons( + ::core::convert::Into::into(self.0), + Cons( + ::core::convert::Into::into(self.1), + Cons(::core::convert::Into::into(self.2), Nil), + ), + ) } } impl ToFieldsRef for Context { @@ -88,7 +94,13 @@ snapshot_derive_cgp_data! { where Self: '__a, { - Cons((&self.0).into(), Cons((&self.1).into(), Cons((&self.2).into(), Nil))) + Cons( + ::core::convert::Into::into(&self.0), + Cons( + ::core::convert::Into::into(&self.1), + Cons(::core::convert::Into::into(&self.2), Nil), + ), + ) } } ///The partial builder for [`Context`]. diff --git a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data.rs b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data.rs index ec841846c..8c7f65ccf 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data.rs @@ -84,9 +84,15 @@ snapshot_derive_cgp_data! { impl ToFields for FooBarBaz { fn to_fields(self) -> ::Fields { match self { - Self::Foo(field) => Either::Left(field.into()), - Self::Bar(field) => Either::Right(Either::Left(field.into())), - Self::Baz(field) => Either::Right(Either::Right(Either::Left(field.into()))), + Self::Foo(field) => Either::Left(::core::convert::Into::into(field)), + Self::Bar(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } + Self::Baz(field) => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(field))), + ) + } } } } @@ -96,9 +102,15 @@ snapshot_derive_cgp_data! { Self: '__a, { match self { - Self::Foo(field) => Either::Left(field.into()), - Self::Bar(field) => Either::Right(Either::Left(field.into())), - Self::Baz(field) => Either::Right(Either::Right(Either::Left(field.into()))), + Self::Foo(field) => Either::Left(::core::convert::Into::into(field)), + Self::Bar(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } + Self::Baz(field) => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(field))), + ) + } } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_empty_variants.rs b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_empty_variants.rs index 07c28e3c8..1e0d15561 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_empty_variants.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_empty_variants.rs @@ -192,11 +192,19 @@ snapshot_derive_cgp_data! { impl ToFields for Status { fn to_fields(self) -> ::Fields { match self { - Self::Active(field) => Either::Left(field.into()), - Self::Closed => Either::Right(Either::Left(Nil.into())), - Self::Paused() => Either::Right(Either::Right(Either::Left(Nil.into()))), + Self::Active(field) => Either::Left(::core::convert::Into::into(field)), + Self::Closed => Either::Right(Either::Left(::core::convert::Into::into(Nil))), + Self::Paused() => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(Nil))), + ) + } Self::Archived {} => { - Either::Right(Either::Right(Either::Right(Either::Left(Nil.into())))) + Either::Right( + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(Nil))), + ), + ) } } } @@ -207,11 +215,19 @@ snapshot_derive_cgp_data! { Self: '__a, { match self { - Self::Active(field) => Either::Left(field.into()), - Self::Closed => Either::Right(Either::Left(Nil.into())), - Self::Paused() => Either::Right(Either::Right(Either::Left(Nil.into()))), + Self::Active(field) => Either::Left(::core::convert::Into::into(field)), + Self::Closed => Either::Right(Either::Left(::core::convert::Into::into(Nil))), + Self::Paused() => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(Nil))), + ) + } Self::Archived {} => { - Either::Right(Either::Right(Either::Right(Either::Left(Nil.into())))) + Either::Right( + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(Nil))), + ), + ) } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_generic.rs b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_generic.rs index c669f5b8d..70b84b75d 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_generic.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_generic.rs @@ -79,9 +79,15 @@ snapshot_derive_cgp_data! { impl ToFields for FooBarBazGeneric { fn to_fields(self) -> ::Fields { match self { - Self::Foo(field) => Either::Left(field.into()), - Self::Bar(field) => Either::Right(Either::Left(field.into())), - Self::Baz(field) => Either::Right(Either::Right(Either::Left(field.into()))), + Self::Foo(field) => Either::Left(::core::convert::Into::into(field)), + Self::Bar(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } + Self::Baz(field) => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(field))), + ) + } } } } @@ -91,9 +97,15 @@ snapshot_derive_cgp_data! { Self: '__a, { match self { - Self::Foo(field) => Either::Left(field.into()), - Self::Bar(field) => Either::Right(Either::Left(field.into())), - Self::Baz(field) => Either::Right(Either::Right(Either::Left(field.into()))), + Self::Foo(field) => Either::Left(::core::convert::Into::into(field)), + Self::Bar(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } + Self::Baz(field) => { + Either::Right( + Either::Right(Either::Left(::core::convert::Into::into(field))), + ) + } } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_shape.rs b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_shape.rs index 2a6fc8505..8e97dfd4b 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_shape.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/derive_cgp_data_shape.rs @@ -132,8 +132,10 @@ snapshot_derive_cgp_data! { impl ToFields for Shape { fn to_fields(self) -> ::Fields { match self { - Self::Circle(field) => Either::Left(field.into()), - Self::Rectangle(field) => Either::Right(Either::Left(field.into())), + Self::Circle(field) => Either::Left(::core::convert::Into::into(field)), + Self::Rectangle(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } @@ -143,8 +145,10 @@ snapshot_derive_cgp_data! { Self: '__a, { match self { - Self::Circle(field) => Either::Left(field.into()), - Self::Rectangle(field) => Either::Right(Either::Left(field.into())), + Self::Circle(field) => Either::Left(::core::convert::Into::into(field)), + Self::Rectangle(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum.rs b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum.rs index 261218871..7581ce5cc 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum.rs @@ -119,8 +119,10 @@ snapshot_derive_has_fields! { impl ToFields for Person { fn to_fields(self) -> ::Fields { match self { - Self::Anonymous(field) => Either::Left(field.into()), - Self::Named(field) => Either::Right(Either::Left(field.into())), + Self::Anonymous(field) => Either::Left(::core::convert::Into::into(field)), + Self::Named(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } @@ -130,8 +132,10 @@ snapshot_derive_has_fields! { Self: '__a, { match self { - Self::Anonymous(field) => Either::Left(field.into()), - Self::Named(field) => Either::Right(Either::Left(field.into())), + Self::Anonymous(field) => Either::Left(::core::convert::Into::into(field)), + Self::Named(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_generic.rs b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_generic.rs index 79c681c67..90eacb452 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_generic.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_generic.rs @@ -117,8 +117,10 @@ snapshot_derive_has_fields! { impl<'a, Name> ToFields for Person<'a, Name> { fn to_fields(self) -> ::Fields { match self { - Self::Anonymous(field) => Either::Left(field.into()), - Self::Named(field) => Either::Right(Either::Left(field.into())), + Self::Anonymous(field) => Either::Left(::core::convert::Into::into(field)), + Self::Named(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } @@ -128,8 +130,10 @@ snapshot_derive_has_fields! { Self: '__a, { match self { - Self::Anonymous(field) => Either::Left(field.into()), - Self::Named(field) => Either::Right(Either::Left(field.into())), + Self::Anonymous(field) => Either::Left(::core::convert::Into::into(field)), + Self::Named(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } } } } diff --git a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_shapes.rs b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_shapes.rs index 31d95510a..7bb520c05 100644 --- a/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_shapes.rs +++ b/crates/tests/cgp-tests/tests/extensible_variants/has_fields_enum_shapes.rs @@ -259,13 +259,20 @@ snapshot_derive_has_fields! { impl ToFields for Shape { fn to_fields(self) -> ::Fields { match self { - Self::Empty => Either::Left(Nil.into()), - Self::Circle(field) => Either::Right(Either::Left(field.into())), + Self::Empty => Either::Left(::core::convert::Into::into(Nil)), + Self::Circle(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } Self::Rectangle(field_0, field_1) => { Either::Right( Either::Right( Either::Left( - Cons(field_0.into(), Cons(field_1.into(), Nil)).into(), + ::core::convert::Into::into( + Cons( + ::core::convert::Into::into(field_0), + Cons(::core::convert::Into::into(field_1), Nil), + ), + ), ), ), ) @@ -275,7 +282,12 @@ snapshot_derive_has_fields! { Either::Right( Either::Right( Either::Left( - Cons(base.into(), Cons(height.into(), Nil)).into(), + ::core::convert::Into::into( + Cons( + ::core::convert::Into::into(base), + Cons(::core::convert::Into::into(height), Nil), + ), + ), ), ), ), @@ -290,13 +302,20 @@ snapshot_derive_has_fields! { Self: '__a, { match self { - Self::Empty => Either::Left(Nil.into()), - Self::Circle(field) => Either::Right(Either::Left(field.into())), + Self::Empty => Either::Left(::core::convert::Into::into(Nil)), + Self::Circle(field) => { + Either::Right(Either::Left(::core::convert::Into::into(field))) + } Self::Rectangle(field_0, field_1) => { Either::Right( Either::Right( Either::Left( - Cons(field_0.into(), Cons(field_1.into(), Nil)).into(), + ::core::convert::Into::into( + Cons( + ::core::convert::Into::into(field_0), + Cons(::core::convert::Into::into(field_1), Nil), + ), + ), ), ), ) @@ -306,7 +325,12 @@ snapshot_derive_has_fields! { Either::Right( Either::Right( Either::Left( - Cons(base.into(), Cons(height.into(), Nil)).into(), + ::core::convert::Into::into( + Cons( + ::core::convert::Into::into(base), + Cons(::core::convert::Into::into(height), Nil), + ), + ), ), ), ), diff --git a/crates/tests/cgp-tests/tests/generic_components/fn_generic_param.rs b/crates/tests/cgp-tests/tests/generic_components/fn_generic_param.rs index 35ed0cfa8..22002c636 100644 --- a/crates/tests/cgp-tests/tests/generic_components/fn_generic_param.rs +++ b/crates/tests/cgp-tests/tests/generic_components/fn_generic_param.rs @@ -51,18 +51,20 @@ snapshot_cgp_fn! { >, { fn rectangle_area(&self) -> Scalar { - let width: Scalar = self - .get_field( + let width: Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: Scalar = self - .get_field( + ), + ); + let height: Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -75,8 +77,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); width * height } } diff --git a/crates/tests/cgp-tests/tests/generic_components/fn_impl_generics.rs b/crates/tests/cgp-tests/tests/generic_components/fn_impl_generics.rs index d063cc673..95b7ae260 100644 --- a/crates/tests/cgp-tests/tests/generic_components/fn_impl_generics.rs +++ b/crates/tests/cgp-tests/tests/generic_components/fn_impl_generics.rs @@ -39,12 +39,12 @@ snapshot_cgp_fn! { >, { fn greet(&self) -> String { - let name: &Name = self - .get_field( - ::core::marker::PhantomData::< - Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - >, - ); + let name: &Name = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + ); format!("Hello, {}!", name) } } diff --git a/crates/tests/cgp-tests/tests/getters/abstract_type_extend.rs b/crates/tests/cgp-tests/tests/getters/abstract_type_extend.rs index e8ea6cd48..db90b7615 100644 --- a/crates/tests/cgp-tests/tests/getters/abstract_type_extend.rs +++ b/crates/tests/cgp-tests/tests/getters/abstract_type_extend.rs @@ -47,18 +47,22 @@ snapshot_cgp_auto_getter! { >, { fn width(&self) -> __Context__::Scalar { - self.get_field( + ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone() + ), + ) } fn height(&self) -> __Context__::Scalar { - self.get_field( + ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -71,8 +75,8 @@ snapshot_cgp_auto_getter! { >, >, >, - ) - .clone() + ), + ) } } ") @@ -201,20 +205,22 @@ snapshot_cgp_getter! { >, { fn width(__context__: &__Context__) -> __Context__::Scalar { - __context__ - .get_field( + ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone() + ), + ) } fn height(__context__: &__Context__) -> __Context__::Scalar { - __context__ - .get_field( + ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 6, @@ -227,8 +233,8 @@ snapshot_cgp_getter! { >, >, >, - ) - .clone() + ), + ) } } impl<__Context__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/abstract_type_use_type.rs b/crates/tests/cgp-tests/tests/getters/abstract_type_use_type.rs index 4f09d5087..4bc7746ec 100644 --- a/crates/tests/cgp-tests/tests/getters/abstract_type_use_type.rs +++ b/crates/tests/cgp-tests/tests/getters/abstract_type_use_type.rs @@ -48,18 +48,22 @@ snapshot_cgp_auto_getter! { >, { fn width(&self) -> <__Context__ as HasScalarType>::Scalar { - self.get_field( + ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone() + ), + ) } fn height(&self) -> <__Context__ as HasScalarType>::Scalar { - self.get_field( + ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -72,8 +76,8 @@ snapshot_cgp_auto_getter! { >, >, >, - ) - .clone() + ), + ) } } ") @@ -202,20 +206,22 @@ snapshot_cgp_getter! { >, { fn width(__context__: &__Context__) -> <__Context__ as HasScalarType>::Scalar { - __context__ - .get_field( + ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone() + ), + ) } fn height(__context__: &__Context__) -> <__Context__ as HasScalarType>::Scalar { - __context__ - .get_field( + ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 6, @@ -228,8 +234,8 @@ snapshot_cgp_getter! { >, >, >, - ) - .clone() + ), + ) } } impl<__Context__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/assoc_type_auto_getter.rs b/crates/tests/cgp-tests/tests/getters/assoc_type_auto_getter.rs index b4fd5a111..683c66fda 100644 --- a/crates/tests/cgp-tests/tests/getters/assoc_type_auto_getter.rs +++ b/crates/tests/cgp-tests/tests/getters/assoc_type_auto_getter.rs @@ -33,7 +33,8 @@ snapshot_cgp_auto_getter! { { type Name = Name; fn name(&self) -> &Self::Name { - self.get_field( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, diff --git a/crates/tests/cgp-tests/tests/getters/assoc_type_getter.rs b/crates/tests/cgp-tests/tests/getters/assoc_type_getter.rs index 28a93a31f..7418221c4 100644 --- a/crates/tests/cgp-tests/tests/getters/assoc_type_getter.rs +++ b/crates/tests/cgp-tests/tests/getters/assoc_type_getter.rs @@ -112,21 +112,18 @@ snapshot_cgp_getter! { { type Scalar = Scalar; fn scalar(__context__: &__Context__) -> &Self::Scalar { - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol< - 6, - Chars< - 's', - Chars< - 'c', - Chars<'a', Chars<'l', Chars<'a', Chars<'r', Nil>>>>, - >, - >, + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol< + 6, + Chars< + 's', + Chars<'c', Chars<'a', Chars<'l', Chars<'a', Chars<'r', Nil>>>>>, >, >, - ) + >, + ) } } impl<__Context__, Scalar> IsProviderFor @@ -148,7 +145,7 @@ snapshot_cgp_getter! { { type Scalar = Scalar; fn scalar(__context__: &__Context__) -> &Self::Scalar { - __context__.get_field(::core::marker::PhantomData::<__Tag__>) + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>) } } impl<__Context__, Scalar, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential.rs b/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential.rs index 309b97979..919db50c1 100644 --- a/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential.rs +++ b/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential.rs @@ -106,12 +106,12 @@ snapshot_cgp_getter! { { type Name = Name; fn name(__context__: &__Context__) -> &Self::Name { - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - >, - ) + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + ) } } impl<__Context__, Name> IsProviderFor for UseFields @@ -129,7 +129,7 @@ snapshot_cgp_getter! { { type Name = Name; fn name(__context__: &__Context__) -> &Self::Name { - __context__.get_field(::core::marker::PhantomData::<__Tag__>) + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>) } } impl<__Context__, Name, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential_auto.rs b/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential_auto.rs index 28771f92b..df5c056d7 100644 --- a/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/assoc_type_self_referential_auto.rs @@ -36,7 +36,8 @@ snapshot_cgp_auto_getter! { { type Scalar = Scalar; fn scalar(&self) -> &Self::Scalar { - self.get_field( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, diff --git a/crates/tests/cgp-tests/tests/getters/auto_getter_generic.rs b/crates/tests/cgp-tests/tests/getters/auto_getter_generic.rs index 81c43447e..8eae3a8ff 100644 --- a/crates/tests/cgp-tests/tests/getters/auto_getter_generic.rs +++ b/crates/tests/cgp-tests/tests/getters/auto_getter_generic.rs @@ -26,7 +26,8 @@ snapshot_cgp_auto_getter! { >, { fn foo(&self, _phantom: PhantomData) -> &Foo { - self.get_field( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, diff --git a/crates/tests/cgp-tests/tests/getters/clone.rs b/crates/tests/cgp-tests/tests/getters/clone.rs index d7125da3c..852b25efd 100644 --- a/crates/tests/cgp-tests/tests/getters/clone.rs +++ b/crates/tests/cgp-tests/tests/getters/clone.rs @@ -106,13 +106,14 @@ snapshot_cgp_getter! { >, { fn name(__context__: &__Context__) -> __Context__::Name { - __context__ - .get_field( + ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .clone() + ), + ) } } impl<__Context__> IsProviderFor for UseFields @@ -129,7 +130,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = __Context__::Name>, { fn name(__context__: &__Context__) -> __Context__::Name { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).clone() + ::core::clone::Clone::clone( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor @@ -148,11 +151,12 @@ snapshot_cgp_getter! { >, { fn name(__context__: &__Context__) -> __Context__::Name { - __Provider__::get_field( + ::core::clone::Clone::clone( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .clone() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/clone_auto.rs b/crates/tests/cgp-tests/tests/getters/clone_auto.rs index 660b1cc42..944699874 100644 --- a/crates/tests/cgp-tests/tests/getters/clone_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/clone_auto.rs @@ -34,12 +34,14 @@ snapshot_cgp_auto_getter! { >, { fn name(&self) -> __Context__::Name { - self.get_field( + ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .clone() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/mref.rs b/crates/tests/cgp-tests/tests/getters/mref.rs index 314b7908c..c5726f1d3 100644 --- a/crates/tests/cgp-tests/tests/getters/mref.rs +++ b/crates/tests/cgp-tests/tests/getters/mref.rs @@ -90,12 +90,12 @@ snapshot_cgp_getter! { { fn foo(__context__: &__Context__) -> MRef<'_, String> { MRef::Ref( - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - >, - ), + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, + >, + ), ) } } @@ -111,7 +111,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = String>, { fn foo(__context__: &__Context__) -> MRef<'_, String> { - MRef::Ref(__context__.get_field(::core::marker::PhantomData::<__Tag__>)) + MRef::Ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/mref_auto.rs b/crates/tests/cgp-tests/tests/getters/mref_auto.rs index c955c4cb2..ba61807af 100644 --- a/crates/tests/cgp-tests/tests/getters/mref_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mref_auto.rs @@ -27,12 +27,12 @@ snapshot_cgp_auto_getter! { { fn foo(&self) -> MRef<'_, String> { MRef::Ref( - self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - >, - ), + HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, + >, + ), ) } } diff --git a/crates/tests/cgp-tests/tests/getters/mut_getter.rs b/crates/tests/cgp-tests/tests/getters/mut_getter.rs index 1aecec316..2149b9f57 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_getter.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_getter.rs @@ -94,15 +94,15 @@ snapshot_cgp_getter! { >, { fn count(__context__: &mut __Context__) -> &mut u32 { - __context__ - .get_field_mut( - ::core::marker::PhantomData::< - Symbol< - 5, - Chars<'c', Chars<'o', Chars<'u', Chars<'n', Chars<'t', Nil>>>>>, - >, + HasFieldMut::get_field_mut( + __context__, + ::core::marker::PhantomData::< + Symbol< + 5, + Chars<'c', Chars<'o', Chars<'u', Chars<'n', Chars<'t', Nil>>>>>, >, - ) + >, + ) } } impl<__Context__> IsProviderFor for UseFields @@ -117,7 +117,7 @@ snapshot_cgp_getter! { __Context__: HasFieldMut<__Tag__, Value = u32>, { fn count(__context__: &mut __Context__) -> &mut u32 { - __context__.get_field_mut(::core::marker::PhantomData::<__Tag__>) + HasFieldMut::get_field_mut(__context__, ::core::marker::PhantomData::<__Tag__>) } } impl<__Context__, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/mut_option_auto.rs b/crates/tests/cgp-tests/tests/getters/mut_option_auto.rs index d763c32e8..fe1f945d7 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_option_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_option_auto.rs @@ -26,12 +26,14 @@ snapshot_cgp_auto_getter! { >, { fn foo(&mut self) -> Option<&mut u32> { - self.get_field_mut( + ::core::option::Option::as_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_mut() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/mut_option_str_auto.rs b/crates/tests/cgp-tests/tests/getters/mut_option_str_auto.rs index fa425acd2..4042e848a 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_option_str_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_option_str_auto.rs @@ -27,12 +27,14 @@ snapshot_cgp_auto_getter! { >, { fn name(&mut self) -> Option<&mut str> { - self.get_field_mut( + ::core::option::Option::as_deref_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .as_deref_mut() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/mut_ref_auto.rs b/crates/tests/cgp-tests/tests/getters/mut_ref_auto.rs index 1e565a9a5..82a578426 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_ref_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_ref_auto.rs @@ -27,7 +27,8 @@ snapshot_cgp_auto_getter! { >, { fn count(&mut self) -> &mut u32 { - self.get_field_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol< 5, diff --git a/crates/tests/cgp-tests/tests/getters/mut_slice.rs b/crates/tests/cgp-tests/tests/getters/mut_slice.rs index 486b3e8de..1d3abfb83 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_slice.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_slice.rs @@ -92,41 +92,47 @@ snapshot_cgp_getter! { where __Context__: HasFieldMut< Symbol<5, Chars<'i', Chars<'t', Chars<'e', Chars<'m', Chars<'s', Nil>>>>>>, - Value: AsMut<[u32]> + 'static, + Value: ::core::convert::AsMut<[u32]> + 'static, >, { fn items(__context__: &mut __Context__) -> &mut [u32] { - __context__ - .get_field_mut( + ::core::convert::AsMut::as_mut( + HasFieldMut::get_field_mut( + __context__, ::core::marker::PhantomData::< Symbol< 5, Chars<'i', Chars<'t', Chars<'e', Chars<'m', Chars<'s', Nil>>>>>, >, >, - ) - .as_mut() + ), + ) } } impl<__Context__> IsProviderFor for UseFields where __Context__: HasFieldMut< Symbol<5, Chars<'i', Chars<'t', Chars<'e', Chars<'m', Chars<'s', Nil>>>>>>, - Value: AsMut<[u32]> + 'static, + Value: ::core::convert::AsMut<[u32]> + 'static, >, {} impl<__Context__, __Tag__> ItemsGetter<__Context__> for UseField<__Tag__> where - __Context__: HasFieldMut<__Tag__, Value: AsMut<[u32]> + 'static>, + __Context__: HasFieldMut<__Tag__, Value: ::core::convert::AsMut<[u32]> + 'static>, { fn items(__context__: &mut __Context__) -> &mut [u32] { - __context__.get_field_mut(::core::marker::PhantomData::<__Tag__>).as_mut() + ::core::convert::AsMut::as_mut( + HasFieldMut::get_field_mut( + __context__, + ::core::marker::PhantomData::<__Tag__>, + ), + ) } } impl<__Context__, __Tag__> IsProviderFor for UseField<__Tag__> where - __Context__: HasFieldMut<__Tag__, Value: AsMut<[u32]> + 'static>, + __Context__: HasFieldMut<__Tag__, Value: ::core::convert::AsMut<[u32]> + 'static>, {} impl<__Context__, __Provider__> ItemsGetter<__Context__> for WithProvider<__Provider__> where @@ -137,11 +143,12 @@ snapshot_cgp_getter! { >, { fn items(__context__: &mut __Context__) -> &mut [u32] { - __Provider__::get_field_mut( + ::core::convert::AsMut::as_mut( + __Provider__::get_field_mut( __context__, ::core::marker::PhantomData::, - ) - .as_mut() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/mut_slice_auto.rs b/crates/tests/cgp-tests/tests/getters/mut_slice_auto.rs index 79aa4ac40..ddd3c2d3c 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_slice_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_slice_auto.rs @@ -23,16 +23,18 @@ snapshot_cgp_auto_getter! { where __Context__: HasFieldMut< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - Value: AsMut<[u32]> + 'static, + Value: ::core::convert::AsMut<[u32]> + 'static, >, { fn foo(&mut self) -> &mut [u32] { - self.get_field_mut( + ::core::convert::AsMut::as_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_mut() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/mut_str_auto.rs b/crates/tests/cgp-tests/tests/getters/mut_str_auto.rs index 78aea201a..cfcf678f6 100644 --- a/crates/tests/cgp-tests/tests/getters/mut_str_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/mut_str_auto.rs @@ -1,6 +1,6 @@ //! `#[cgp_auto_getter]` with a `&mut self` receiver returning `&mut str`: the //! blanket impl reads the `String` field mutably through `get_field_mut` (bounded -//! by `HasFieldMut`) and calls `.as_mut_str()`, so a `String` field can be exposed +//! by `HasFieldMut`) and calls `.as_mut()`, so a `String` field can be exposed //! as a mutable `&mut str`. //! //! See cgp-knowledge-base/cgp/reference/macros/cgp_auto_getter.md. @@ -27,12 +27,14 @@ snapshot_cgp_auto_getter! { >, { fn foo(&mut self) -> &mut str { - self.get_field_mut( + ::core::convert::AsMut::as_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_mut_str() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/non_self.rs b/crates/tests/cgp-tests/tests/getters/non_self.rs index 3aa7d3867..c660a6091 100644 --- a/crates/tests/cgp-tests/tests/getters/non_self.rs +++ b/crates/tests/cgp-tests/tests/getters/non_self.rs @@ -123,24 +123,24 @@ snapshot_cgp_getter! { >, { fn foo_bar(__context__: &__Context__::Foo) -> &__Context__::Bar { - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol< - 7, + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol< + 7, + Chars< + 'f', Chars< - 'f', + 'o', Chars< 'o', - Chars< - 'o', - Chars<'_', Chars<'b', Chars<'a', Chars<'r', Nil>>>>, - >, + Chars<'_', Chars<'b', Chars<'a', Chars<'r', Nil>>>>, >, >, >, >, - ) + >, + ) } } impl<__Context__> IsProviderFor for UseFields @@ -166,7 +166,7 @@ snapshot_cgp_getter! { __Context__::Foo: HasField<__Tag__, Value = __Context__::Bar>, { fn foo_bar(__context__: &__Context__::Foo) -> &__Context__::Bar { - __context__.get_field(::core::marker::PhantomData::<__Tag__>) + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>) } } impl<__Context__, __Tag__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/non_self_auto.rs b/crates/tests/cgp-tests/tests/getters/non_self_auto.rs index f703fb4df..075d40732 100644 --- a/crates/tests/cgp-tests/tests/getters/non_self_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/non_self_auto.rs @@ -49,24 +49,24 @@ snapshot_cgp_auto_getter! { >, { fn foo_bar(__context__: &__Context__::Foo) -> &__Context__::Bar { - __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol< - 7, + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol< + 7, + Chars< + 'f', Chars< - 'f', + 'o', Chars< 'o', - Chars< - 'o', - Chars<'_', Chars<'b', Chars<'a', Chars<'r', Nil>>>>, - >, + Chars<'_', Chars<'b', Chars<'a', Chars<'r', Nil>>>>, >, >, >, >, - ) + >, + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/option.rs b/crates/tests/cgp-tests/tests/getters/option.rs index 0e5dd2dc8..88fb96e8b 100644 --- a/crates/tests/cgp-tests/tests/getters/option.rs +++ b/crates/tests/cgp-tests/tests/getters/option.rs @@ -89,13 +89,14 @@ snapshot_cgp_getter! { >, { fn foo(__context__: &__Context__) -> Option<&String> { - __context__ - .get_field( + ::core::option::Option::as_ref( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_ref() + ), + ) } } impl<__Context__> IsProviderFor for UseFields @@ -110,7 +111,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = Option>, { fn foo(__context__: &__Context__) -> Option<&String> { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).as_ref() + ::core::option::Option::as_ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor @@ -123,11 +126,12 @@ snapshot_cgp_getter! { __Provider__: FieldGetter<__Context__, FooGetterComponent, Value = Option>, { fn foo(__context__: &__Context__) -> Option<&String> { - __Provider__::get_field( + ::core::option::Option::as_ref( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .as_ref() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/option_auto.rs b/crates/tests/cgp-tests/tests/getters/option_auto.rs index eb4a8de00..045c288cf 100644 --- a/crates/tests/cgp-tests/tests/getters/option_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/option_auto.rs @@ -26,12 +26,14 @@ snapshot_cgp_auto_getter! { >, { fn foo(&self) -> Option<&String> { - self.get_field( + ::core::option::Option::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_ref() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/option_str_auto.rs b/crates/tests/cgp-tests/tests/getters/option_str_auto.rs index c692f87e1..81bdd0c3a 100644 --- a/crates/tests/cgp-tests/tests/getters/option_str_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/option_str_auto.rs @@ -39,7 +39,9 @@ snapshot_cgp_auto_getter! { >, { fn nickname(&self) -> Option<&str> { - self.get_field( + OptionAsRef::option_as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 8, @@ -58,8 +60,8 @@ snapshot_cgp_auto_getter! { >, >, >, - ) - .as_deref() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/slice.rs b/crates/tests/cgp-tests/tests/getters/slice.rs index 217d3fc74..a52090734 100644 --- a/crates/tests/cgp-tests/tests/getters/slice.rs +++ b/crates/tests/cgp-tests/tests/getters/slice.rs @@ -86,38 +86,41 @@ snapshot_cgp_getter! { where __Context__: HasField< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - Value: AsRef<[u8]> + 'static, + Value: ::core::convert::AsRef<[u8]> + 'static, >, { fn foo(__context__: &__Context__) -> &[u8] { - __context__ - .get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_ref() + ), + ) } } impl<__Context__> IsProviderFor for UseFields where __Context__: HasField< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - Value: AsRef<[u8]> + 'static, + Value: ::core::convert::AsRef<[u8]> + 'static, >, {} impl<__Context__, __Tag__> FooGetter<__Context__> for UseField<__Tag__> where - __Context__: HasField<__Tag__, Value: AsRef<[u8]> + 'static>, + __Context__: HasField<__Tag__, Value: ::core::convert::AsRef<[u8]> + 'static>, { fn foo(__context__: &__Context__) -> &[u8] { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).as_ref() + ::core::convert::AsRef::as_ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor for UseField<__Tag__> where - __Context__: HasField<__Tag__, Value: AsRef<[u8]> + 'static>, + __Context__: HasField<__Tag__, Value: ::core::convert::AsRef<[u8]> + 'static>, {} impl<__Context__, __Provider__> FooGetter<__Context__> for WithProvider<__Provider__> where @@ -128,11 +131,12 @@ snapshot_cgp_getter! { >, { fn foo(__context__: &__Context__) -> &[u8] { - __Provider__::get_field( + ::core::convert::AsRef::as_ref( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .as_ref() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/slice_auto.rs b/crates/tests/cgp-tests/tests/getters/slice_auto.rs index 3798656f2..db99510bf 100644 --- a/crates/tests/cgp-tests/tests/getters/slice_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/slice_auto.rs @@ -22,16 +22,18 @@ snapshot_cgp_auto_getter! { where __Context__: HasField< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, - Value: AsRef<[u8]> + 'static, + Value: ::core::convert::AsRef<[u8]> + 'static, >, { fn foo(&self) -> &[u8] { - self.get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_ref() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/string.rs b/crates/tests/cgp-tests/tests/getters/string.rs index 9c4d44d83..e72f9c79f 100644 --- a/crates/tests/cgp-tests/tests/getters/string.rs +++ b/crates/tests/cgp-tests/tests/getters/string.rs @@ -1,5 +1,5 @@ //! `#[cgp_getter]` returning `&str`: the getter reads a `String` field and the -//! generated provider impls call `.as_str()`, so a `String` field can be exposed +//! generated provider impls call `.as_ref()`, so a `String` field can be exposed //! as `&str`. The context binds the source field by wiring to `UseField`. //! //! See cgp-knowledge-base/cgp/reference/macros/cgp_getter.md and @@ -89,13 +89,14 @@ snapshot_cgp_getter! { >, { fn foo(__context__: &__Context__) -> &str { - __context__ - .get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_str() + ), + ) } } impl<__Context__> IsProviderFor for UseFields @@ -110,7 +111,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).as_str() + ::core::convert::AsRef::as_ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor @@ -123,11 +126,12 @@ snapshot_cgp_getter! { __Provider__: FieldGetter<__Context__, FooGetterComponent, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __Provider__::get_field( + ::core::convert::AsRef::as_ref( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .as_str() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/string_auto.rs b/crates/tests/cgp-tests/tests/getters/string_auto.rs index 60cdb93ce..cb9fd2bf8 100644 --- a/crates/tests/cgp-tests/tests/getters/string_auto.rs +++ b/crates/tests/cgp-tests/tests/getters/string_auto.rs @@ -1,5 +1,5 @@ //! `#[cgp_auto_getter]` returning `&str`: the blanket impl reads a `String` -//! field named after the method and calls `.as_str()`, exposing a `String` field +//! field named after the method and calls `.as_ref()`, exposing a `String` field //! as `&str` without any wiring. //! //! See cgp-knowledge-base/cgp/reference/macros/cgp_auto_getter.md. @@ -26,12 +26,14 @@ snapshot_cgp_auto_getter! { >, { fn foo(&self) -> &str { - self.get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_str() + ), + ) } } ") diff --git a/crates/tests/cgp-tests/tests/getters/string_custom_name.rs b/crates/tests/cgp-tests/tests/getters/string_custom_name.rs index 630011408..d935a67e6 100644 --- a/crates/tests/cgp-tests/tests/getters/string_custom_name.rs +++ b/crates/tests/cgp-tests/tests/getters/string_custom_name.rs @@ -89,13 +89,14 @@ snapshot_cgp_getter! { >, { fn foo(__context__: &__Context__) -> &str { - __context__ - .get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_str() + ), + ) } } impl<__Context__> IsProviderFor for UseFields @@ -110,7 +111,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).as_str() + ::core::convert::AsRef::as_ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor @@ -123,11 +126,12 @@ snapshot_cgp_getter! { __Provider__: FieldGetter<__Context__, GetStringComponent, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __Provider__::get_field( + ::core::convert::AsRef::as_ref( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .as_str() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/getters/string_custom_spec.rs b/crates/tests/cgp-tests/tests/getters/string_custom_spec.rs index ad5fcbcad..ef9476af1 100644 --- a/crates/tests/cgp-tests/tests/getters/string_custom_spec.rs +++ b/crates/tests/cgp-tests/tests/getters/string_custom_spec.rs @@ -83,13 +83,14 @@ snapshot_cgp_getter! { >, { fn foo(__context__: &__Context__) -> &str { - __context__ - .get_field( + ::core::convert::AsRef::as_ref( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol<3, Chars<'f', Chars<'o', Chars<'o', Nil>>>>, >, - ) - .as_str() + ), + ) } } impl<__Context__> IsProviderFor for UseFields @@ -104,7 +105,9 @@ snapshot_cgp_getter! { __Context__: HasField<__Tag__, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __context__.get_field(::core::marker::PhantomData::<__Tag__>).as_str() + ::core::convert::AsRef::as_ref( + HasField::get_field(__context__, ::core::marker::PhantomData::<__Tag__>), + ) } } impl<__Context__, __Tag__> IsProviderFor @@ -117,11 +120,12 @@ snapshot_cgp_getter! { __Provider__: FieldGetter<__Context__, GetStringComp, Value = String>, { fn foo(__context__: &__Context__) -> &str { - __Provider__::get_field( + ::core::convert::AsRef::as_ref( + __Provider__::get_field( __context__, ::core::marker::PhantomData::, - ) - .as_str() + ), + ) } } impl<__Context__, __Provider__> IsProviderFor diff --git a/crates/tests/cgp-tests/tests/higher_order_providers/use_provider_impl.rs b/crates/tests/cgp-tests/tests/higher_order_providers/use_provider_impl.rs index f07bc756a..11a9c835a 100644 --- a/crates/tests/cgp-tests/tests/higher_order_providers/use_provider_impl.rs +++ b/crates/tests/cgp-tests/tests/higher_order_providers/use_provider_impl.rs @@ -76,8 +76,9 @@ snapshot_cgp_impl! { Inner: AreaCalculator<__Context__>, { fn area(__context__: &__Context__) -> f64 { - let scale_factor: f64 = __context__ - .get_field( + let scale_factor: f64 = ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 12, @@ -108,8 +109,8 @@ snapshot_cgp_impl! { >, >, >, - ) - .clone(); + ), + ); Inner::area(__context__) * scale_factor * scale_factor } } diff --git a/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_extend.rs b/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_extend.rs index e8aa6fc30..8bbe5df7e 100644 --- a/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_extend.rs +++ b/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_extend.rs @@ -63,18 +63,20 @@ snapshot_cgp_fn! { >, { fn rectangle_area(&self) -> Self::Scalar { - let width: Self::Scalar = self - .get_field( + let width: Self::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: Self::Scalar = self - .get_field( + ), + ); + let height: Self::Scalar = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -87,8 +89,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); width * height } } diff --git a/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_uses.rs b/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_uses.rs index a021ac18f..95647d4ca 100644 --- a/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_uses.rs +++ b/crates/tests/cgp-tests/tests/impl_side_dependencies/fn_uses.rs @@ -71,8 +71,9 @@ snapshot_cgp_fn! { >, { fn scaled_rectangle_area(&self) -> f64 { - let scale_factor: f64 = self - .get_field( + let scale_factor: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 12, @@ -103,8 +104,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); self.rectangle_area() * scale_factor * scale_factor } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_calling_fn.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_calling_fn.rs index a62a21ad8..67cbb7ab4 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_calling_fn.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_calling_fn.rs @@ -40,18 +40,20 @@ snapshot_cgp_fn! { >, { fn rectangle_area(&self) -> f64 { - let width: f64 = self - .get_field( + let width: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: f64 = self - .get_field( + ), + ); + let height: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -64,8 +66,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); width * height } } @@ -125,8 +127,9 @@ snapshot_cgp_fn! { >, { fn scaled_rectangle_area(&self) -> f64 { - let scale_factor: f64 = self - .get_field( + let scale_factor: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 12, @@ -157,8 +160,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); self.rectangle_area() * scale_factor * scale_factor } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_custom_trait_name.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_custom_trait_name.rs index ebf913f46..c734af9af 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_custom_trait_name.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_custom_trait_name.rs @@ -37,18 +37,20 @@ snapshot_cgp_fn! { >, { fn rectangle_area(&self) -> f64 { - let width: f64 = self - .get_field( + let width: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: f64 = self - .get_field( + ), + ); + let height: f64 = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -61,8 +63,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .clone(); + ), + ); width * height } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_greet.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_greet.rs index 349287d21..0290d5673 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_greet.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_greet.rs @@ -1,7 +1,7 @@ //! `#[cgp_fn]` with a single `#[implicit]` `&str` argument. //! //! The implicit `name` is dropped from the signature and read from the context's -//! `name` field via `HasField`, with `.as_str()` applied automatically. The +//! `name` field via `HasField`, with `.as_ref()` applied automatically. The //! `CheckPerson` bound proves any context with a `name: String` field implements //! the generated trait. //! @@ -28,17 +28,18 @@ snapshot_cgp_fn! { where Self: HasField< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - Value = String, + Value: ::core::convert::AsRef + 'static, >, { fn greet(&self) { - let name: &str = self - .get_field( + let name: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .as_str(); + ), + ); println!("Hello, {}!", name); } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_multi_and_use_type.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_multi_and_use_type.rs index f39526674..137cfd492 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_multi_and_use_type.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_multi_and_use_type.rs @@ -74,30 +74,30 @@ snapshot_cgp_fn! { Self: HasBarType, { async fn do_foo_bar(&self, x: X, y: Y) -> Option<::Baz> { - let foo_x: &>::Foo = self - .get_field( - ::core::marker::PhantomData::< - Symbol< - 5, - Chars<'f', Chars<'o', Chars<'o', Chars<'_', Chars<'x', Nil>>>>>, - >, + let foo_x: &>::Foo = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol< + 5, + Chars<'f', Chars<'o', Chars<'o', Chars<'_', Chars<'x', Nil>>>>>, >, - ); - let foo_y: &>::Foo = self - .get_field( - ::core::marker::PhantomData::< - Symbol< - 5, - Chars<'f', Chars<'o', Chars<'o', Chars<'_', Chars<'y', Nil>>>>>, - >, + >, + ); + let foo_y: &>::Foo = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol< + 5, + Chars<'f', Chars<'o', Chars<'o', Chars<'_', Chars<'y', Nil>>>>>, >, - ); - let bar: &::Bar = self - .get_field( - ::core::marker::PhantomData::< - Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, - >, - ); + >, + ); + let bar: &::Bar = HasField::get_field( + self, + ::core::marker::PhantomData::< + Symbol<3, Chars<'b', Chars<'a', Chars<'r', Nil>>>>, + >, + ); None } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_self_immutable.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_self_immutable.rs index 7df14b42f..deefe9d6d 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_self_immutable.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_self_immutable.rs @@ -37,7 +37,7 @@ snapshot_cgp_fn! { Chars<'r', Chars<'e', Chars<'f', Chars<'i', Chars<'x', Nil>>>>>, >, >, - Value = String, + Value: ::core::convert::AsRef + 'static, > + HasField< Symbol< @@ -47,12 +47,13 @@ snapshot_cgp_fn! { Chars<'u', Chars<'f', Chars<'f', Chars<'i', Chars<'x', Nil>>>>>, >, >, - Value = String, + Value: ::core::convert::AsRef + 'static, >, { fn format_label(&mut self) -> String { - let prefix: &str = self - .get_field( + let prefix: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -65,10 +66,11 @@ snapshot_cgp_fn! { >, >, >, - ) - .as_str(); - let suffix: &str = self - .get_field( + ), + ); + let suffix: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 6, @@ -81,8 +83,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .as_str(); + ), + ); format!("{prefix}-{suffix}") } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_slice.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_slice.rs index cb77ca8cc..7bb5c9b56 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_slice.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mut_slice.rs @@ -32,17 +32,18 @@ snapshot_cgp_fn! { where Self: HasFieldMut< Symbol<4, Chars<'d', Chars<'a', Chars<'t', Chars<'a', Nil>>>>>, - Value: AsMut<[u8]> + 'static, + Value: ::core::convert::AsMut<[u8]> + 'static, >, { fn zero_all(&mut self) { - let data: &mut [u8] = self - .get_field_mut( + let data: &mut [u8] = ::core::convert::AsMut::as_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'d', Chars<'a', Chars<'t', Chars<'a', Nil>>>>>, >, - ) - .as_mut(); + ), + ); for byte in data.iter_mut() { *byte = 0; } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mutable.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mutable.rs index 6da70f2be..9d7459229 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mutable.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_mutable.rs @@ -36,12 +36,12 @@ snapshot_cgp_fn! { >, { fn capitalize_name(&mut self) { - let name: &mut String = self - .get_field_mut( - ::core::marker::PhantomData::< - Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - >, - ); + let name: &mut String = HasFieldMut::get_field_mut( + self, + ::core::marker::PhantomData::< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + ); if let Some(first_char) = name.chars().next() && first_char.is_lowercase() { let char_len = first_char.len_utf8(); let capitalized = first_char.to_uppercase().to_string(); diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_mut.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_mut.rs index e685a1897..91f2fe527 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_mut.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_mut.rs @@ -36,13 +36,14 @@ snapshot_cgp_fn! { >, { fn clear_slot(&mut self) { - let slot: Option<&mut u8> = self - .get_field_mut( + let slot: Option<&mut u8> = ::core::option::Option::as_mut( + HasFieldMut::get_field_mut( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'s', Chars<'l', Chars<'o', Chars<'t', Nil>>>>>, >, - ) - .as_mut(); + ), + ); if let Some(value) = slot { *value = 0; } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_str.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_str.rs index caa29fa6d..a7733c042 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_str.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_option_str.rs @@ -43,12 +43,13 @@ snapshot_cgp_fn! { >, >, >, - Value = Option, + Value: OptionAsRef + 'static, >, { fn describe(&self) -> String { - let nickname: Option<&str> = self - .get_field( + let nickname: Option<&str> = OptionAsRef::option_as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 8, @@ -67,8 +68,8 @@ snapshot_cgp_fn! { >, >, >, - ) - .as_deref(); + ), + ); match nickname { Some(name) => format!("aka {name}"), None => "anonymous".to_owned(), diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_owned_tuple.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_owned_tuple.rs index bb3d4fc56..c593fc586 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_owned_tuple.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_owned_tuple.rs @@ -31,16 +31,17 @@ snapshot_cgp_fn! { >, { fn origin_distance(&self) -> f64 { - let point: (f64, f64) = self - .get_field( + let point: (f64, f64) = ::core::clone::Clone::clone( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol< 5, Chars<'p', Chars<'o', Chars<'i', Chars<'n', Chars<'t', Nil>>>>>, >, >, - ) - .clone(); + ), + ); (point.0 * point.0 + point.1 * point.1).sqrt() } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_slice.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_slice.rs index e158513c9..2db751805 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_slice.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_fn_slice.rs @@ -30,17 +30,18 @@ snapshot_cgp_fn! { where Self: HasField< Symbol<4, Chars<'d', Chars<'a', Chars<'t', Chars<'a', Nil>>>>>, - Value: AsRef<[u8]> + 'static, + Value: ::core::convert::AsRef<[u8]> + 'static, >, { fn count_matches(&mut self, byte: u8) -> usize { - let data: &[u8] = self - .get_field( + let data: &[u8] = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'d', Chars<'a', Chars<'t', Chars<'a', Nil>>>>>, >, - ) - .as_ref(); + ), + ); data.iter().filter(|b| **b == byte).count() } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit.rs index e42a5143d..3498cc084 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit.rs @@ -47,18 +47,20 @@ snapshot_cgp_impl! { >, { fn area(__context__: &__Context__) -> f64 { - let width: f64 = __context__ - .get_field( + let width: f64 = ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 5, Chars<'w', Chars<'i', Chars<'d', Chars<'t', Chars<'h', Nil>>>>>, >, >, - ) - .clone(); - let height: f64 = __context__ - .get_field( + ), + ); + let height: f64 = ::core::clone::Clone::clone( + HasField::get_field( + __context__, ::core::marker::PhantomData::< Symbol< 6, @@ -71,8 +73,8 @@ snapshot_cgp_impl! { >, >, >, - ) - .clone(); + ), + ); width * height } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_option_str.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_option_str.rs new file mode 100644 index 000000000..44c8ba1ec --- /dev/null +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_option_str.rs @@ -0,0 +1,103 @@ +//! `#[cgp_impl]` with an `Option<&str>` `#[implicit]` argument. +//! +//! The provider reads any `Option` whose `U` implements `AsRef` through the +//! `OptionAsRef` helper trait, so an `Option`, an `Option>`, or an +//! `Option>` field works and none needs an allocator. +//! +//! See cgp-knowledge-base/cgp/reference/macros/cgp_impl.md and +//! cgp-knowledge-base/cgp/reference/attributes/implicit.md. + +use cgp::prelude::*; +use cgp_macro_test_util::snapshot_cgp_impl; + +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +snapshot_cgp_impl! { + #[cgp_impl(new GreetNickname)] + impl Greeter { + fn greet(&self, #[implicit] nickname: Option<&str>) -> String { + match nickname { + Some(name) => format!("Hello, {name}!"), + None => "Hello!".to_owned(), + } + } + } + + expand_greet_nickname(output) { + insta::assert_snapshot!(output, @r#" + impl<__Context__> Greeter<__Context__> for GreetNickname + where + __Context__: HasField< + Symbol< + 8, + Chars< + 'n', + Chars< + 'i', + Chars< + 'c', + Chars<'k', Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + >, + >, + >, + Value: OptionAsRef + 'static, + >, + { + fn greet(__context__: &__Context__) -> String { + let nickname: Option<&str> = OptionAsRef::option_as_ref( + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol< + 8, + Chars< + 'n', + Chars< + 'i', + Chars< + 'c', + Chars< + 'k', + Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>, + >, + >, + >, + >, + >, + >, + ), + ); + match nickname { + Some(name) => format!("Hello, {name}!"), + None => "Hello!".to_owned(), + } + } + } + impl<__Context__> IsProviderFor for GreetNickname + where + __Context__: HasField< + Symbol< + 8, + Chars< + 'n', + Chars< + 'i', + Chars< + 'c', + Chars<'k', Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + >, + >, + >, + Value: OptionAsRef + 'static, + >, + {} + ///Provider `GreetNickname` for [`Greeter`]. + pub struct GreetNickname; + "#) + } +} diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str.rs new file mode 100644 index 000000000..9eb9123af --- /dev/null +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str.rs @@ -0,0 +1,58 @@ +//! `#[cgp_impl]` with a `&str` `#[implicit]` argument. +//! +//! The provider reads any `AsRef` field through `.as_ref()`, so a `String`, a +//! `Cow`, or a `Box` field works and none needs an allocator. The bound +//! lands on the provider's `IsProviderFor` impl, like any other implicit argument. +//! +//! See cgp-knowledge-base/cgp/reference/macros/cgp_impl.md and +//! cgp-knowledge-base/cgp/reference/attributes/implicit.md. + +use cgp::prelude::*; +use cgp_macro_test_util::snapshot_cgp_impl; + +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +snapshot_cgp_impl! { + #[cgp_impl(new GreetHello)] + impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } + } + + expand_greet_hello(output) { + insta::assert_snapshot!(output, @r#" + impl<__Context__> Greeter<__Context__> for GreetHello + where + __Context__: HasField< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + Value: ::core::convert::AsRef + 'static, + >, + { + fn greet(__context__: &__Context__) -> String { + let name: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + ), + ); + format!("Hello, {name}!") + } + } + impl<__Context__> IsProviderFor for GreetHello + where + __Context__: HasField< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + Value: ::core::convert::AsRef + 'static, + >, + {} + ///Provider `GreetHello` for [`Greeter`]. + pub struct GreetHello; + "#) + } +} diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str_fields.rs b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str_fields.rs new file mode 100644 index 000000000..4ac69667b --- /dev/null +++ b/crates/tests/cgp-tests/tests/implicit_arguments/cgp_impl_implicit_str_fields.rs @@ -0,0 +1,77 @@ +//! A `#[cgp_impl]` `&str` implicit reads every `AsRef` field. +//! +//! The snapshot tests pin the expansion; this one runs the provider against a +//! `String`, a `&str`, and a `Cow` field, so the bound is exercised at runtime +//! as well as at compile time. +//! +//! See cgp-knowledge-base/cgp/reference/attributes/implicit.md. + +use std::borrow::Cow; + +use cgp::prelude::*; + +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } +} + +#[derive(HasField)] +pub struct WithString { + pub name: String, +} + +#[derive(HasField)] +pub struct WithStr<'a> { + pub name: &'a str, +} + +#[derive(HasField)] +pub struct WithCow<'a> { + pub name: Cow<'a, str>, +} + +delegate_components! { + WithString { + GreeterComponent: GreetHello, + } +} + +delegate_components! { + <'a> WithStr<'a> { + GreeterComponent: GreetHello, + } +} + +delegate_components! { + <'a> WithCow<'a> { + GreeterComponent: GreetHello, + } +} + +check_components! { + WithString { + GreeterComponent, + } +} + +#[test] +fn a_str_implicit_reads_every_as_ref_str_field() { + let with_string = WithString { + name: "a".to_owned(), + }; + let with_str = WithStr { name: "b" }; + let with_cow = WithCow { + name: Cow::Borrowed("c"), + }; + + assert_eq!(with_string.greet(), "Hello, a!"); + assert_eq!(with_str.greet(), "Hello, b!"); + assert_eq!(with_cow.greet(), "Hello, c!"); +} diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn.rs b/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn.rs index 5144aa8db..1cc8aea27 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn.rs @@ -34,17 +34,18 @@ snapshot_cgp_fn! { where Self: HasField< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - Value = String, + Value: ::core::convert::AsRef + 'static, >, { fn greet_fn(&self) -> String { - let name: &str = self - .get_field( + let name: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .as_str(); + ), + ); name.to_owned() } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn_without_doc.rs b/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn_without_doc.rs index 8a2f806e8..13ce9f511 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn_without_doc.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/doc_comment_on_cgp_fn_without_doc.rs @@ -28,17 +28,18 @@ snapshot_cgp_fn! { where Self: HasField< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - Value = String, + Value: ::core::convert::AsRef + 'static, >, { fn greet_fn(&self) -> String { - let name: &str = self - .get_field( + let name: &str = ::core::convert::AsRef::as_ref( + HasField::get_field( + self, ::core::marker::PhantomData::< Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, >, - ) - .as_str(); + ), + ); name.to_owned() } } diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/mod.rs b/crates/tests/cgp-tests/tests/implicit_arguments/mod.rs index c5762dbf7..a2d050d24 100644 --- a/crates/tests/cgp-tests/tests/implicit_arguments/mod.rs +++ b/crates/tests/cgp-tests/tests/implicit_arguments/mod.rs @@ -25,3 +25,11 @@ pub mod implicit_context; pub mod doc_comment_on_cgp_fn; // The gap-filling half: a function with no doc leaves the method with a generated line. pub mod doc_comment_on_cgp_fn_without_doc; + +pub mod str_field_probe; + +// `#[cgp_impl]` reads a `&str` and an `Option<&str>` implicit the same way +// `#[cgp_fn]` does, and the runtime test covers the three field types. +pub mod cgp_impl_implicit_option_str; +pub mod cgp_impl_implicit_str; +pub mod cgp_impl_implicit_str_fields; diff --git a/crates/tests/cgp-tests/tests/implicit_arguments/str_field_probe.rs b/crates/tests/cgp-tests/tests/implicit_arguments/str_field_probe.rs new file mode 100644 index 000000000..a95b56331 --- /dev/null +++ b/crates/tests/cgp-tests/tests/implicit_arguments/str_field_probe.rs @@ -0,0 +1,46 @@ +//! A `&str` implicit argument reads any `AsRef` field. +//! +//! The argument lowers to a `HasField + 'static>` bound and +//! reads the field with `.as_ref()`, so a `String`, a `&str`, or a `Cow` field +//! all work, and none of them needs an allocator. +//! +//! See cgp-knowledge-base/cgp/reference/attributes/implicit.md. + +use std::borrow::Cow; + +use cgp::prelude::*; + +#[cgp_fn] +pub fn greet_name(&self, #[implicit] name: &str) -> &str { + name +} + +#[derive(HasField)] +pub struct WithString { + pub name: String, +} + +#[derive(HasField)] +pub struct WithStr<'a> { + pub name: &'a str, +} + +#[derive(HasField)] +pub struct WithCow<'a> { + pub name: Cow<'a, str>, +} + +#[test] +fn a_str_implicit_reads_every_as_ref_str_field() { + let with_string = WithString { + name: "a".to_owned(), + }; + let with_str = WithStr { name: "b" }; + let with_cow = WithCow { + name: Cow::Borrowed("c"), + }; + + assert_eq!(with_string.greet_name(), "a"); + assert_eq!(with_str.greet_name(), "b"); + assert_eq!(with_cow.greet_name(), "c"); +} diff --git a/crates/tests/cgp-tests/tests/namespaces/default_impl_use_type.rs b/crates/tests/cgp-tests/tests/namespaces/default_impl_use_type.rs index b5c67dec4..f8da55b7a 100644 --- a/crates/tests/cgp-tests/tests/namespaces/default_impl_use_type.rs +++ b/crates/tests/cgp-tests/tests/namespaces/default_impl_use_type.rs @@ -52,12 +52,12 @@ snapshot_cgp_impl! { __Context__: HasNameType, { fn greet(__context__: &__Context__) -> String { - let name: &<__Context__ as HasNameType>::Name = __context__ - .get_field( - ::core::marker::PhantomData::< - Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, - >, - ); + let name: &<__Context__ as HasNameType>::Name = HasField::get_field( + __context__, + ::core::marker::PhantomData::< + Symbol<4, Chars<'n', Chars<'a', Chars<'m', Chars<'e', Nil>>>>>, + >, + ); format!("Hello, {name}!") } }