mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
hir: Remove Expr::While
The previous commit desugared it to a loop.
This commit is contained in:
parent
31bcba84f9
commit
92a97c292a
7 changed files with 0 additions and 73 deletions
|
@ -178,14 +178,6 @@ impl Printer<'_> {
|
||||||
w!(self, "loop ");
|
w!(self, "loop ");
|
||||||
self.print_expr(*body);
|
self.print_expr(*body);
|
||||||
}
|
}
|
||||||
Expr::While { condition, body, label } => {
|
|
||||||
if let Some(lbl) = label {
|
|
||||||
w!(self, "{}: ", self.body[*lbl].name.display(self.db));
|
|
||||||
}
|
|
||||||
w!(self, "while ");
|
|
||||||
self.print_expr(*condition);
|
|
||||||
self.print_expr(*body);
|
|
||||||
}
|
|
||||||
Expr::Call { callee, args, is_assignee_expr: _ } => {
|
Expr::Call { callee, args, is_assignee_expr: _ } => {
|
||||||
self.print_expr(*callee);
|
self.print_expr(*callee);
|
||||||
w!(self, "(");
|
w!(self, "(");
|
||||||
|
|
|
@ -228,11 +228,6 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
||||||
scopes.set_scope(expr, scope);
|
scopes.set_scope(expr, scope);
|
||||||
compute_block_scopes(statements, *tail, body, scopes, &mut scope);
|
compute_block_scopes(statements, *tail, body, scopes, &mut scope);
|
||||||
}
|
}
|
||||||
Expr::While { condition, body: body_expr, label } => {
|
|
||||||
let mut scope = scopes.new_labeled_scope(*scope, make_label(label));
|
|
||||||
compute_expr_scopes(*condition, body, scopes, &mut scope);
|
|
||||||
compute_expr_scopes(*body_expr, body, scopes, &mut scope);
|
|
||||||
}
|
|
||||||
Expr::Loop { body: body_expr, label } => {
|
Expr::Loop { body: body_expr, label } => {
|
||||||
let mut scope = scopes.new_labeled_scope(*scope, make_label(label));
|
let mut scope = scopes.new_labeled_scope(*scope, make_label(label));
|
||||||
compute_expr_scopes(*body_expr, body, scopes, &mut scope);
|
compute_expr_scopes(*body_expr, body, scopes, &mut scope);
|
||||||
|
|
|
@ -191,11 +191,6 @@ pub enum Expr {
|
||||||
body: ExprId,
|
body: ExprId,
|
||||||
label: Option<LabelId>,
|
label: Option<LabelId>,
|
||||||
},
|
},
|
||||||
While {
|
|
||||||
condition: ExprId,
|
|
||||||
body: ExprId,
|
|
||||||
label: Option<LabelId>,
|
|
||||||
},
|
|
||||||
Call {
|
Call {
|
||||||
callee: ExprId,
|
callee: ExprId,
|
||||||
args: Box<[ExprId]>,
|
args: Box<[ExprId]>,
|
||||||
|
@ -379,10 +374,6 @@ impl Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::Loop { body, .. } => f(*body),
|
Expr::Loop { body, .. } => f(*body),
|
||||||
Expr::While { condition, body, .. } => {
|
|
||||||
f(*condition);
|
|
||||||
f(*body);
|
|
||||||
}
|
|
||||||
Expr::Call { callee, args, .. } => {
|
Expr::Call { callee, args, .. } => {
|
||||||
f(*callee);
|
f(*callee);
|
||||||
args.iter().copied().for_each(f);
|
args.iter().copied().for_each(f);
|
||||||
|
|
|
@ -488,10 +488,6 @@ impl InferenceContext<'_> {
|
||||||
self.consume_expr(*tail);
|
self.consume_expr(*tail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::While { condition, body, label: _ } => {
|
|
||||||
self.consume_expr(*condition);
|
|
||||||
self.consume_expr(*body);
|
|
||||||
}
|
|
||||||
Expr::Call { callee, args, is_assignee_expr: _ } => {
|
Expr::Call { callee, args, is_assignee_expr: _ } => {
|
||||||
self.consume_expr(*callee);
|
self.consume_expr(*callee);
|
||||||
self.consume_exprs(args.iter().copied());
|
self.consume_exprs(args.iter().copied());
|
||||||
|
|
|
@ -198,19 +198,6 @@ impl InferenceContext<'_> {
|
||||||
None => self.result.standard_types.never.clone(),
|
None => self.result.standard_types.never.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Expr::While { condition, body, label } => {
|
|
||||||
self.with_breakable_ctx(BreakableKind::Loop, None, label, |this| {
|
|
||||||
this.infer_expr(
|
|
||||||
condition,
|
|
||||||
&Expectation::HasType(this.result.standard_types.bool_.clone()),
|
|
||||||
);
|
|
||||||
this.infer_expr(body, &Expectation::HasType(TyBuilder::unit()));
|
|
||||||
});
|
|
||||||
|
|
||||||
// the body may not run, so it diverging doesn't mean we diverge
|
|
||||||
self.diverges = Diverges::Maybe;
|
|
||||||
TyBuilder::unit()
|
|
||||||
}
|
|
||||||
Expr::Closure { body, args, ret_type, arg_types, closure_kind, capture_by: _ } => {
|
Expr::Closure { body, args, ret_type, arg_types, closure_kind, capture_by: _ } => {
|
||||||
assert_eq!(args.len(), arg_types.len());
|
assert_eq!(args.len(), arg_types.len());
|
||||||
|
|
||||||
|
|
|
@ -69,10 +69,6 @@ impl InferenceContext<'_> {
|
||||||
self.infer_mut_expr(*tail, Mutability::Not);
|
self.infer_mut_expr(*tail, Mutability::Not);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Expr::While { condition: c, body, label: _ } => {
|
|
||||||
self.infer_mut_expr(c, Mutability::Not);
|
|
||||||
self.infer_mut_expr(body, Mutability::Not);
|
|
||||||
}
|
|
||||||
Expr::MethodCall { receiver: it, method_name: _, args, generic_args: _ }
|
Expr::MethodCall { receiver: it, method_name: _, args, generic_args: _ }
|
||||||
| Expr::Call { callee: it, args, is_assignee_expr: _ } => {
|
| Expr::Call { callee: it, args, is_assignee_expr: _ } => {
|
||||||
self.infer_mut_not_expr_iter(args.iter().copied().chain(Some(*it)));
|
self.infer_mut_not_expr_iter(args.iter().copied().chain(Some(*it)));
|
||||||
|
|
|
@ -582,36 +582,6 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Expr::While { condition, body, label } => {
|
|
||||||
self.lower_loop(current, place, *label, expr_id.into(), |this, begin| {
|
|
||||||
let scope = this.push_drop_scope();
|
|
||||||
let Some((discr, to_switch)) =
|
|
||||||
this.lower_expr_to_some_operand(*condition, begin)?
|
|
||||||
else {
|
|
||||||
return Ok(());
|
|
||||||
};
|
|
||||||
let fail_cond = this.new_basic_block();
|
|
||||||
let after_cond = this.new_basic_block();
|
|
||||||
this.set_terminator(
|
|
||||||
to_switch,
|
|
||||||
TerminatorKind::SwitchInt {
|
|
||||||
discr,
|
|
||||||
targets: SwitchTargets::static_if(1, after_cond, fail_cond),
|
|
||||||
},
|
|
||||||
expr_id.into(),
|
|
||||||
);
|
|
||||||
let fail_cond = this.drop_until_scope(this.drop_scopes.len() - 1, fail_cond);
|
|
||||||
let end = this.current_loop_end()?;
|
|
||||||
this.set_goto(fail_cond, end, expr_id.into());
|
|
||||||
if let Some((_, block)) = this.lower_expr_as_place(after_cond, *body, true)? {
|
|
||||||
let block = scope.pop_and_drop(this, block);
|
|
||||||
this.set_goto(block, begin, expr_id.into());
|
|
||||||
} else {
|
|
||||||
scope.pop_assume_dropped(this);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
Expr::Call { callee, args, .. } => {
|
Expr::Call { callee, args, .. } => {
|
||||||
if let Some((func_id, generic_args)) = self.infer.method_resolution(expr_id) {
|
if let Some((func_id, generic_args)) = self.infer.method_resolution(expr_id) {
|
||||||
let ty = chalk_ir::TyKind::FnDef(
|
let ty = chalk_ir::TyKind::FnDef(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue