-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow referencing generic parameters inside array length expressions #140524
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
Comments
That is just
|
This is desirable and was an explicit limitation when stabilizing Handling this correctly has a lot of both technical and design questions, e.g. whether to allow constants which may result in monomorphization time evaluation errors in the type system and how equality of generic constants should work. |
Yeah, this is definitely not something we support in the type system at the moment. I'm a bit surprised as well that the issue body suggests that we FCP this -- it feels somewhat premature, rather than straight-up asking whether this is something we can support 😸 At best this is a diagnostics issue for now, and we can be a bit more explicit in justifying why we don't support this. For the record, we accidentally stabilized a somewhat morally related code piece of code: fn foo<T>() {
let x = [0u32; std::mem::size_of::<&T>()];
} This was not ever intended, though. See #76200 for an FCW. The only thing we support today (and we're definitely not planning to remove!!) is bare generic parameters, like |
OK, woah. It seems clear that this issue has upset folks. I assure you it was not the intent of @tmandry to step on any toes here, but rather to try and unblock what seemed to be a stalled conversation and to gather more context. If I am reading the room correctly, I think part of the frustration is that indeed the conversation is not especially stalled, there's ongoing work in the form of the project goal, etc. Is that correct? That is, perhaps this issue came off as a "why don't you just" sort of thing that is assuming things are easy when in fact they are complicated? Let me give a bit of context as to the origin of this issue. We were in a lang-team meeting and discussing the distinction between, say, Now that I think about it now, this explanation seems to have some holes. Among other things, even though In any case, what I will say is, this is a pretty complex area and there has been a lot of shifts over time and questions over time. So I would encourage a bit of benefit of the doubt -- we're all just trying to wrap our head around what are the blockers and to reach a shared understanding of what the goal is, not to disparage anyone's work or push half-baked things to stabilization or anything like that! |
That's accurate, and I'm happy to take feedback on how that can be communicated more clearly.
Is the issue not clear that it is asking for context? I don't think it's inappropriate to state my intention, as that can help clarify the kind of context that's needed.
Quoting myself: I can see how this is easy to interpret as "why don't you just". To be crystal clear, my intention has been to convey that the justification given in the error message is not enough of a reason to disallow this. This is now a moot point since that justification is itself not the blocker, but yes we might want to consider improving the diagnostic. In any case, many thanks for your work on |
Today this works:
but this does not:
with the following error:
We talked about this in the lang meeting today, and the consensus of those present was that this is not a sufficient justification for disallowing this. In particular, we are happy to allow this and issue a post-monomorphization error in the cases where the value of the const makes the array too large.
Ideally I'd like us to FCP this issue to formalize the consensus, but first want to collect any context we might be missing.
cc @nikomatsakis who had some context and was going to post it here.
cc @rust-lang/types; is there another justification we're missing?
cc @rust-lang/lang
The text was updated successfully, but these errors were encountered: