Skip to content

Commit

Permalink
Fix for new Rust nightly warnings related to unnecessary qualificatio…
Browse files Browse the repository at this point in the history
…ns (#2911)
  • Loading branch information
kennykerr authored Mar 5, 2024
1 parent 1b4833c commit e31d823
Show file tree
Hide file tree
Showing 1,215 changed files with 1,005,631 additions and 1,006,643 deletions.
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/rdl/from_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Writer {
#tokens
};

let file = rdl::File::parse_str(&tokens.into_string())?;
let file = File::parse_str(&tokens.into_string())?;
write_to_file(output, file.fmt())
//write_to_file(output, tokens.into_string())
}
Expand Down Expand Up @@ -321,7 +321,7 @@ impl Writer {

fn ty(&self, ty: &metadata::Type) -> TokenStream {
match ty {
metadata::Type::Void => quote! { ::core::ffi::c_void },
metadata::Type::Void => quote! { core::ffi::c_void },
metadata::Type::Bool => quote! { bool },
metadata::Type::Char => quote! { u16 },
metadata::Type::I8 => quote! { i8 },
Expand Down
28 changes: 14 additions & 14 deletions crates/libs/bindgen/src/rust/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
if def.interface_impls().next().is_some() {
let name = to_ident(def.name());
quote! {
pub type #name = *mut ::core::ffi::c_void;
pub type #name = *mut core::ffi::c_void;
}
} else {
quote! {}
Expand Down Expand Up @@ -53,11 +53,11 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
return Some(quote! {
#[doc(hidden)]
#features
pub fn #interface_type<R, F: FnOnce(&#interface_type) -> ::windows_core::Result<R>>(
pub fn #interface_type<R, F: FnOnce(&#interface_type) -> windows_core::Result<R>>(
callback: F,
) -> ::windows_core::Result<R> {
static SHARED: ::windows_core::imp::FactoryCache<#name, #interface_type> =
::windows_core::imp::FactoryCache::new();
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<#name, #interface_type> =
windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
});
Expand All @@ -71,14 +71,14 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
if def.interface_impls().next().is_some() {
let new = if type_def_has_default_constructor(def) {
quote! {
pub fn new() -> ::windows_core::Result<Self> {
pub fn new() -> windows_core::Result<Self> {
Self::IActivationFactory(|f| f.ActivateInstance::<Self>())
}
fn IActivationFactory<R, F: FnOnce(&::windows_core::imp::IGenericFactory) -> ::windows_core::Result<R>>(
fn IActivationFactory<R, F: FnOnce(&windows_core::imp::IGenericFactory) -> windows_core::Result<R>>(
callback: F,
) -> ::windows_core::Result<R> {
static SHARED: ::windows_core::imp::FactoryCache<#name, ::windows_core::imp::IGenericFactory> =
::windows_core::imp::FactoryCache::new();
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<#name, windows_core::imp::IGenericFactory> =
windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
}
Expand All @@ -89,8 +89,8 @@ fn gen_class(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
let mut tokens = quote! {
#features
#[repr(transparent)]
#[derive(::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug, ::core::clone::Clone)]
pub struct #name(::windows_core::IUnknown);
#[derive(PartialEq, Eq, core::fmt::Debug, Clone)]
pub struct #name(windows_core::IUnknown);
};

tokens.combine(&gen_conversions(writer, def, &name, &interfaces, &cfg));
Expand Down Expand Up @@ -131,10 +131,10 @@ fn gen_conversions(writer: &Writer, def: metadata::TypeDef, ident: &TokenStream,
let features = writer.cfg_features(cfg);
let mut tokens = quote! {
#features
::windows_core::imp::interface_hierarchy!(#ident, ::windows_core::IUnknown, ::windows_core::IInspectable);
windows_core::imp::interface_hierarchy!(#ident, windows_core::IUnknown, windows_core::IInspectable);
};

let mut hierarchy = format!("::windows_core::imp::required_hierarchy!({ident}");
let mut hierarchy = format!("windows_core::imp::required_hierarchy!({ident}");
let mut hierarchy_cfg = cfg.clone();
let mut hierarchy_added = false;

Expand Down
62 changes: 31 additions & 31 deletions crates/libs/bindgen/src/rust/com_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface
let args = writer.win32_args(&signature.params, kind);
let params = writer.win32_params(&signature.params, kind);
let generics = expand_generics(generics, quote!(T));
let where_clause = expand_where_clause(where_clause, quote!(T: ::windows_core::Interface));
let where_clause = expand_where_clause(where_clause, quote!(T: windows_core::Interface));

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<T> #where_clause {
let mut result__ = ::std::ptr::null_mut();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).and_then(||::windows_core::Type::from_abi(result__))
pub unsafe fn #name<#generics>(&self, #params) -> windows_core::Result<T> #where_clause {
let mut result__ = std::ptr::null_mut();
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args).and_then(||windows_core::Type::from_abi(result__))
}
}
}
metadata::SignatureKind::QueryOptional(_) => {
let args = writer.win32_args(&signature.params, kind);
let params = writer.win32_params(&signature.params, kind);
let generics = expand_generics(generics, quote!(T));
let where_clause = expand_where_clause(where_clause, quote!(T: ::windows_core::Interface));
let where_clause = expand_where_clause(where_clause, quote!(T: windows_core::Interface));

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params result__: *mut ::core::option::Option<T>) -> ::windows_core::Result<()> #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).ok()
pub unsafe fn #name<#generics>(&self, #params result__: *mut Option<T>) -> windows_core::Result<()> #where_clause {
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args).ok()
}
}
}
Expand All @@ -58,16 +58,16 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface
let map = if metadata::type_is_blittable(&return_type) {
quote! { map(||result__) }
} else {
quote! { and_then(||::windows_core::Type::from_abi(result__)) }
quote! { and_then(||windows_core::Type::from_abi(result__)) }
};

let return_type = writer.type_name(&return_type);

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).#map
pub unsafe fn #name<#generics>(&self, #params) -> windows_core::Result<#return_type> #where_clause {
let mut result__ = std::mem::zeroed();
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args).#map
}
}
}
Expand All @@ -77,8 +77,8 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<()> #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args).ok()
pub unsafe fn #name<#generics>(&self, #params) -> windows_core::Result<()> #where_clause {
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args).ok()
}
}
}
Expand All @@ -93,26 +93,26 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> ::windows_core::Result<#return_type> #where_clause {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
::windows_core::Type::from_abi(result__)
pub unsafe fn #name<#generics>(&self, #params) -> windows_core::Result<#return_type> #where_clause {
let mut result__ = std::mem::zeroed();
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args);
windows_core::Type::from_abi(result__)
}
}
} else {
let map = if metadata::type_is_blittable(&return_type) {
quote! { result__ }
} else {
quote! { ::std::mem::transmute(result__) }
quote! { std::mem::transmute(result__) }
};

let return_type = writer.type_name(&return_type);

quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
let mut result__ = ::std::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args);
let mut result__ = std::mem::zeroed();
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args);
#map
}
}
Expand All @@ -126,8 +126,8 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface
quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) -> #return_type #where_clause {
let mut result__: #return_type = ::core::mem::zeroed();
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), &mut result__, #args);
let mut result__: #return_type = core::mem::zeroed();
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), &mut result__, #args);
result__
}
}
Expand All @@ -140,7 +140,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface
quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) #return_type #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args)
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args)
}
}
}
Expand All @@ -151,7 +151,7 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef, kind: metadata::Interface
quote! {
#features
pub unsafe fn #name<#generics>(&self, #params) #where_clause {
(::windows_core::Interface::vtable(self)#bases.#vname)(::windows_core::Interface::as_raw(self), #args)
(windows_core::Interface::vtable(self)#bases.#vname)(windows_core::Interface::as_raw(self), #args)
}
}
}
Expand All @@ -167,12 +167,12 @@ pub fn gen_upcall(writer: &Writer, sig: &metadata::Signature, inner: TokenStream

quote! {
match #inner(#(#invoke_args,)*) {
::core::result::Result::Ok(ok__) => {
Ok(ok__) => {
// use `core::ptr::write` since the result could be uninitialized
::core::ptr::write(#result, ::core::mem::transmute(ok__));
::windows_core::HRESULT(0)
core::ptr::write(#result, core::mem::transmute(ok__));
windows_core::HRESULT(0)
}
::core::result::Result::Err(err) => err.into()
Err(err) => err.into()
}
}
}
Expand Down Expand Up @@ -204,10 +204,10 @@ fn gen_win32_invoke_arg(writer: &Writer, param: &metadata::SignatureParam) -> To
let name = writer.param_name(param.def);

if param.def.flags().contains(metadata::ParamAttributes::In) && metadata::type_is_nullable(&param.ty) {
quote! { ::windows_core::from_raw_borrowed(&#name) }
quote! { windows_core::from_raw_borrowed(&#name) }
} else if (!param.ty.is_pointer() && metadata::type_is_nullable(&param.ty)) || (param.def.flags().contains(metadata::ParamAttributes::In) && !metadata::type_is_primitive(&param.ty)) {
quote! { ::core::mem::transmute(&#name) }
quote! { core::mem::transmute(&#name) }
} else {
quote! { ::core::mem::transmute_copy(&#name) }
quote! { core::mem::transmute_copy(&#name) }
}
}
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn field_initializer<'a>(writer: &Writer, field: metadata::Field, input: &'a str
// The Win32 metadata uses integer values for initializing pointers. This is a workaround
// to allow most such cases to work.
let (_, rest) = read_literal(input);
(quote! { #name: ::core::ptr::null_mut(), }, rest)
(quote! { #name: core::ptr::null_mut(), }, rest)
}
_ => {
let (literal, rest) = read_literal(input);
Expand Down
Loading

0 comments on commit e31d823

Please sign in to comment.