Remove fields that are dead since the removal of type ascription syntax
Since `{ ident: ident }` is a parse error, these fields are dead.
This commit is contained in:
parent
90f5eab952
commit
848b0da34f
13 changed files with 13 additions and 66 deletions
|
@ -545,14 +545,6 @@ pub struct Block {
|
|||
pub rules: BlockCheckMode,
|
||||
pub span: Span,
|
||||
pub tokens: Option<LazyAttrTokenStream>,
|
||||
/// The following *isn't* a parse error, but will cause multiple errors in following stages.
|
||||
/// ```compile_fail
|
||||
/// let x = {
|
||||
/// foo: var
|
||||
/// };
|
||||
/// ```
|
||||
/// #34255
|
||||
pub could_be_bare_literal: bool,
|
||||
}
|
||||
|
||||
/// A match pattern.
|
||||
|
|
|
@ -1225,7 +1225,7 @@ fn walk_mt<T: MutVisitor>(vis: &mut T, MutTy { ty, mutbl: _ }: &mut MutTy) {
|
|||
}
|
||||
|
||||
pub fn walk_block<T: MutVisitor>(vis: &mut T, block: &mut P<Block>) {
|
||||
let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut();
|
||||
let Block { id, stmts, rules: _, span, tokens } = block.deref_mut();
|
||||
vis.visit_id(id);
|
||||
stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt));
|
||||
visit_lazy_tts(vis, tokens);
|
||||
|
|
|
@ -1035,7 +1035,7 @@ pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef)
|
|||
}
|
||||
|
||||
pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result {
|
||||
let Block { stmts, id: _, rules: _, span: _, tokens: _, could_be_bare_literal: _ } = block;
|
||||
let Block { stmts, id: _, rules: _, span: _, tokens: _ } = block;
|
||||
walk_list!(visitor, visit_stmt, stmts);
|
||||
V::Result::output()
|
||||
}
|
||||
|
|
|
@ -395,7 +395,6 @@ mod llvm_enzyme {
|
|||
tokens: None,
|
||||
rules: unsf,
|
||||
span,
|
||||
could_be_bare_literal: false,
|
||||
};
|
||||
let unsf_expr = ecx.expr_block(P(unsf_block));
|
||||
let blackbox_call_expr = ecx.expr_path(ecx.path(span, blackbox_path));
|
||||
|
|
|
@ -110,7 +110,6 @@ fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> {
|
|||
rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated),
|
||||
span,
|
||||
tokens: None,
|
||||
could_be_bare_literal: false,
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -286,7 +286,6 @@ impl<'a> ExtCtxt<'a> {
|
|||
rules: BlockCheckMode::Default,
|
||||
span,
|
||||
tokens: None,
|
||||
could_be_bare_literal: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -971,18 +971,8 @@ impl<'a> Parser<'a> {
|
|||
// fn foo() -> Foo {
|
||||
// field: value,
|
||||
// }
|
||||
// Suggest:
|
||||
// fn foo() -> Foo { Path {
|
||||
// field: value,
|
||||
// } }
|
||||
let guar = err.delay_as_bug();
|
||||
self.restore_snapshot(snapshot);
|
||||
let mut tail = self.mk_block(
|
||||
thin_vec![self.mk_stmt_err(expr.span, guar)],
|
||||
s,
|
||||
lo.to(self.prev_token.span),
|
||||
);
|
||||
tail.could_be_bare_literal = true;
|
||||
if maybe_struct_name.is_ident() && can_be_struct_literal {
|
||||
// Account for `if Example { a: one(), }.is_pos() {}`.
|
||||
// expand `before` so that we take care of module path such as:
|
||||
|
@ -1004,6 +994,10 @@ impl<'a> Parser<'a> {
|
|||
return None;
|
||||
}
|
||||
} else {
|
||||
// Suggest:
|
||||
// fn foo() -> Foo { Path {
|
||||
// field: value,
|
||||
// } }
|
||||
self.dcx().emit_err(StructLiteralBodyWithoutPath {
|
||||
span: expr.span,
|
||||
sugg: StructLiteralBodyWithoutPathSugg {
|
||||
|
@ -1011,7 +1005,11 @@ impl<'a> Parser<'a> {
|
|||
after: expr.span.shrink_to_hi(),
|
||||
},
|
||||
});
|
||||
Ok(tail)
|
||||
Ok(self.mk_block(
|
||||
thin_vec![self.mk_stmt_err(expr.span, guar)],
|
||||
s,
|
||||
lo.to(self.prev_token.span),
|
||||
))
|
||||
}
|
||||
}
|
||||
(Err(err), Ok(tail)) => {
|
||||
|
@ -1025,10 +1023,7 @@ impl<'a> Parser<'a> {
|
|||
self.consume_block(exp!(OpenBrace), exp!(CloseBrace), ConsumeClosingDelim::Yes);
|
||||
Err(err)
|
||||
}
|
||||
(Ok(_), Ok(mut tail)) => {
|
||||
tail.could_be_bare_literal = true;
|
||||
Ok(tail)
|
||||
}
|
||||
(Ok(_), Ok(tail)) => Ok(tail),
|
||||
});
|
||||
}
|
||||
None
|
||||
|
|
|
@ -1043,14 +1043,7 @@ impl<'a> Parser<'a> {
|
|||
rules: BlockCheckMode,
|
||||
span: Span,
|
||||
) -> P<Block> {
|
||||
P(Block {
|
||||
stmts,
|
||||
id: DUMMY_NODE_ID,
|
||||
rules,
|
||||
span,
|
||||
tokens: None,
|
||||
could_be_bare_literal: false,
|
||||
})
|
||||
P(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None })
|
||||
}
|
||||
|
||||
pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt {
|
||||
|
|
|
@ -674,11 +674,6 @@ struct DiagMetadata<'ast> {
|
|||
/// they are used (in a `break` or `continue` statement)
|
||||
unused_labels: FxHashMap<NodeId, Span>,
|
||||
|
||||
/// Only used for better errors on `let x = { foo: bar };`.
|
||||
/// In the case of a parse error with `let x = { foo: bar, };`, this isn't needed, it's only
|
||||
/// needed for cases where this parses as a correct type ascription.
|
||||
current_block_could_be_bare_struct_literal: Option<Span>,
|
||||
|
||||
/// Only used for better errors on `let <pat>: <expr, not type>;`.
|
||||
current_let_binding: Option<(Span, Option<Span>, Option<Span>)>,
|
||||
|
||||
|
@ -4650,13 +4645,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
self.ribs[ValueNS].push(Rib::new(RibKind::Normal));
|
||||
}
|
||||
|
||||
let prev = self.diag_metadata.current_block_could_be_bare_struct_literal.take();
|
||||
if let (true, [Stmt { kind: StmtKind::Expr(expr), .. }]) =
|
||||
(block.could_be_bare_literal, &block.stmts[..])
|
||||
&& let ExprKind::Type(..) = expr.kind
|
||||
{
|
||||
self.diag_metadata.current_block_could_be_bare_struct_literal = Some(block.span);
|
||||
}
|
||||
// Descend into the block.
|
||||
for stmt in &block.stmts {
|
||||
if let StmtKind::Item(ref item) = stmt.kind
|
||||
|
@ -4670,7 +4658,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
|||
|
||||
self.visit_stmt(stmt);
|
||||
}
|
||||
self.diag_metadata.current_block_could_be_bare_struct_literal = prev;
|
||||
|
||||
// Move back up.
|
||||
self.parent_scope.module = orig_module;
|
||||
|
|
|
@ -450,7 +450,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
err.span_suggestion_verbose(sugg.0, sugg.1, &sugg.2, Applicability::MaybeIncorrect);
|
||||
}
|
||||
|
||||
self.suggest_bare_struct_literal(&mut err);
|
||||
self.suggest_changing_type_to_const_param(&mut err, res, source, span);
|
||||
self.explain_functions_in_pattern(&mut err, res, source);
|
||||
|
||||
|
@ -1281,19 +1280,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn suggest_bare_struct_literal(&mut self, err: &mut Diag<'_>) {
|
||||
if let Some(span) = self.diag_metadata.current_block_could_be_bare_struct_literal {
|
||||
err.multipart_suggestion(
|
||||
"you might have meant to write a `struct` literal",
|
||||
vec![
|
||||
(span.shrink_to_lo(), "{ SomeStruct ".to_string()),
|
||||
(span.shrink_to_hi(), "}".to_string()),
|
||||
],
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn explain_functions_in_pattern(
|
||||
&mut self,
|
||||
err: &mut Diag<'_>,
|
||||
|
|
|
@ -176,7 +176,6 @@ fn rewrite_closure_with_block(
|
|||
.first()
|
||||
.map(|attr| attr.span.to(body.span))
|
||||
.unwrap_or(body.span),
|
||||
could_be_bare_literal: false,
|
||||
};
|
||||
let block = crate::expr::rewrite_block_with_visitor(
|
||||
context,
|
||||
|
|
|
@ -423,7 +423,6 @@ fn rewrite_empty_macro_def_body(
|
|||
rules: ast::BlockCheckMode::Default,
|
||||
span,
|
||||
tokens: None,
|
||||
could_be_bare_literal: false,
|
||||
};
|
||||
block.rewrite_result(context, shape)
|
||||
}
|
||||
|
|
|
@ -114,7 +114,6 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
|||
rules: BlockCheckMode::Default,
|
||||
span: DUMMY_SP,
|
||||
tokens: None,
|
||||
could_be_bare_literal: false,
|
||||
});
|
||||
iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None)));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue