From 7b2e4f0e861e56dbce05befaf28ab9e52bd13bf0 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Thu, 5 Sep 2024 16:28:15 +0900 Subject: [PATCH] glib-macros: Do not generate import of `Property{Get,Set}` in `Properties` --- glib-macros/src/properties.rs | 2 -- glib-macros/tests/properties.rs | 13 +++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/glib-macros/src/properties.rs b/glib-macros/src/properties.rs index 07c91891fc13..35ba2f7ccc4d 100644 --- a/glib-macros/src/properties.rs +++ b/glib-macros/src/properties.rs @@ -758,8 +758,6 @@ pub fn impl_derive_props(input: PropsMacroInput) -> TokenStream { }; let expanded = quote! { - use #crate_ident::property::{PropertyGet, PropertySet}; - #properties_enum impl #crate_ident::subclass::object::DerivedObjectProperties for #struct_ident { diff --git a/glib-macros/tests/properties.rs b/glib-macros/tests/properties.rs index 84b3ca69f695..b9ae8e289a71 100644 --- a/glib-macros/tests/properties.rs +++ b/glib-macros/tests/properties.rs @@ -182,6 +182,19 @@ mod foo { .expect("Setter to be only called once"); } } + + /// Checks that `Properties` does not pollute the scope with + /// trait imports, as it did in older versions. + #[test] + fn no_import_leaks() { + // `vec.get` can match these methods (in order of precedence): + // (1) ` as PropertyGet>::get` + // (2) `<[String]>::get` through deref of `Vec` + // Had the macro introduced `PropertyGet` into the scope, it would + // resolve to (1), which we do not want. + let vec: Vec = vec![String::new(); 2]; + assert_eq!(vec.get(1), Some(&String::new())); + } } glib::wrapper! {