Skip to content

const-eval: perform validation before interning #122398

Closed
@RalfJung

Description

@RalfJung

Currently, after const-eval is done, we first intern the result into tcx and then validate that it matches the type. This is unfortunate because interning can go wrong (when there is a mutable pointer somewhere we did not expect), and in most cases that issue would also be detected by validation -- and validation shows a much nicer error, indicating where in the value the issue arises.

However, interning currently also does the job of adjusting the allocation's mutability to its final value. This has to be done before validation. So fixing this would end up with a final order of operations like:

  • Adjust mutability
  • Validation
  • Interning

All that said, I'm not entirely sure whether this is worth it since triggering the interning error should be pretty rare. Our static const checks should largely prevent them.

Cc @rust-lang/wg-const-eval

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)WG-const-evalWorking group: Const evaluation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions