Skip to content

Fix parsing for single-type transitive paths (#13) #14

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

Merged
merged 8 commits into from
May 22, 2025

Conversation

A-Manning
Copy link
Contributor

Fixes #13.

@bobozaur
Copy link
Owner

@A-Manning Thanks for doing this! I'm unfortunately a bit swamped but I promise to review this til the end of the week.

Copy link
Owner

@bobozaur bobozaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can polish this a bit more before merging.

Nevertheless, the underlying problem is a bit more subtle. Not only are at least two types required in the type list, but we need, in fact, at least two distinct types.

However, let's please not tackle that in this PR.

Cargo.toml Outdated
Comment on lines 23 to 24
[dev-dependencies]
trybuild = "1.0.104"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not use this.

There should not be many fail tests around the library but regardless of that we could make use of doc tests and compile_fail attribute to achieve the same thing. See https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it is hacky to use doc tests for this. The tests are not documentation

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason why such tests would not qualify as documentation since they pertain to the correct usage of the crate API.

Explicitly stating the invalid usage of the API in the crate docs with supporting examples is, at least to me, to be preferred.

Just to make it a bit more clear, I'd agree with the usage of trybuild for something like testing the macros from the sqlx crate, where the testing environment (like a live database) matters as well.

@A-Manning A-Manning force-pushed the 2025-03-17-fix-attr-parsing branch 3 times, most recently from 30b8cf5 to ba2ec29 Compare April 29, 2025 07:37
@A-Manning
Copy link
Contributor Author

we need, in fact, at least two distinct types.

It is possible to use Rust's type system to ensure that you have at least two distinct types, however it is quite awkward to do so. See https://docs.rs/typewit/latest/typewit/struct.TypeNe.html#method.with_fn

I think it is not worth checking this, as it would require either adding typewit as a dependency, or copying several definitions

@A-Manning A-Manning force-pushed the 2025-03-17-fix-attr-parsing branch from ba2ec29 to 82e4e84 Compare April 29, 2025 11:46
@bobozaur
Copy link
Owner

bobozaur commented Apr 29, 2025

It is possible to use Rust's type system to ensure that you have at least two distinct types, however it is quite awkward to do so. See https://docs.rs/typewit/latest/typewit/struct.TypeNe.html#method.with_fn

Interesting crate, haven't heard of it before!

But yeah, I wasn't thinking of going that far with the check as much as doing the humane amount of checking against the type names. That will obviously fail for type aliases and such, but the whole point behind the check as well as this PR is providing some nicer error messages.

The outcomes do not change, either compilation succeeds or fails. Going above and beyond just for that is indeed an overkill. Perhaps down the line if TypeId::of becomes stable in const contexts some const assert! checks could be introduced. EDIT: Nvm I was looking at https://doc.rust-lang.org/beta/std/intrinsics/fn.type_id.html returning a u128 which I believe could be compared at compile time by an assert! in a const context. But mixed that up with the actual TypeId that gets returned from the stable function.

@A-Manning A-Manning force-pushed the 2025-03-17-fix-attr-parsing branch from 82e4e84 to 2cb508e Compare April 29, 2025 11:56
@bobozaur
Copy link
Owner

bobozaur commented May 8, 2025

Hey @A-Manning , not meaning to rush but I was wondering if you plan to work on this more anytime soon. It seems there shouldn't be a lot more left.

If you're unable to (which is perfectly fine), would you mind if I wrap it up instead?

@A-Manning
Copy link
Contributor Author

would you mind if I wrap it up instead?

Feel free to push fixup commits and merge.
I can make the requested changes regarding Vec vs VecDeque this weekend.

I may of may not remove the trybuild dev dependency and use doctests instead, feel free to push this if you want to merge it sooner

@A-Manning A-Manning force-pushed the 2025-03-17-fix-attr-parsing branch from 2cb508e to 7835cb2 Compare May 12, 2025 10:02
@bobozaur bobozaur self-requested a review May 22, 2025 16:15
@bobozaur bobozaur force-pushed the 2025-03-17-fix-attr-parsing branch from 21bef46 to 8977be3 Compare May 22, 2025 16:21
Copy link
Owner

@bobozaur bobozaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@A-Manning I patched some things up and will merge this. Thank you very much for taking the time to work on this and for your contribution!

I'll soon follow up with some other changes. For all it's worth, I figured out how to enforce unique types in the path list by emulating what the static_assertions crate does here. It's actually so simple and yet so genius.

@bobozaur bobozaur merged commit 758aabf into bobozaur:main May 22, 2025
3 checks passed
@bobozaur bobozaur mentioned this pull request May 23, 2025
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.

Single-type paths cause generated impls to loop infinitely
2 participants