Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Generated broken futures code #1373

Open
alatiera opened this issue Jul 21, 2022 · 1 comment
Open

[BUG] Generated broken futures code #1373

alatiera opened this issue Jul 21, 2022 · 1 comment
Labels

Comments

@alatiera
Copy link

While trying to generate bindings against glib 2.73+ in gtk-rs/gtk-rs-core#717 , gir tries to generate the following code which doesn't compile.

    #[cfg(any(feature = "v2_74", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_74")))]
    pub fn new_tmp_future(
        tmpl: Option<impl AsRef<std::path::Path>>,
        io_priority: glib::Priority,
    ) -> Pin<
        Box_<dyn std::future::Future<Output = Result<(File, FileIOStream), glib::Error>> + 'static>,
    > {
        let tmpl = tmpl.map(ToOwned::to_owned);
        Box_::pin(crate::GioFuture::new(
            &(),
            move |_obj, cancellable, send| {
                Self::new_tmp_async(
                    tmpl.as_ref().map(::std::borrow::Borrow::borrow),
                    io_priority,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }
    
    #[cfg(any(feature = "v2_74", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_74")))]
    pub fn new_tmp_dir_future(
        tmpl: Option<impl AsRef<std::path::Path>>,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<File, glib::Error>> + 'static>> {
        let tmpl = tmpl.map(ToOwned::to_owned);
        Box_::pin(crate::GioFuture::new(
            &(),
            move |_obj, cancellable, send| {
                Self::new_tmp_dir_async(
                    tmpl.as_ref().map(::std::borrow::Borrow::borrow),
                    io_priority,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }
    
    #[cfg(any(feature = "v2_74", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_74")))]
    fn make_symbolic_link_future(
        &self,
        symlink_value: impl AsRef<std::path::Path>,
        io_priority: glib::Priority,
    ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
        let symlink_value = symlink_value.clone();
        Box_::pin(crate::GioFuture::new(
            self,
            move |obj, cancellable, send| {
                obj.make_symbolic_link_async(
                    &symlink_value,
                    io_priority,
                    Some(cancellable),
                    move |res| {
                        send.resolve(res);
                    },
                );
            },
        ))
    }

The code doesn't compile and the it needs the following changes:

diff --git a/gio/src/auto/file.rs b/gio/src/auto/file.rs
index bc2c6c4c8e3..8d165759630 100644
--- a/gio/src/auto/file.rs
+++ b/gio/src/auto/file.rs
@@ -164,12 +164,12 @@ impl File {
     ) -> Pin<
         Box_<dyn std::future::Future<Output = Result<(File, FileIOStream), glib::Error>> + 'static>,
     > {
-        let tmpl = tmpl.map(ToOwned::to_owned);
+        let tmpl = tmpl.map(|tmpl| tmpl.as_ref().to_owned());
         Box_::pin(crate::GioFuture::new(
             &(),
             move |_obj, cancellable, send| {
                 Self::new_tmp_async(
-                    tmpl.as_ref().map(::std::borrow::Borrow::borrow),
+                    tmpl.as_ref().map(<std::path::PathBuf as std::borrow::Borrow<std::path::Path>>::borrow),
                     io_priority,
                     Some(cancellable),
                     move |res| {
@@ -238,12 +238,12 @@ impl File {
         tmpl: Option<impl AsRef<std::path::Path>>,
         io_priority: glib::Priority,
     ) -> Pin<Box_<dyn std::future::Future<Output = Result<File, glib::Error>> + 'static>> {
-        let tmpl = tmpl.map(ToOwned::to_owned);
+        let tmpl = tmpl.map(|tmpl| tmpl.as_ref().to_owned());
         Box_::pin(crate::GioFuture::new(
             &(),
             move |_obj, cancellable, send| {
                 Self::new_tmp_dir_async(
-                    tmpl.as_ref().map(::std::borrow::Borrow::borrow),
+                    tmpl.as_ref().map(<std::path::PathBuf as std::borrow::Borrow<std::path::Path>>::borrow),
                     io_priority,
                     Some(cancellable),
                     move |res| {
@@ -2056,7 +2056,7 @@ impl<O: IsA<File>> FileExt for O {
         symlink_value: impl AsRef<std::path::Path>,
         io_priority: glib::Priority,
     ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
-        let symlink_value = symlink_value.clone();
+        let symlink_value = symlink_value.as_ref().to_owned();
         Box_::pin(crate::GioFuture::new(
             self,
             move |obj, cancellable, send| {

gir verion: 74b6e47
gir files: gtk-rs/gir-files@9e94571

@alatiera alatiera added the bug label Jul 21, 2022
@bilelmoussaoui
Copy link
Member

It is the same as #1261 no?

@bilelmoussaoui bilelmoussaoui transferred this issue from gtk-rs/gtk-rs-core Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants