-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rust preventing calculations on const generics #82319
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
If you want to do calculations with const generics you'll need the |
@jonas-schievink You've closed this without even having the common courtesy to explain to me why that is; I don't appreciate that. @SkiFire13 I'm aware of the link you've made. It doesn't stop me thinking it's a bug. Rust's |
It may be counterintuitive but it's definitely intended behaviour, so I wouldn't call it a bug. This however doesn't mean that the language is not open to changes, there's always the internals forum to propose and discuss them.
This is however perfectly intuitive if it's declared outside a function.
I don't think I understand how this may happen other than shadowing a global const with a const generic parameter.
I agree this is counterintuitive, however AFAIK there's a reason we can't have generic static, and that's because we need to support the |
@SkiFire13 Thanks for the explanation. We're going to disagree on the use of the word bug. That's ok; my view comes from a much wider perspective, and I understand where you're coming from.
I agree, and I wouldn't want any language to repeat C's need to declare before use; it's verbose and violates pyramid thinking and how we usually process information we read.
I probably haven't been as clear as I could have been in my terse description. If you're like me, you find examples easier to follow than descriptions. I often find discussing code akin to trying to write down the feelings a dream gives; an impossible thing to communicate. Regardless, it'd be getting well off the topic of this issue if we discussed it further on this issue report.
Thank you for the explanation. That makes quite a lot of sense. Personally, I've not been a fan of dynamic loading of libraries for over 5 years, ever since a very nasty cyber attack raised my awareness of their weaknesses (and, also, how few of us appreciate that things like From a software versioning and reliability point of view, it's frequently much better to just ship one statically linked binary; it makes it impossible for versioning changes on the end use machine to break it. From a patching point of view, they're actually an anti-pattern; an average sysadmin has no idea which applications to restart if a particular dylib is updated. I've yet to meet one yet who knows he has to restart everything if libc changes version because of a security fix - and very busy sysadmins frequently can't track stuff as granular as that. Indeed, the whole idea that the state of the system is mutated by a package manager gives me the shivers... and it's a common entry to attack. Immutable in-memory OS distros are the way to go. |
I'm wrapping an AVX512 intrinsic, one of whose arguments needed to be const. So, far, so good. However, the wrapper of my wrapper needs to do a simple const calculation before use, and my old friend,
[E0401]: can't use generic parameters from outer function
(which has always struck me as broken regarding const, especially when it relates to a generic parameter as part of a struct's impl, when it's not an outer function, but I digress), prevents this code from working:-I've raised a related issue about const generics on the stdsimd working group issues (rust-lang/stdarch#1011), but this is potentially a wider issue. Now, this may be by design, but to me as an user, it's a bug. Why? Because it's naturally the code I'd write in about 30 seconds to do what I wanted.
Thoughts?
The text was updated successfully, but these errors were encountered: