Skip to content

Commit c49e2df

Browse files
committed
Put a BlockTailInfo in BlockFrame::TailExpr.
Because it has the same fields, and avoids the need to deconstruct the latter to construct the former.
1 parent 5d2d11f commit c49e2df

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
lines changed

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ mod binding_form_impl {
937937
/// involved in borrow_check errors, e.g., explanations of where the
938938
/// temporaries come from, when their destructors are run, and/or how
939939
/// one might revise the code to satisfy the borrow checker's rules.
940-
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
940+
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
941941
pub struct BlockTailInfo {
942942
/// If `true`, then the value resulting from evaluating this tail
943943
/// expression is ignored by the block's expression context.

compiler/rustc_mir_build/src/builder/block.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
331331
let expr = &this.thir[expr_id];
332332
let tail_result_is_ignored =
333333
destination_ty.is_unit() || this.block_context.currently_ignores_tail_results();
334-
this.block_context
335-
.push(BlockFrame::TailExpr { tail_result_is_ignored, span: expr.span });
334+
this.block_context.push(BlockFrame::TailExpr {
335+
info: BlockTailInfo { tail_result_is_ignored, span: expr.span },
336+
});
336337

337338
block = this.expr_into_dest(destination, block, expr_id).into_block();
338339
let popped = this.block_context.pop();

compiler/rustc_mir_build/src/builder/expr/stmt.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
164164
}
165165
}
166166
this.block_context.push(BlockFrame::TailExpr {
167-
tail_result_is_ignored: true,
168-
span: expr.span,
167+
info: BlockTailInfo { tail_result_is_ignored: true, span: expr.span },
169168
});
170169
Some(expr.span)
171170
} else {

compiler/rustc_mir_build/src/builder/mod.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,7 @@ enum BlockFrame {
112112
/// Evaluation is currently within the tail expression of a block.
113113
///
114114
/// Example: `{ STMT_1; STMT_2; EXPR }`
115-
TailExpr {
116-
/// If true, then the surrounding context of the block ignores
117-
/// the result of evaluating the block's tail expression.
118-
///
119-
/// Example: `let _ = { STMT_1; EXPR };`
120-
tail_result_is_ignored: bool,
121-
122-
/// `Span` of the tail expression.
123-
span: Span,
124-
},
115+
TailExpr { info: BlockTailInfo },
125116

126117
/// Generic mark meaning that the block occurred as a subexpression
127118
/// where the result might be used.
@@ -277,9 +268,7 @@ impl BlockContext {
277268
match bf {
278269
BlockFrame::SubExpr => continue,
279270
BlockFrame::Statement { .. } => break,
280-
&BlockFrame::TailExpr { tail_result_is_ignored, span } => {
281-
return Some(BlockTailInfo { tail_result_is_ignored, span });
282-
}
271+
&BlockFrame::TailExpr { info } => return Some(info),
283272
}
284273
}
285274

@@ -302,9 +291,9 @@ impl BlockContext {
302291

303292
// otherwise: use accumulated is_ignored state.
304293
Some(
305-
BlockFrame::TailExpr { tail_result_is_ignored: ignored, .. }
306-
| BlockFrame::Statement { ignores_expr_result: ignored },
307-
) => *ignored,
294+
BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: ign, .. } }
295+
| BlockFrame::Statement { ignores_expr_result: ign },
296+
) => *ign,
308297
}
309298
}
310299
}

0 commit comments

Comments
 (0)