Skip to content

Commit d58cb93

Browse files
committed
Rename hir::ExprKind::Use to ::DropTemps and improve docs.
1 parent 862a878 commit d58cb93

File tree

12 files changed

+32
-26
lines changed

12 files changed

+32
-26
lines changed

src/librustc/cfg/construct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
369369
hir::ExprKind::AddrOf(_, ref e) |
370370
hir::ExprKind::Cast(ref e, _) |
371371
hir::ExprKind::Type(ref e, _) |
372-
hir::ExprKind::Use(ref e) |
372+
hir::ExprKind::DropTemps(ref e) |
373373
hir::ExprKind::Unary(_, ref e) |
374374
hir::ExprKind::Field(ref e, _) |
375375
hir::ExprKind::Yield(ref e) |

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10291029
visitor.visit_expr(subexpression);
10301030
visitor.visit_ty(typ)
10311031
}
1032-
ExprKind::Use(ref subexpression) => {
1032+
ExprKind::DropTemps(ref subexpression) => {
10331033
visitor.visit_expr(subexpression);
10341034
}
10351035
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {

src/librustc/hir/lowering.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -4671,7 +4671,7 @@ impl<'a> LoweringContext<'a> {
46714671
// The construct was introduced in #21984.
46724672
// FIXME(60253): Is this still necessary?
46734673
// Also, add the attributes to the outer returned expr node.
4674-
return self.expr_use(head_sp, match_expr, e.attrs.clone())
4674+
return self.expr_drop_temps(head_sp, match_expr, e.attrs.clone())
46754675
}
46764676

46774677
// Desugar `ExprKind::Try`
@@ -5030,15 +5030,19 @@ impl<'a> LoweringContext<'a> {
50305030
)
50315031
}
50325032

5033-
/// Wrap the given `expr` in `hir::ExprKind::Use`.
5033+
/// Wrap the given `expr` in a terminating scope using `hir::ExprKind::DropTemps`.
50345034
///
5035-
/// In terms of drop order, it has the same effect as
5036-
/// wrapping `expr` in `{ let _t = $expr; _t }` but
5037-
/// should provide better compile-time performance.
5035+
/// In terms of drop order, it has the same effect as wrapping `expr` in
5036+
/// `{ let _t = $expr; _t }` but should provide better compile-time performance.
50385037
///
50395038
/// The drop order can be important in e.g. `if expr { .. }`.
5040-
fn expr_use(&mut self, span: Span, expr: P<hir::Expr>, attrs: ThinVec<Attribute>) -> hir::Expr {
5041-
self.expr(span, hir::ExprKind::Use(expr), attrs)
5039+
fn expr_drop_temps(
5040+
&mut self,
5041+
span: Span,
5042+
expr: P<hir::Expr>,
5043+
attrs: ThinVec<Attribute>
5044+
) -> hir::Expr {
5045+
self.expr(span, hir::ExprKind::DropTemps(expr), attrs)
50425046
}
50435047

50445048
fn expr_match(

src/librustc/hir/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ impl Expr {
13661366
ExprKind::Unary(..) => ExprPrecedence::Unary,
13671367
ExprKind::Lit(_) => ExprPrecedence::Lit,
13681368
ExprKind::Type(..) | ExprKind::Cast(..) => ExprPrecedence::Cast,
1369-
ExprKind::Use(ref expr, ..) => expr.precedence(),
1369+
ExprKind::DropTemps(ref expr, ..) => expr.precedence(),
13701370
ExprKind::If(..) => ExprPrecedence::If,
13711371
ExprKind::While(..) => ExprPrecedence::While,
13721372
ExprKind::Loop(..) => ExprPrecedence::Loop,
@@ -1438,7 +1438,7 @@ impl Expr {
14381438
ExprKind::Binary(..) |
14391439
ExprKind::Yield(..) |
14401440
ExprKind::Cast(..) |
1441-
ExprKind::Use(..) |
1441+
ExprKind::DropTemps(..) |
14421442
ExprKind::Err => {
14431443
false
14441444
}
@@ -1488,10 +1488,12 @@ pub enum ExprKind {
14881488
Cast(P<Expr>, P<Ty>),
14891489
/// A type reference (e.g., `Foo`).
14901490
Type(P<Expr>, P<Ty>),
1491-
/// Semantically equivalent to `{ let _t = expr; _t }`.
1492-
/// Maps directly to `hair::ExprKind::Use`.
1493-
/// Only exists to tweak the drop order in HIR.
1494-
Use(P<Expr>),
1491+
/// Wraps the expression in a terminating scope.
1492+
/// This makes it semantically equivalent to `{ let _t = expr; _t }`.
1493+
///
1494+
/// This construct only exists to tweak the drop order in HIR lowering.
1495+
/// An example of that is the desugaring of `for` loops.
1496+
DropTemps(P<Expr>),
14951497
/// An `if` block, with an optional else block.
14961498
///
14971499
/// I.e., `if <expr> { <expr> } else { <expr> }`.

src/librustc/hir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ impl<'a> State<'a> {
13881388
self.word_space(":")?;
13891389
self.print_type(&ty)?;
13901390
}
1391-
hir::ExprKind::Use(ref init) => {
1391+
hir::ExprKind::DropTemps(ref init) => {
13921392
// Print `{`:
13931393
self.cbox(indent_unit)?;
13941394
self.ibox(0)?;

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
520520
self.consume_expr(&base);
521521
}
522522

523-
hir::ExprKind::Use(ref expr) => {
523+
hir::ExprKind::DropTemps(ref expr) => {
524524
self.consume_expr(&expr);
525525
}
526526

src/librustc/middle/liveness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
521521
hir::ExprKind::Binary(..) |
522522
hir::ExprKind::AddrOf(..) |
523523
hir::ExprKind::Cast(..) |
524-
hir::ExprKind::Use(..) |
524+
hir::ExprKind::DropTemps(..) |
525525
hir::ExprKind::Unary(..) |
526526
hir::ExprKind::Break(..) |
527527
hir::ExprKind::Continue(_) |
@@ -1222,7 +1222,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
12221222
hir::ExprKind::AddrOf(_, ref e) |
12231223
hir::ExprKind::Cast(ref e, _) |
12241224
hir::ExprKind::Type(ref e, _) |
1225-
hir::ExprKind::Use(ref e) |
1225+
hir::ExprKind::DropTemps(ref e) |
12261226
hir::ExprKind::Unary(_, ref e) |
12271227
hir::ExprKind::Yield(ref e) |
12281228
hir::ExprKind::Repeat(ref e, _) => {
@@ -1526,7 +1526,7 @@ fn check_expr<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, expr: &'tcx Expr) {
15261526
hir::ExprKind::Match(..) | hir::ExprKind::While(..) | hir::ExprKind::Loop(..) |
15271527
hir::ExprKind::Index(..) | hir::ExprKind::Field(..) |
15281528
hir::ExprKind::Array(..) | hir::ExprKind::Tup(..) | hir::ExprKind::Binary(..) |
1529-
hir::ExprKind::Cast(..) | hir::ExprKind::Use(..) | hir::ExprKind::Unary(..) |
1529+
hir::ExprKind::Cast(..) | hir::ExprKind::DropTemps(..) | hir::ExprKind::Unary(..) |
15301530
hir::ExprKind::Ret(..) | hir::ExprKind::Break(..) | hir::ExprKind::Continue(..) |
15311531
hir::ExprKind::Lit(_) | hir::ExprKind::Block(..) | hir::ExprKind::AddrOf(..) |
15321532
hir::ExprKind::Struct(..) | hir::ExprKind::Repeat(..) |

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
677677
hir::ExprKind::Assign(..) | hir::ExprKind::AssignOp(..) |
678678
hir::ExprKind::Closure(..) | hir::ExprKind::Ret(..) |
679679
hir::ExprKind::Unary(..) | hir::ExprKind::Yield(..) |
680-
hir::ExprKind::MethodCall(..) | hir::ExprKind::Cast(..) | hir::ExprKind::Use(..) |
680+
hir::ExprKind::MethodCall(..) | hir::ExprKind::Cast(..) | hir::ExprKind::DropTemps(..) |
681681
hir::ExprKind::Array(..) | hir::ExprKind::Tup(..) | hir::ExprKind::If(..) |
682682
hir::ExprKind::Binary(..) | hir::ExprKind::While(..) |
683683
hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) | hir::ExprKind::Match(..) |

src/librustc/middle/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,8 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
908908
visitor.cx.var_parent = visitor.cx.parent;
909909
}
910910

911-
hir::ExprKind::Use(ref expr) => {
912-
// `Use(expr)` does not denote a conditional scope.
911+
hir::ExprKind::DropTemps(ref expr) => {
912+
// `DropTemps(expr)` does not denote a conditional scope.
913913
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
914914
terminating(expr.hir_id.local_id);
915915
}

src/librustc_mir/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
759759
}
760760
}
761761
}
762-
hir::ExprKind::Use(ref source) => {
762+
hir::ExprKind::DropTemps(ref source) => {
763763
ExprKind::Use { source: source.to_ref() }
764764
}
765765
hir::ExprKind::Box(ref value) => {

src/librustc_passes/rvalue_promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ fn check_expr_kind<'a, 'tcx>(
437437
hir::ExprKind::AddrOf(_, ref expr) |
438438
hir::ExprKind::Repeat(ref expr, _) |
439439
hir::ExprKind::Type(ref expr, _) |
440-
hir::ExprKind::Use(ref expr) => {
440+
hir::ExprKind::DropTemps(ref expr) => {
441441
v.check_expr(&expr)
442442
}
443443

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45384538
self.check_expr_eq_type(&e, ty);
45394539
ty
45404540
}
4541-
ExprKind::Use(ref e) => {
4541+
ExprKind::DropTemps(ref e) => {
45424542
self.check_expr_with_expectation(e, expected)
45434543
}
45444544
ExprKind::Array(ref args) => {

0 commit comments

Comments
 (0)