Skip to content

Commit

Permalink
glib-macros: Specify quoted types explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
felinira committed Apr 1, 2023
1 parent 3e6519c commit 1189a23
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions glib-macros/src/boxed_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::utils::{crate_ident_new, find_attribute_meta, find_nested_meta, parse
fn gen_option_to_ptr() -> TokenStream {
quote! {
match s {
Some(s) => ::std::boxed::Box::into_raw(::std::boxed::Box::new(s.clone())),
None => ::std::ptr::null_mut(),
::core::option::Option::Some(s) => ::std::boxed::Box::into_raw(::std::boxed::Box::new(s.clone())),
::core::option::Option::None => ::std::ptr::null_mut(),
};
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> TokenStream {

quote! {
impl #crate_ident::subclass::boxed::BoxedType for #name {
const NAME: &'static str = #gtype_name;
const NAME: &'static ::core::primitive::str = #gtype_name;
}

impl #crate_ident::StaticType for #name {
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> TokenStream {
impl #crate_ident::HasParamSpec for #name {
type ParamSpec = #crate_ident::ParamSpecBoxed;
type SetValue = Self;
type BuilderFn = fn(&str) -> #crate_ident::ParamSpecBoxedBuilder<Self>;
type BuilderFn = fn(&::core::primitive::str) -> #crate_ident::ParamSpecBoxedBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
|name| Self::ParamSpec::builder(name)
Expand Down
2 changes: 1 addition & 1 deletion glib-macros/src/downgrade_derive/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn derive_downgrade_for_enum(
type Strong = #ident #generics;

fn upgrade(&self) -> ::core::option::Option<Self::Strong> {
Some(match self {#(
::core::option::Option::Some(match self {#(
#upgrade_variants
),*})
}
Expand Down
2 changes: 1 addition & 1 deletion glib-macros/src/downgrade_derive/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn derive_downgrade_for_struct(

fn upgrade(&self) -> ::core::option::Option<Self::Strong> {
let Self #destruct = self;
Some(#ident #upgrade)
::core::option::Option::Some(#ident #upgrade)
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion glib-macros/src/enum_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn impl_enum(input: &syn::DeriveInput) -> TokenStream {
impl #crate_ident::HasParamSpec for #name {
type ParamSpec = #crate_ident::ParamSpecEnum;
type SetValue = Self;
type BuilderFn = fn(&str, Self) -> #crate_ident::ParamSpecEnumBuilder<Self>;
type BuilderFn = fn(&::core::primitive::str, Self) -> #crate_ident::ParamSpecEnumBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
|name, default_value| Self::ParamSpec::builder_with_default(name, default_value)
Expand Down
4 changes: 2 additions & 2 deletions glib-macros/src/error_domain_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn impl_error_domain(input: &syn::DeriveInput) -> TokenStream {

static QUARK: #crate_ident::once_cell::sync::Lazy<#crate_ident::Quark> =
#crate_ident::once_cell::sync::Lazy::new(|| unsafe {
from_glib(#crate_ident::ffi::g_quark_from_static_string(concat!(#domain_name, "\0") as *const str as *const _))
from_glib(#crate_ident::ffi::g_quark_from_static_string(concat!(#domain_name, "\0") as *const ::core::primitive::str as *const _))
});
*QUARK
}
Expand All @@ -48,7 +48,7 @@ pub fn impl_error_domain(input: &syn::DeriveInput) -> TokenStream {
#[inline]
fn from(value: i32) -> ::core::option::Option<Self>
where
Self: Sized
Self: std::marker::Sized
{
#from_glib
}
Expand Down
2 changes: 1 addition & 1 deletion glib-macros/src/flags_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn impl_flags(attrs: &NestedMeta, input: &DeriveInput) -> TokenStream {
impl #crate_ident::HasParamSpec for #name {
type ParamSpec = #crate_ident::ParamSpecFlags;
type SetValue = Self;
type BuilderFn = fn(&str) -> #crate_ident::ParamSpecFlagsBuilder<Self>;
type BuilderFn = fn(&::core::primitive::str) -> #crate_ident::ParamSpecFlagsBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
|name| Self::ParamSpec::builder(name)
Expand Down
10 changes: 5 additions & 5 deletions glib-macros/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ fn expand_wrapper_getset_properties(props: &[PropDesc]) -> TokenStream2 {
let ident = format_ident!("set_{}", ident);
let target_ty = quote!(<<#ty as #crate_ident::Property>::Value as #crate_ident::HasParamSpec>::SetValue);
let set_ty = if p.nullable {
quote!(Option<impl std::borrow::Borrow<#target_ty>>)
quote!(::core::option::Option<impl std::borrow::Borrow<#target_ty>>)
} else {
quote!(impl std::borrow::Borrow<#target_ty>)
};
Expand Down Expand Up @@ -558,7 +558,7 @@ fn expand_wrapper_connect_prop_notify(props: &[PropDesc]) -> TokenStream2 {
let fn_ident = format_ident!("connect_{}_notify", name_to_ident(name));
let span = p.attrs_span;
quote_spanned!(span=> pub fn #fn_ident<F: Fn(&Self) + 'static>(&self, f: F) -> #crate_ident::SignalHandlerId {
self.connect_notify_local(Some(#name), move |this, _| {
self.connect_notify_local(::core::option::Option::Some(#name), move |this, _| {
f(this)
})
})
Expand Down Expand Up @@ -619,10 +619,10 @@ fn expand_properties_enum(props: &[PropDesc]) -> TokenStream2 {
impl std::convert::TryFrom<usize> for DerivedPropertiesEnum {
type Error = usize;

fn try_from(item: usize) -> Result<Self, Self::Error> {
fn try_from(item: usize) -> ::core::result::Result<Self, Self::Error> {
match item {
#(#indices => Ok(Self::#properties),)*
_ => Err(item)
#(#indices => ::core::result::Result::Ok(Self::#properties),)*
_ => ::core::result::Result::Err(item)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions glib-macros/src/shared_boxed_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn gen_impl_to_value_optional(name: &Ident, crate_ident: &TokenStream) -> TokenS
let mut value = #crate_ident::Value::for_value_type::<Self>();
unsafe {
let ptr = match s {
Some(s) => #refcounted_type_prefix::into_raw(s.0.clone()),
None => ::std::ptr::null(),
::core::option::Option::Some(s) => #refcounted_type_prefix::into_raw(s.0.clone()),
::core::option::Option::None => ::std::ptr::null(),
};

#crate_ident::gobject_ffi::g_value_take_boxed(
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn impl_shared_boxed(input: &syn::DeriveInput) -> proc_macro2::TokenStream {

quote! {
impl #crate_ident::subclass::shared::SharedType for #name {
const NAME: &'static str = #gtype_name;
const NAME: &'static ::core::primitive::str = #gtype_name;

type RefCountedType = #refcounted_type;

Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn impl_shared_boxed(input: &syn::DeriveInput) -> proc_macro2::TokenStream {
impl #crate_ident::HasParamSpec for #name {
type ParamSpec = #crate_ident::ParamSpecBoxed;
type SetValue = Self;
type BuilderFn = fn(&str) -> #crate_ident::ParamSpecBoxedBuilder<Self>;
type BuilderFn = fn(&::core::primitive::str) -> #crate_ident::ParamSpecBoxedBuilder<Self>;

fn param_spec_builder() -> Self::BuilderFn {
|name| Self::ParamSpec::builder(name)
Expand Down
4 changes: 2 additions & 2 deletions glib-macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ pub fn gen_enum_from_glib(
let name = &v.ident;
quote_spanned! { v.span() =>
if value == #enum_name::#name as i32 {
return Some(#enum_name::#name);
return ::core::option::Option::Some(#enum_name::#name);
}
}
});
quote! {
#(#recurse)*
None
::core::option::Option::None
}
}
8 changes: 4 additions & 4 deletions glib-macros/src/value_delegate_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ pub fn impl_value_delegate(input: ValueDelegateInput) -> syn::Result<proc_macro:
let to_value_optional = nullable.then(|| {
quote! {
impl #crate_ident::value::ToValueOptional for #ident {
fn to_value_optional(s: Option<&Self>) -> #crate_ident::value::Value {
if let Some(this) = s {
#crate_ident::value::ToValue::to_value(&Some(&#delegate_value))
fn to_value_optional(s: ::core::option::Option<&Self>) -> #crate_ident::value::Value {
if let ::core::option::Option::Some(this) = s {
#crate_ident::value::ToValue::to_value(&::core::option::Option::Some(&#delegate_value))
} else {
#crate_ident::value::ToValueOptional::to_value_optional(None::<&#delegated_ty>)
#crate_ident::value::ToValueOptional::to_value_optional(::core::option::Option::None::<&#delegated_ty>)
}
}
}
Expand Down
48 changes: 24 additions & 24 deletions glib-macros/src/variant_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ fn derive_variant_for_struct(
impl #impl_generics #glib::FromVariant for #ident #type_generics #where_clause {
fn from_variant(variant: &#glib::Variant) -> ::core::option::Option<Self> {
if !variant.is_container() {
return None;
return ::core::option::Option::None;
}
Some(Self(
::core::option::Option::Some(Self(
#(
match variant.try_child_get::<#types>(#idents) {
Ok(Some(field)) => field,
_ => return None,
::core::result::Result::Ok(::core::option::Option::Some(field)) => field,
_ => return ::core::option::Option::None,
}
),*
))
Expand Down Expand Up @@ -182,13 +182,13 @@ fn derive_variant_for_struct(
impl #impl_generics #glib::FromVariant for #ident #type_generics #where_clause {
fn from_variant(variant: &#glib::Variant) -> ::core::option::Option<Self> {
if !variant.is_container() {
return None;
return ::core::option::Option::None;
}
Some(Self {
::core::option::Option::Some(Self {
#(
#idents: match variant.try_child_get::<#types>(#counts) {
Ok(Some(field)) => field,
_ => return None,
::core::result::Result::Ok(::core::option::Option::Some(field)) => field,
_ => return ::core::option::Option::None,
}
),*
})
Expand Down Expand Up @@ -227,7 +227,7 @@ fn derive_variant_for_struct(
let from_variant = quote! {
impl #impl_generics #glib::FromVariant for #ident #type_generics #where_clause {
fn from_variant(variant: &#glib::Variant) -> ::core::option::Option<Self> {
Some(Self)
::core::option::Option::Some(Self)
}
}
};
Expand Down Expand Up @@ -421,13 +421,13 @@ fn derive_variant_for_enum(
)?
}
});
quote! { #tag => ::std::option::Option::Some(Self::#ident { #(#fields),* }), }
quote! { #tag => ::core::option::Option::Some(Self::#ident { #(#fields),* }), }
}
syn::Fields::Unnamed(FieldsUnnamed { unnamed, .. }) => {
let indices = 0..unnamed.iter().count();
let repr = unnamed.iter().map(|f| &f.ty);
quote! {
#tag => ::std::option::Option::Some(Self::#ident(
#tag => ::core::option::Option::Some(Self::#ident(
#(
<#repr as #glib::FromVariant>::from_variant(
&#glib::Variant::try_child_value(&value, #indices)?
Expand All @@ -437,7 +437,7 @@ fn derive_variant_for_enum(
}
}
syn::Fields::Unit => {
quote! { #tag => ::std::option::Option::Some(Self::#ident), }
quote! { #tag => ::core::option::Option::Some(Self::#ident), }
}
}
});
Expand Down Expand Up @@ -477,14 +477,14 @@ fn derive_variant_for_enum(
}

impl #impl_generics #glib::FromVariant for #ident #type_generics #where_clause {
fn from_variant(variant: &#glib::Variant) -> ::std::option::Option<Self> {
fn from_variant(variant: &#glib::Variant) -> ::core::option::Option<Self> {
let (tag, value) = <(#repr, #glib::Variant) as #glib::FromVariant>::from_variant(&variant)?;
if !#glib::VariantTy::is_tuple(#glib::Variant::type_(&value)) {
return ::std::option::Option::None;
return ::core::option::Option::None;
}
match #tag_match {
#(#from)*
_ => ::std::option::Option::None
_ => ::core::option::Option::None
}
}
}
Expand Down Expand Up @@ -520,8 +520,8 @@ fn derive_variant_for_c_enum(
quote! {
let tag = #glib::Variant::str(&variant)?;
match tag {
#(#nicks2 => ::std::option::Option::Some(Self::#idents2),)*
_ => ::std::option::Option::None
#(#nicks2 => ::core::option::Option::Some(Self::#idents2),)*
_ => ::core::option::Option::None
}
},
)
Expand All @@ -535,9 +535,9 @@ fn derive_variant_for_c_enum(
quote! {
let value = <#repr as #glib::FromVariant>::from_variant(&variant)?;
#(if value == Self::#idents as #repr {
return Some(Self::#idents);
return ::core::option::Option::Some(Self::#idents);
})*
None
::core::option::Option::None
},
)
}
Expand All @@ -554,10 +554,10 @@ fn derive_variant_for_c_enum(
quote! {
let ty = <Self as #glib::StaticType>::static_type();
let enum_class = #glib::EnumClass::new(ty);
let enum_class = ::std::option::Option::unwrap(enum_class);
let enum_class = ::core::option::Option::unwrap(enum_class);
let value = <Self as #glib::translate::IntoGlib>::into_glib(*self);
let value = #glib::EnumClass::value(&enum_class, value);
let value = ::std::option::Option::unwrap(value);
let value = ::core::option::Option::unwrap(value);
let nick = #glib::EnumValue::nick(&value);
#glib::ToVariant::to_variant(nick)
},
Expand All @@ -583,7 +583,7 @@ fn derive_variant_for_c_enum(
quote! {
let ty = <Self as #glib::StaticType>::static_type();
let flags_class = #glib::FlagsClass::new(ty);
let flags_class = ::std::option::Option::unwrap(flags_class);
let flags_class = ::core::option::Option::unwrap(flags_class);
let value = <Self as #glib::translate::IntoGlib>::into_glib(*self);
let s = #glib::FlagsClass::to_nick_string(&flags_class, value);
#glib::ToVariant::to_variant(&s)
Expand All @@ -593,7 +593,7 @@ fn derive_variant_for_c_enum(
let flags_class = #glib::FlagsClass::new(ty)?;
let s = #glib::Variant::str(&variant)?;
let value = #glib::FlagsClass::from_nick_string(&flags_class, s).ok()?;
Some(unsafe { #glib::translate::from_glib(value) })
::core::option::Option::Some(unsafe { #glib::translate::from_glib(value) })
},
),
};
Expand Down Expand Up @@ -624,7 +624,7 @@ fn derive_variant_for_c_enum(
}

impl #impl_generics #glib::FromVariant for #ident #type_generics #where_clause {
fn from_variant(variant: &#glib::Variant) -> ::std::option::Option<Self> {
fn from_variant(variant: &#glib::Variant) -> ::core::option::Option<Self> {
#from_variant
}
}
Expand Down

0 comments on commit 1189a23

Please sign in to comment.