Skip to content

Add diagnostic helps for TiffValue proxy implementations#321

Merged
197g merged 3 commits intomainfrom
forward-tiff-value-for-vec-and-array
Jan 6, 2026
Merged

Add diagnostic helps for TiffValue proxy implementations#321
197g merged 3 commits intomainfrom
forward-tiff-value-for-vec-and-array

Conversation

@197g
Copy link
Member

@197g 197g commented Jan 6, 2026

We have a fundamental choice here: We could add more proxy implementations for Vec and Box to follow &'_ T, for some types that indirections is clear. Vec and arrays are also both very natural ways of expressing a repeated value. However, passing an allocated value to the interface forces us to drop it inside. We might be able to utilize the allocation for an in-place byteswap in a future increment but not with the current design.

So, overall, I think that inherently Drop-y types should be avoided in these implementations. Instead, we can use the amazing diagnostic tools in the compiler to just help the users navigate the type system. We can still provide the impl for arrays.

For context, see: https://users.rust-lang.org/t/what-type-is-u16/137395

Now they see:

    |
 38 |         .write_tag(tiff::tags::Tag::GeoKeyDirectoryTag, &geokey);
    |                                                          ^^^^^^ the trait `TiffValue` is not implemented for `&Vec<u16>`
    |
    = note: the trait is implemented for primitive types (`u8`, `i16`, `f32`, etc.)
    = note: the trait is implemented for shared references to values
    = note: the trait is implemented for slices, pass them by reference (e.g. `&[u8]`)
    = note: the trait is implemented for arrays if it is implemented for a slice
    = note: values in a `Vec` or `Box` should be dereferenced, e.g. `&vec[..]`
    = help: the following other types implement trait `TiffValue`:

Previously the compiler would both strip the & in its first message (due to our forwarding impl) and not list any way of getting a reference-to-slice nor make it obvious that this would resolve the situation. (There is a small 'try to dereference' but that is among a noise of type-system squabble and doesn't actually explain how this would affect the type and help).

197g added 2 commits January 6, 2026 17:26
We have a fundamental choice here: We could add more proxy
implementations for `Vec` and `Box` to follow `&'_ T`, for some types
that indirections is clear. Vec and arrays are also both very natural
ways of expressing a repeated value. However, passing an allocated value
to the interface forces us to drop it inside. We might be able to
utilize the allocation for an in-place byteswap in a future increment
but not with the current design.

So, overall, I think that inherently `Drop`-y types should be avoided in
these implementations. Instead, we can use the amazing diagnostic tools
in the compiler to just help the users navigate the type system. We can
still provide the impl for arrays.

For context, see: https://users.rust-lang.org/t/what-type-is-u16/137395

Now they see:

	    |
	 38 |         .write_tag(tiff::tags::Tag::GeoKeyDirectoryTag, &geokey);
	    |                                                          ^^^^^^ the trait `TiffValue` is not implemented for `&Vec<u16>`
	    |
	    = note: the trait is implemented for primitive types (`u8`, `i16`, `f32`, etc.)
	    = note: the trait is implemented for shared references to values
	    = note: the trait is implemented for slices, pass them by reference (e.g. `&[u8]`)
	    = note: the trait is implemented for arrays if it is implemented for a slice
	    = note: values in a `Vec` or `Box` should be dereferenced, e.g. `&vec[..]`
	    = help: the following other types implement trait `TiffValue`:

Previously the compiler would both strip the `&` in its first message
(due to our forwarding impl) and not list any way of getting a
reference-to-slice.
This gives us the diagnostic items. As a side effect we will have
`expect` for lints from 1.81 to apply in later PRs. It's time I think.
@197g 197g force-pushed the forward-tiff-value-for-vec-and-array branch from 6409c85 to 27bfcf5 Compare January 6, 2026 16:28
@197g 197g changed the title Add TiffValue proxy implementations Add lints for TiffValue proxy implementations Jan 6, 2026
@197g 197g changed the title Add lints for TiffValue proxy implementations Add diagnostic helps for TiffValue proxy implementations Jan 6, 2026
@197g 197g merged commit 923df5f into main Jan 6, 2026
15 checks passed
@197g 197g deleted the forward-tiff-value-for-vec-and-array branch January 6, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants