Repository: gtk-rs/gtk3-rs (language: rust)

Issue:
Unable to use `item` method from ListModel 
error message 
```
error[E0599]: no method named `item` found for reference `&torrent_model::TrTorrentModel` in the current scope
  --> src/transmission-gobject/src/torrent_model.rs:82:18
   |
82 |             self.item(index)
   |                  ^^^^ method not found in `&torrent_model::TrTorrentModel`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `item`, perhaps you need to implement it:
           candidate #1: `gio::subclass::prelude::ListModelImpl`

```

Interesting is, that I can use other methods from ListModel like `n_items`, but not `item`

relevant code snippets: 
```
    #[glib::object_subclass]
    impl ObjectSubclass for TrTorrentModel {
        const NAME: &'static str = "TrTorrentModel";
        type ParentType = glib::Object;
        type Type = super::TrTorrentModel;
        type Interfaces = (gio::ListModel,);
    }

    impl ObjectImpl for TrTorrentModel {}

    impl ListModelImpl for TrTorrentModel {
        fn item_type(&self, _list_model: &Self::Type) -> glib::Type {
            TrTorrent::static_type()
        }
        fn n_items(&self, _list_model: &Self::Type) -> u32 {
            self.vec.borrow().len() as u32
        }
        fn item(&self, _list_model: &Self::Type, position: u32) -> Option<glib::Object> {
            self.vec
                .borrow()
                .get(position as usize)
                .map(|o| o.clone().upcast::<glib::Object>())
        }
    }
```

```
glib::wrapper! {
    pub struct TrTorrentModel(ObjectSubclass<imp::TrTorrentModel>) @implements gio::ListModel;
}
```

complete code: https://pastebin.com/gmFra9Qh


Discussion / hints:
We just noticed that this method is named `object` instead of `item`. 

https://gtk-rs.org/gtk-rs/git/docs/gio/trait.ListModelExt.html#tymethod.object

I wonder if anything can be done here, to avoid confusion?
The get_object method has a rename-to annotation to rename it to `get_item` & it seems like that got lost during the whole get removal things. See https://developer.gnome.org/gio/stable/GListModel.html#g-list-model-get-object

cc @fengalin 
> The `get_object` method has a rename-to annotation to rename it to `get_item`

Are you sure? I couldn't find it in the history looking at the version prior to get removal.
Wait, does that mean we don't really handle the `rename-to` annotations? :) 
Are you talking about "shadows" in (Gio-2.0.gir, line 45 398):

`<method name="get_object" c:identifier="g_list_model_get_object" shadows="get_item" version="2.44">`
What exactly is the problem https://gtk-rs.org/gtk-rs/git/docs/gio/prelude/trait.ListModelExt.html#tymethod.object ?
@sdroege I think 

https://gtk-rs.org/gtk-rs/git/docs/gio/subclass/prelude/trait.ListModelImpl.html#tymethod.item

should be consistent with 

https://gtk-rs.org/gtk-rs/git/docs/gio/prelude/trait.ListModelExt.html#tymethod.object
Oh I see. Yes that would make sense.
> Are you talking about "shadows" in (Gio-2.0.gir, line 45 398):
> 
> `<method name="get_object" c:identifier="g_list_model_get_object" shadows="get_item" version="2.44">`

Yes, because the g_list_model_get_item isn't bindings friendly 
There's no match for "shadow" grepping `gir`, so I guess either we need an explicit `rename = "item"` in `Gir.toml` or fix `gir` to handle the "shadow" annotation.
I opened an issue on gir side to handle that someday in the future https://github.com/gtk-rs/gir/issues/1112

Fix patch:
diff --git a/gio/Gir.toml b/gio/Gir.toml
index 93c434d092d2..13a627ff36f1 100644
--- a/gio/Gir.toml
+++ b/gio/Gir.toml
@@ -661,6 +661,13 @@ manual_traits = ["IOStreamExtManual"]
 name = "Gio.ListModel"
 status = "generate"
 version = "2.44"
+    # Can get removed when gir shadow annotations are implemented (gtk-rs/gir#1112)
+    [[object.function]]
+    name = "get_item"
+    ignore = true
+    [[object.function]]
+    name = "get_object"
+    rename = "item"
 
 [[object]]
 name = "Gio.ListStore"
diff --git a/gio/src/auto/list_model.rs b/gio/src/auto/list_model.rs
index 5aa5908f519f..8e4317a6895e 100644
--- a/gio/src/auto/list_model.rs
+++ b/gio/src/auto/list_model.rs
@@ -22,9 +22,6 @@ glib::wrapper! {
 pub const NONE_LIST_MODEL: Option<&ListModel> = None;
 
 pub trait ListModelExt: 'static {
-    //#[doc(alias = "g_list_model_get_item")]
-    //fn item(&self, position: u32) -> /*Unimplemented*/Option<Fundamental: Pointer>;
-
     #[doc(alias = "g_list_model_get_item_type")]
     fn item_type(&self) -> glib::types::Type;
 
@@ -32,7 +29,7 @@ pub trait ListModelExt: 'static {
     fn n_items(&self) -> u32;
 
     #[doc(alias = "g_list_model_get_object")]
-    fn object(&self, position: u32) -> Option<glib::Object>;
+    fn item(&self, position: u32) -> Option<glib::Object>;
 
     #[doc(alias = "g_list_model_items_changed")]
     fn items_changed(&self, position: u32, removed: u32, added: u32);
@@ -44,10 +41,6 @@ pub trait ListModelExt: 'static {
 }
 
 impl<O: IsA<ListModel>> ListModelExt for O {
-    //fn item(&self, position: u32) -> /*Unimplemented*/Option<Fundamental: Pointer> {
-    //    unsafe { TODO: call ffi:g_list_model_get_item() }
-    //}
-
     fn item_type(&self) -> glib::types::Type {
         unsafe {
             from_glib(ffi::g_list_model_get_item_type(
@@ -60,7 +53,7 @@ impl<O: IsA<ListModel>> ListModelExt for O {
         unsafe { ffi::g_list_model_get_n_items(self.as_ref().to_glib_none().0) }
     }
 
-    fn object(&self, position: u32) -> Option<glib::Object> {
+    fn item(&self, position: u32) -> Option<glib::Object> {
         unsafe {
             from_glib_full(ffi::g_list_model_get_object(
                 self.as_ref().to_glib_none().0,


Test patch: