Skip to content

Implement bound(*) to mean "all generic parameters" - #22

Merged
magiclen merged 20 commits into
magiclen:masterfrom
ijackson:all-bounds
Jun 1, 2024
Merged

Implement bound(*) to mean "all generic parameters"#22
magiclen merged 20 commits into
magiclen:masterfrom
ijackson:all-bounds

Conversation

@ijackson

Copy link
Copy Markdown
Contributor

This is new syntax, but it's old behavour: it's the behaviour of eg educe(Clone(bound)) in 0.4.x, as well as the behaviour of std. So this helps with migreation.

I'm not committed to this syntax, but it seems a reasonable choice out of the available options which don't already mean something in 0.5.x.

IMPORTANT: this branch is on top of the branch for #19. That MR should be reviewed and land first, before tackling this one. The new feature is just the top two commits here.

We'll want this in a moment.  No functional chnage.
* Make the internal wrapper type have *all* the parent's generics,
  and contain a PhantomData, so we can:
* Put the bounds on the Debug impl for the internal wrapper type.

* Rename the internal wrapper type to avoid name clashes with users' types.
* Rename the formatter variable to avoid name clashes with users's values.
Rather than trying to filter the generic parameters for ones used in
types, state the bounds in terms of the actual field types.

This is precisely correct.  It avoids lossage in situations where the
field type's implementation of the trait has bounds which depend in a
less-than-straightforward way on its generics.

There is still an issue with implementing traits which have
supertraits.  We ought to apply a `Self: Super` bound, but we don't
yet.
When we are implementing traits which have supertraits, add
bounds of the form `where Self: Super` for each supertrait.

While we're touching every call site, abolish the unused parameters.

(I have future plans that will want `params` in
into_where_predicates_by_generic_parameters_check_types, but not in
create_where_predicates_from_generic_parameters_check_types, so leave
that one there for now.)
Use the new precise bounds function.
Use the new precise bounds function, rather than the ident-hunter.

Apply the Clone supertrait explicitly.  This disposes of the oddity
mentioned in the comment, as will be demonstrated in a test.
Use the new precise bounds function.
This is no longer used, now that everything uses the precise bounds
function.
Nothing calls this.  And, nothing should, because it would give wrong
answers.

Rename create_where_predicates_from_generic_parameters to
create_where_predicates_from_all_generic_parameters.  This will be
useful if we implement a `bound(...)` syntax that allows requesting
the "apply a bound for each generic parameter, regardless" mode.

If we don't want to implement such a mode, we should delete this
function, but let's not entangle this already large bugfix MR with
questions about future features and UI.
@magiclen
magiclen merged commit b7567cb into magiclen:master Jun 1, 2024
@ijackson
ijackson deleted the all-bounds branch July 8, 2024 16:40
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