Skip to content
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

user defined const param type backcompat #6

Closed
lcnr opened this issue Feb 13, 2021 · 7 comments
Closed

user defined const param type backcompat #6

lcnr opened this issue Feb 13, 2021 · 7 comments

Comments

@lcnr
Copy link
Contributor

lcnr commented Feb 13, 2021

allowing a type to be used as a const parameter type adds some additional backcompat concerns.

For example adding raw/function pointer fields is suddenly a breaking change because the type stops being structural match.

How do we want to deal with this? Require the user to explicitly opt in, require all fields to be public (disqualifies NonZeroT), or something else?

@lcnr lcnr changed the title user defined const param type opt-in user defined const param type backcompat Feb 13, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Feb 14, 2021

We already have such behaviour for Send and Sync. So users already know that adding such fields can be breaking changes. I think as long as we aren't worse in UX than Send and Sync, this is fine?

@lcnr
Copy link
Contributor Author

lcnr commented Feb 14, 2021

hm, I guess I am a bit concerned because that interaction is a lot less obvious as I think many types aren't be intended to be used as const params. If there's a good way to avoid these issues I would prefer doing so.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 14, 2021

When you add a ptr to your struct you can also:

unsafe impl (Send/Sync) for Foo

but that's not an option with this I think

@oli-obk
Copy link
Contributor

oli-obk commented Feb 14, 2021

we could add an additional derive(StructuralMatch) requirement for any types used as const generics.

@varkor
Copy link
Member

varkor commented Feb 14, 2021

I'm surprised I can't find previous discussion on this topic: this is presumably a problem for anything involving structural equality, not just const generics. Having a new marker trait seems like the only plausible solution here.

@lcnr
Copy link
Contributor Author

lcnr commented Mar 2, 2021

had some further discussion about this on zulip: https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/meeting.202021-03-02/near/228441502

The consensus seems to be that we want to add an additional trait to opt into allowing types as const parameters as proposed in #6 (comment)

Still open is how exactly this interacts with structural match, it probably makes sense to try and get some conclusions from rust-lang/rust#74446. Maybe we can try and summarize the current status there and then talk about the remaining questions in a sync meeting?

@lcnr
Copy link
Contributor Author

lcnr commented Mar 28, 2022

closing this after summarizing the results in #34

@lcnr lcnr closed this as completed Mar 28, 2022
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

No branches or pull requests

4 participants