-
-
Notifications
You must be signed in to change notification settings - Fork 15k
[const generics] symbol foo is already defined #70408
Copy link
Copy link
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)C-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.F-adt_const_params`#![feature(adt_const_params)]``#![feature(adt_const_params)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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
Instanceof a function into aFxHashSet. Since theInstance'ssubsts contain constants, hashing these constants will cause structurally equal constants to have different hashes.For
HashStablethis has been solved by hashing the actual data and not things like pointers. For comparison we haveTypeRelationwhich 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
ConstKindand especiallyConstValuecan be compared for equality. Technically aConstKind::Unevaluatedis value/structurally equal to any otherConstKind. We may need thatEqimpl for query return value hashing though, not sure.