Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications. The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome. - [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051) - [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d) - [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5) - [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691) - [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95) - [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
This commit is contained in:
commit
d03fe84169
139 changed files with 3135 additions and 3090 deletions
|
@ -1080,6 +1080,50 @@ impl<'a> State<'a> {
|
|||
self.ann.post(self, AnnNode::Block(blk))
|
||||
}
|
||||
|
||||
fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
|
||||
match els {
|
||||
Some(_else) => {
|
||||
match _else.kind {
|
||||
// "another else-if"
|
||||
hir::ExprKind::If(ref i, ref then, ref e) => {
|
||||
self.cbox(INDENT_UNIT - 1);
|
||||
self.ibox(0);
|
||||
self.s.word(" else if ");
|
||||
self.print_expr_as_cond(&i);
|
||||
self.s.space();
|
||||
self.print_expr(&then);
|
||||
self.print_else(e.as_ref().map(|e| &**e))
|
||||
}
|
||||
// "final else"
|
||||
hir::ExprKind::Block(ref b, _) => {
|
||||
self.cbox(INDENT_UNIT - 1);
|
||||
self.ibox(0);
|
||||
self.s.word(" else ");
|
||||
self.print_block(&b)
|
||||
}
|
||||
// BLEAH, constraints would be great here
|
||||
_ => {
|
||||
panic!("print_if saw if with weird alternative");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_if(
|
||||
&mut self,
|
||||
test: &hir::Expr<'_>,
|
||||
blk: &hir::Expr<'_>,
|
||||
elseopt: Option<&hir::Expr<'_>>,
|
||||
) {
|
||||
self.head("if");
|
||||
self.print_expr_as_cond(test);
|
||||
self.s.space();
|
||||
self.print_expr(blk);
|
||||
self.print_else(elseopt)
|
||||
}
|
||||
|
||||
pub fn print_anon_const(&mut self, constant: &hir::AnonConst) {
|
||||
self.ann.nested(self, Nested::Body(constant.body))
|
||||
}
|
||||
|
@ -1349,6 +1393,9 @@ impl<'a> State<'a> {
|
|||
// Print `}`:
|
||||
self.bclose_maybe_open(expr.span, true);
|
||||
}
|
||||
hir::ExprKind::If(ref test, ref blk, ref elseopt) => {
|
||||
self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e));
|
||||
}
|
||||
hir::ExprKind::Loop(ref blk, opt_label, _) => {
|
||||
if let Some(label) = opt_label {
|
||||
self.print_ident(label.ident);
|
||||
|
@ -2429,7 +2476,13 @@ impl<'a> State<'a> {
|
|||
//
|
||||
// Duplicated from `parse::classify`, but adapted for the HIR.
|
||||
fn expr_requires_semi_to_be_stmt(e: &hir::Expr<'_>) -> bool {
|
||||
!matches!(e.kind, hir::ExprKind::Match(..) | hir::ExprKind::Block(..) | hir::ExprKind::Loop(..))
|
||||
!matches!(
|
||||
e.kind,
|
||||
hir::ExprKind::If(..)
|
||||
| hir::ExprKind::Match(..)
|
||||
| hir::ExprKind::Block(..)
|
||||
| hir::ExprKind::Loop(..)
|
||||
)
|
||||
}
|
||||
|
||||
/// This statement requires a semicolon after it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue