You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
min_const_generic takes precedence over const_generics #76280
I expect the code below code to compile, but it fails. const_generics should allow more than just the types whitelisted in min_const_generics, but it seems rustc only looks at the min_const_generics flag in this case.
error: `&'static [u8]` is forbidden as the type of a const generic parameter
--> src/lib.rs:4:25
|
4 | struct Contain<const S: &'static [u8]>;
| ^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`
I imagine this to happen whenever at first you only decide to use min_const_generics, but then later also switch to const_generics. You might just follow rustc, which tells you to add #![feature(const_generics)] to your project, so you do, but then you get the behaviour as described in this issue.
This could also perhaps get triggered in a more subtle way where you write a library that uses cfg_attr to enable or disable features.
It probably makes sense to instead check if we are not using feature(const_generics) here, but there are a quite a few places were we check for feature(min_const_generics), we maybe want to instead emit an error/warning when using both const_generics and min_const_generics in the same crate.
error[E0658]: const generics are unstable
--> src/lib.rs:3:16
|
3 | struct S<const I: usize>;
| ^
|
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable
So currently const_generics is not a superset of min_const_generics.
error[E0658]: const generics are unstable
--> src/lib.rs:3:16
|
3 | struct S<const I: usize>;
| ^
|
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable
So currently const_generics is not a superset of min_const_generics.
You are missing a ! in your feature. I still think const_generics are a superset of min_const_generics, but rustc just suggest using the smaller one in this case becouse that's the subset aiming to be stabilized for now
I was confused looking at some ui tests for const generics, and missed that those now have support differentiating between expected behavior under const_generics and min_const_generics, and thought a particular error was always being thrown, instead of only under min_const_generics.
Activity
Amjad50 commentedon Sep 3, 2020
You are right
rust/compiler/rustc_typeck/src/check/wfcheck.rs
Lines 293 to 310 in 08deb86
But why would you want to use the two of them?
DutchGhost commentedon Sep 3, 2020
I imagine this to happen whenever at first you only decide to use
min_const_generics, but then later also switch toconst_generics. You might just follow rustc, which tells you to add#![feature(const_generics)]to your project, so you do, but then you get the behaviour as described in this issue.This could also perhaps get triggered in a more subtle way where you write a library that uses
cfg_attrto enable or disable features.Amjad50 commentedon Sep 3, 2020
what do you think @lcnr ?
lcnr commentedon Sep 3, 2020
It probably makes sense to instead check if we are not using
feature(const_generics)here, but there are a quite a few places were we check forfeature(min_const_generics), we maybe want to instead emit an error/warning when using bothconst_genericsandmin_const_genericsin the same crate.Amjad50 commentedon Sep 3, 2020
Created a way to produce an error in case of incompatible features, like this one
DutchGhost commentedon Sep 3, 2020
I have one question, how does using 'incompatible feature' cause maybe undefined behavior?
Are there other incompatible features?
In this case, wouldn't it be better to produce an error message like "feature(const_generics) is a superset of feature(min_const_generics)"?
CDirkx commentedon Sep 4, 2020
Note that:
results in a compile error:
So currently
const_genericsis not a superset ofmin_const_generics.DutchGhost commentedon Sep 4, 2020
You are missing a
!in your feature. I still think const_generics are a superset of min_const_generics, but rustc just suggest using the smaller one in this case becouse that's the subset aiming to be stabilized for nowCDirkx commentedon Sep 4, 2020
Ah of course, my bad 😅
I was confused looking at some ui tests for const generics, and missed that those now have support differentiating between expected behavior under
const_genericsandmin_const_generics, and thought a particular error was always being thrown, instead of only undermin_const_generics.Rollup merge of rust-lang#76293 - Amjad50:incompatible_features_error…
Rollup merge of rust-lang#76293 - Amjad50:incompatible_features_error…
Rollup merge of rust-lang#76293 - Amjad50:incompatible_features_error…