Skip to content

Feat: Allow lifetime for bounds in non-binded generic params #107

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 6 commits into from
Apr 15, 2025

Conversation

stegaBOB
Copy link
Contributor

It's currently not possible to use higher rank trait bounds without providing custom predicate type bounds. Our particular use case is enabling "trivial bounds" without requiring the nightly feature. For context: rust-lang/rust#48214 (comment)

For example:

// fails due to "the trait bound `std::string::String: std::marker::Copy` is not satisfied"
#[derive_where(Clone, Copy; String)]
struct TestThing {
    a: String,
}

// Compiles! Copy is just not implemented due to String obviously not being copy, so it would compile error on use.
#[derive_where(Clone, Copy; for<'a> String)]
struct TestThing {
    a: String,
}

This is useful for adding perfect derives to macro-generated structs.

I'm not fully sure whether having a HRTB should make has_type_param return false or not. I think its probably fine to keep it returning true since adding one that's not used doesn't change the behavior; it should still be derivable w/ the standard derive. Users can always make type aliases to get around this anyways if they disagree lol.

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

This is indeed a very strange quirk of Rust!

Please add a changelog entry as well.
Otherwise LGTM!

@stegaBOB stegaBOB requested a review from daxpedda April 14, 2025 21:35
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

  • Run cargo +nightly fmt.
  • Changelog entry.

@stegaBOB stegaBOB requested a review from daxpedda April 14, 2025 22:10
@stegaBOB
Copy link
Contributor Author

Completely missed the changelog request! Sorry about that. Should be good to go now I think

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Completely missed the changelog request! Sorry about that.

All good! I know how it is :)

Will wait for #108 before merging.

@daxpedda daxpedda force-pushed the stegaBOB/feat/for-lifetimes branch from e6acb63 to c882e1c Compare April 15, 2025 10:27
@daxpedda daxpedda merged commit 440496c into ModProg:main Apr 15, 2025
67 checks passed
@stegaBOB
Copy link
Contributor Author

stegaBOB commented Apr 16, 2025

Hey @daxpedda was wondering if there are any plans to cut a new release soon. We're currently working on a private registry so we aren't blocked on this or anything, but just wanted to ask since its been a while since the last one. Thanks! :)

Edit: just noticed the new PR... 🤦 that pretty much answers my question lol.

@daxpedda daxpedda mentioned this pull request Apr 16, 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.

2 participants