Skip to content

Language in constant evaluation section is unclear #497

Closed
@chriskrycho

Description

@chriskrycho

This text from Constant Evaluation: Constant Expressions is a bit murky:

Certain types of expressions can be evaluated at compile time. These are called constant expressions and are required in const contexts. In other places, such as in let statements, constant expressions may be evaluated at compile time. If errors, such as out of bounds array indexing or overflow occurs, then it is a compiler error if the value must be evaluated at compile time, otherwise it is just a warning, but the code will most likely panic when run.

Suggested rephrasing:

Certain types of expressions, called constant expressions, can be evaluated at compile time. In const contexts, these are the only allowed expressions, and are always evaluated at compile time. In other places, such as in let statements, constant expressions are allowed but not required, and may be evaluated at compile time. Errors such as out of bounds array indexing or overflow are compiler errors if the value must be evaluated at compile time (i.e. in const contexts); otherwise they are just warnings, but the code will most likely panic when run.

Happy to submit a PR to that effect or similar!

Metadata

Metadata

Assignees

Labels

Language CleanupImprovements to existing language which is correct but not clear, or missing examples, or the like.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions