Skip to content

tags: fix index() lifetime bind

The signature for TagListRef::index didn't bind the lifetime of the returned TagValue to &self. This causes the following code to compile:

 1 let title = {
 2     let mut tags = TagList::new();
 3     {
 4         let tags = tags.get_mut().unwrap();
 5         tags.add::<Title>(&"some title", TagMergeMode::Append);
 6     }
 7
 8     let title = tags.index::<Title>(0).unwrap();
 9     assert_eq!(title.get(), "some title");
10
11     title
12 };
13
14 assert_eq!(title.get(), "some title");

... but it panics at runtime on the last title.get():

Invalid tag type: WrongValueType(ValueTypeMismatchError
    { actual: <invalid>, requested: gchararray })

Indeed, the title TagValue is freed with the tags on line 12.

This commit fixes the function signature so the returned TagValue can't outlive its TagListRef.

Merge request reports

Loading