Skip to content

Commit 6aa7b31

Browse files
Rollup merge of rust-lang#152927 - AlexCeleste:thir-missing-index-subexpressions, r=TaKO8Ki
Index expressions rendered the index: subexpression as the id, instea… …d of actually showing the content of the subexpression This meant the content of the subexpression was completely missing from tree view (as the id did not reference anything)
2 parents 6aad104 + b7c28a8 commit 6aa7b31

3 files changed

Lines changed: 1235 additions & 1 deletion

File tree

compiler/rustc_mir_build/src/thir/print.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,10 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
397397
}
398398
Index { lhs, index } => {
399399
print_indented!(self, "Index {", depth_lvl);
400-
print_indented!(self, format!("index: {:?}", index), depth_lvl + 1);
401400
print_indented!(self, "lhs:", depth_lvl + 1);
402401
self.print_expr(*lhs, depth_lvl + 2);
402+
print_indented!(self, "index:", depth_lvl + 1);
403+
self.print_expr(*index, depth_lvl + 2);
403404
print_indented!(self, "}", depth_lvl);
404405
}
405406
VarRef { id } => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ check-pass
2+
//@ compile-flags: -Zunpretty=thir-tree
3+
4+
fn index(x: usize) -> usize { x }
5+
6+
fn indexing(x: usize) -> usize {
7+
let a1: [usize; 5] = [1, 2, 3, 4, 5];
8+
let a2: [usize; 5] = [x; 5];
9+
10+
a1[0];
11+
a2[1];
12+
13+
a1[x];
14+
a2[x + 2];
15+
16+
a1[a2[x] + a2[x - 3]];
17+
a2[index (x + 1) - x];
18+
19+
0
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)