constant reference has unstable address acrosss compilation units. #72004
Labels
A-const-eval
Area: Constant evaluation (MIR interpretation)
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
C-bug
Category: This is a bug.
Consider the following code, split across two crates:
This behavior is mildly surprising - effectively inlining a function changes the computation result.
The reference mentions a similar situation:
however, as written, this is not applicable to the code above - there's only one reference to a constant, not multiple. It is the same reference to a constant that gets treated differently based on the compilation unit.
I understand that this is an incredibly niche situation, and likely no real code hits it.
I also understand that it's likely very hard to "fix" the "bug" (i.e. make
assert_eq!
above pass).I think I'd be happy if the reference doc was simply adjusted instead (but have no suggestion on a better wording). I'm mildly concerned that even with better wording, the code might be obfuscated enough to the point where
main()
does not see any reference types while doing the inlining, yet still triggers the bug (but I couldn't craft such obfuscation myself).The text was updated successfully, but these errors were encountered: