-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[const generics] symbol foo
is already defined
#70408
Comments
There's two ways that I see that we can use to go forward:
|
Keep in mind types have the same problem with |
Ok, but even ignoring any |
You shouldn't need |
Oh, as a side mention, if you need to validate that the typesystem doesn't contain any non-deduplicatable constants (e.g. |
I don't think we can run into issues with |
this is now fixed by valtrees: needs test though: #![feature(adt_const_params)]
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
BYTES
}
pub fn main() {
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]);
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA");
} |
…Simulacrum Add a test for rust-lang#70408 closes rust-lang#70408
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#97917 (Implement ExitCodeExt for Windows) - rust-lang#98844 (Reword comments and rename HIR visiting methods.) - rust-lang#98979 (interpret: use AllocRange in UninitByteAccess) - rust-lang#98986 (Fix missing word in comment) - rust-lang#98994 (replace process exit with more detailed exit in src/bootstrap/*.rs) - rust-lang#98995 (Add a test for rust-lang#80471) - rust-lang#99002 (suggest adding a derive for #[default] applied to variants) - rust-lang#99004 (Add a test for rust-lang#70408) - rust-lang#99017 (Replace boolean argument for print_where_clause with an enum to make code more clear) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Const generics causes monomorphization to compare constants by identity instead of structurally. This means that two different references to equal data will compare as unequal.
The root problem is in
rust/src/librustc_mir/monomorphize/collector.rs
Line 338 in 3c1d9ad
Instance
of a function into aFxHashSet
. Since theInstance
'ssubst
s contain constants, hashing these constants will cause structurally equal constants to have different hashes.For
HashStable
this has been solved by hashing the actual data and not things like pointers. For comparison we haveTypeRelation
which does a more appropriate version of comparison.I tried this code:
I expected to see this happen: successful compilation just as if the type were
&'static [u8]
Instead, this happened:
cc @varkor
cc @rust-lang/wg-const-eval It's a footgun that
ConstKind
and especiallyConstValue
can be compared for equality. Technically aConstKind::Unevaluated
is value/structurally equal to any otherConstKind
. We may need thatEq
impl for query return value hashing though, not sure.The text was updated successfully, but these errors were encountered: