Skip to content

Commit

Permalink
Rollup merge of rust-lang#40576 - dwrensha:mir-terminator-kind-doc-ty…
Browse files Browse the repository at this point in the history
…po, r=nikomatsakis

fix innacuracy in mir TerminatorKind::SwitchInt docs

Each index of `values` corresponds to an index of `targets`, and `targets` additionally has a "default case" element at its end, so `targets.len() == values.len() + 1`, not the other way around. For example, [here](https://github.com/rust-lang/rust/blob/0aeb9c12979e6da753701a798d04105b6b1a8c28/src/librustc/mir/mod.rs#L549-L550) is a concrete instance of `SwitchInt` being constructed with `targets.len() == 2` and `values.len() == 1`.
  • Loading branch information
frewsxcv authored Mar 21, 2017
2 parents 17656ab + e9c07cf commit 2532ad7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ pub enum TerminatorKind<'tcx> {
values: Cow<'tcx, [ConstInt]>,

/// Possible branch sites. The last element of this vector is used
/// for the otherwise branch, so values.len() == targets.len() + 1
/// for the otherwise branch, so targets.len() == values.len() + 1
/// should hold.
// This invariant is quite non-obvious and also could be improved.
// One way to make this invariant is to have something like this instead:
Expand Down

0 comments on commit 2532ad7

Please sign in to comment.