Help with `explicit generic argument not allowed` error

I'm trying to update my application to the newest version of gtk4-rs. I'm creating a pixbuf from a memory input stream.

        let pixbuf = Pixbuf::from_stream_at_scale::<MemoryInputStream, Cancellable>(
            &stream, width, -1, true, None,
        );

The compiler says this:

error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
   --> src/gui/mod.rs:200:53
    |
200 |         let pixbuf = Pixbuf::from_stream_at_scale::<MemoryInputStream, Cancellable>(
    |                                                     ^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^ explicit generic argument not allowed
    |                                                     |
    |                                                     explicit generic argument not allowed
    |
    = note: see issue #83701 <https://github.com/rust-lang/rust/issues/83701> for more information
    = help: add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable

For more information about this error, try `rustc --explain E0632`.
error: could not compile `gfret` due to previous error

Following that and adding #![feature(explicit_generic_args_with_impl_trait)] to the crate root I get:

error[E0107]: this associated function takes 0 generic arguments but 2 generic arguments were supplied
   --> src/gui/mod.rs:200:30
    |
200 |         let pixbuf = Pixbuf::from_stream_at_scale::<MemoryInputStream, Cancellable>(
    |                              ^^^^^^^^^^^^^^^^^^^^---------------------------------- help: remove these generics
    |                              |
    |                              expected 0 generic arguments
    |
note: associated function defined here, with 0 generic parameters
   --> /home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-pixbuf-0.15.1/src/auto/pixbuf.rs:137:12
    |
137 |     pub fn from_stream_at_scale(
    |            ^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0107`.
error: could not compile `gfret` due to previous error

Then removing the generic arguments so my code reads:

        let pixbuf = Pixbuf::from_stream_at_scale(
            &stream, width, -1, true, None,
        );

Now the compiler tells me this:

error[E0283]: type annotations needed
   --> src/gui/mod.rs:200:22
    |
200 |         let pixbuf = Pixbuf::from_stream_at_scale(
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `impl IsA<gio::Cancellable>` declared on the associated function `from_stream_at_scale`
    |
    = note: cannot satisfy `_: IsA<Cancellable>`
note: required by a bound in `Pixbuf::from_stream_at_scale`
   --> /home/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/gdk-pixbuf-0.15.1/src/auto/pixbuf.rs:142:35
    |
142 |         cancellable: Option<&impl IsA<gio::Cancellable>>,
    |                                   ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Pixbuf::from_stream_at_scale`

I'm unsure how to fix this.

The function doesn't take any generic paramters, so you can't pass generic parameters to it. To give a type hint for the option, you can type Option::<TypeGoesHere>::None

Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.