Get rid of Block::recovered

This commit is contained in:
Vadim Petrochenkov 2018-12-20 02:33:56 +03:00
parent fff01ccfa8
commit 4ac592516f
13 changed files with 12 additions and 41 deletions

View File

@ -2709,7 +2709,6 @@ impl<'a> LoweringContext<'a> {
rules: self.lower_block_check_mode(&b.rules),
span: b.span,
targeted_by_break,
recovered: b.recovered,
})
}
@ -3781,7 +3780,6 @@ impl<'a> LoweringContext<'a> {
rules: hir::DefaultBlock,
span,
targeted_by_break: false,
recovered: blk.recovered,
});
P(self.expr_block(blk, ThinVec::new()))
}
@ -4823,7 +4821,6 @@ impl<'a> LoweringContext<'a> {
rules: hir::DefaultBlock,
span,
targeted_by_break: false,
recovered: false,
}
}

View File

@ -807,11 +807,6 @@ pub struct Block {
/// break out of this block early.
/// Used by `'label: {}` blocks and by `catch` statements.
pub targeted_by_break: bool,
/// If true, don't emit return value type errors as the parser had
/// to recover from a parse error so this block will not have an
/// appropriate type. A parse error will have been emitted so the
/// compilation will never succeed if this is true.
pub recovered: bool,
}
#[derive(Clone, RustcEncodable, RustcDecodable)]

View File

@ -410,7 +410,6 @@ impl_stable_hash_for!(struct hir::Block {
rules,
span,
targeted_by_break,
recovered,
});
impl_stable_hash_for!(struct hir::Pat {

View File

@ -741,7 +741,6 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
fn stmt_to_block(rules: ast::BlockCheckMode,
recovered: bool,
s: Option<ast::Stmt>,
sess: &Session) -> ast::Block {
ast::Block {
@ -749,7 +748,6 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
rules,
id: sess.next_node_id(),
span: syntax_pos::DUMMY_SP,
recovered,
}
}
@ -768,7 +766,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
}
}
let empty_block = stmt_to_block(BlockCheckMode::Default, false, None, self.sess);
let empty_block = stmt_to_block(BlockCheckMode::Default, None, self.sess);
let loop_expr = P(ast::Expr {
node: ast::ExprKind::Loop(P(empty_block), None),
id: self.sess.next_node_id(),
@ -809,7 +807,7 @@ impl<'a> fold::Folder for ReplaceBodyWithLoop<'a> {
old_blocks.push(new_block);
}
stmt_to_block(b.rules, b.recovered, Some(loop_stmt), self.sess)
stmt_to_block(b.rules, Some(loop_stmt), self.sess)
} else {
//push `loop {}` onto the end of our fresh block and yield that
new_block.stmts.push(loop_stmt);

View File

@ -4772,12 +4772,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
//
// #41425 -- label the implicit `()` as being the
// "found type" here, rather than the "expected type".
//
// #44579 -- if the block was recovered during parsing,
// the type would be nonsensical and it is not worth it
// to perform the type check, so we avoid generating the
// diagnostic output.
if !self.diverges.get().always() && !blk.recovered {
if !self.diverges.get().always() {
coerce.coerce_forced_unit(self, &self.misc(blk.span), &mut |err| {
if let Some(expected_ty) = expected.only_has_type(self) {
self.consider_hint_about_removing_semicolon(blk,

View File

@ -444,7 +444,6 @@ pub struct Block {
/// Distinguishes between `unsafe { ... }` and `{ ... }`
pub rules: BlockCheckMode,
pub span: Span,
pub recovered: bool,
}
#[derive(Clone, RustcEncodable, RustcDecodable)]

View File

@ -587,7 +587,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
id: ast::DUMMY_NODE_ID,
rules: BlockCheckMode::Default,
span,
recovered: false,
})
}

View File

@ -892,12 +892,11 @@ fn noop_fold_bounds<T: Folder>(bounds: GenericBounds, folder: &mut T)
}
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {
b.map(|Block {id, stmts, rules, span, recovered}| Block {
b.map(|Block {id, stmts, rules, span}| Block {
id: folder.new_id(id),
stmts: stmts.move_flat_map(|s| folder.fold_stmt(s).into_iter()),
rules,
span: folder.new_span(span),
recovered,
})
}

View File

@ -32,6 +32,7 @@ use ast::{UseTree, UseTreeKind};
use ast::{BinOpKind, UnOp};
use ast::{RangeEnd, RangeSyntax};
use {ast, attr};
use ext::base::DummyResult;
use source_map::{self, SourceMap, Spanned, respan};
use syntax_pos::{self, Span, MultiSpan, BytePos, FileName};
use errors::{self, Applicability, DiagnosticBuilder, DiagnosticId};
@ -4966,16 +4967,16 @@ impl<'a> Parser<'a> {
/// Precondition: already parsed the '{'.
fn parse_block_tail(&mut self, lo: Span, s: BlockCheckMode) -> PResult<'a, P<Block>> {
let mut stmts = vec![];
let mut recovered = false;
while !self.eat(&token::CloseDelim(token::Brace)) {
let stmt = match self.parse_full_stmt(false) {
Err(mut err) => {
err.emit();
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
self.eat(&token::CloseDelim(token::Brace));
recovered = true;
break;
Some(Stmt {
id: ast::DUMMY_NODE_ID,
node: StmtKind::Expr(DummyResult::raw_expr(self.span)),
span: self.span,
})
}
Ok(stmt) => stmt,
};
@ -4993,7 +4994,6 @@ impl<'a> Parser<'a> {
id: ast::DUMMY_NODE_ID,
rules: s,
span: lo.to(self.prev_span),
recovered,
}))
}

View File

@ -153,6 +153,5 @@ fn call_intrinsic(cx: &ExtCtxt,
id: ast::DUMMY_NODE_ID,
rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated),
span,
recovered: false,
}))
}

View File

@ -105,7 +105,6 @@ fn iter_exprs(depth: usize, f: &mut FnMut(P<Expr>)) {
id: DUMMY_NODE_ID,
rules: BlockCheckMode::Default,
span: DUMMY_SP,
recovered: false,
});
iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None)));
},

View File

@ -20,5 +20,4 @@ pub fn main() {
// least throw a conventional error.
assert!({one! two});
//~^ ERROR expected `(` or `{`, found `}`
//~| ERROR cannot apply unary operator `!` to type `!`
}

View File

@ -25,13 +25,6 @@ LL | assert!({one! two()});
= note: expected type `bool`
found type `()`
error[E0600]: cannot apply unary operator `!` to type `!`
--> $DIR/issue-10536.rs:31:5
|
LL | assert!({one! two});
| ^^^^^^^^^^^^^^^^^^^^ cannot apply unary operator `!`
error: aborting due to 4 previous errors
error: aborting due to 5 previous errors
Some errors occurred: E0308, E0600.
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0308`.