Skip to content

Commit

Permalink
Merge pull request #1502 from kawadakk/patch/fix-macro-properties-imp…
Browse files Browse the repository at this point in the history
…ort-leaks

glib-macros: Do not emit import of `Property{Get,Set}` in `Properties` derive macro
  • Loading branch information
sdroege committed Sep 5, 2024
2 parents a8b23f4 + 7b2e4f0 commit f444832
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 0 additions & 2 deletions glib-macros/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions glib-macros/tests/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) `<Vec<String> as PropertyGet>::get`
// (2) `<[String]>::get` through deref of `Vec<String>`
// Had the macro introduced `PropertyGet` into the scope, it would
// resolve to (1), which we do not want.
let vec: Vec<String> = vec![String::new(); 2];
assert_eq!(vec.get(1), Some(&String::new()));
}
}

glib::wrapper! {
Expand Down

0 comments on commit f444832

Please sign in to comment.