[−][src]Module rustc_mir::transform::promote_consts

A pass that promotes borrows of constant rvalues.

The rvalues considered constant are trees of temps, each with exactly one initialization, and holding a constant value with no interior mutability. They are placed into a new MIR constant body in promoted and the borrow rvalue is replaced with a Literal::Promoted using the index into promoted of that constant MIR.

This pass assumes that every use is dominated by an initialization and can otherwise silence errors, if move analysis runs after promotion on broken MIR.

Structs

Collector
PromoteTemps

A MirPass for promotion.

Promoter
Unpromotable
Validator

Checks whether locals that appear in a promotion context (Candidate) are actually promotable.

Enums

Candidate

A "root candidate" for promotion, which will become the returned value in a promoted MIR, unless it's a subset of a larger candidate.

TempState

State of a temporary during collection and promotion.

Functions

args_required_const
collect_temps_and_candidates
promote_candidates
should_suggest_const_in_array_repeat_expressions_attribute

This function returns true if the const_in_array_repeat_expressions feature attribute should be suggested. This function is probably quite expensive, it shouldn't be run in the happy path. Feature attribute should be suggested if operand can be promoted and the feature is not enabled.

validate_candidates