Change:
I ended up spending way too much time debugging the following error, since I was trying to port some C code to rust. Give the error: The error message is very vague and hard to determine the actual error here. Seeing as though some programming languages like Java and C use for arrays, I think it'd make sense for the compiler to suggest using if the user is trying to create an array. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I suppose adding manual diagnostic somewhere around will get the job done. claim

Discussion:
} else if self.check(&token::BinOp(token::Or)) || self.check(&token::OrOr) { self.parse_closure_expr(attrs) } else if self.check(&token::OpenDelim(token::Bracket)) { <del> self.parse_array_or_repeat_expr(attrs) </del> <ins> self.parse_array_or_repeat_expr(attrs, token::Bracket) </ins> } else if self.check_path() { self.parse_path_start_expr(attrs) } else if self.check_keyword(kw::Move) || self.check_keyword(kw::Static) {

self.maybe_recover_from_bad_qpath(expr, true) } <del> fn parse_array_or_repeat_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> { </del> <ins> fn parse_array_or_repeat_expr( &mut self, attrs: AttrVec, close_delim: token::DelimToken, ) -> PResult<'a, P<Expr>> { </ins> let lo = self.token.span; <del> self.bump(); // `[` </del> <ins> self.bump(); // `[` or other open delim </ins> <del> let close = &token::CloseDelim(token::Bracket); </del> <ins> let close = &token::CloseDelim(close_delim); </ins> let kind = if self.eat(close) { // Empty vector ExprKind::Array(Vec::new())

} } <ins> fn is_array_like_block(&mut self) -> bool { self.look_ahead(1, |t| matches!(t.kind, TokenKind::Ident(..) | TokenKind::Literal(_))) && self.look_ahead(2, |t| t == &token::Comma) && self.look_ahead(3, |t| t.can_begin_expr()) } /// Emits a suggestion if it looks like the user meant an array but /// accidentally used braces, causing the code to be interpreted as a block /// expression. fn maybe_suggest_brackets_instead_of_braces( &mut self, lo: Span, attrs: AttrVec, ) -> Option<P<Expr>> { let mut snapshot = self.clone(); match snapshot.parse_array_or_repeat_expr(attrs, token::Brace) { Ok(arr) => { let hi = snapshot.prev_token.span; self.struct_span_err( arr.span, "this code is interpreted as a block expression, not an array", ) .multipart_suggestion( "try using [] instead of {}", vec![(lo, "[".to_owned()), (hi, "]".to_owned())], Applicability::MaybeIncorrect, ) .note("to define an array, one would use square brackets instead of curly braces") .emit(); *self = snapshot; Some(self.mk_expr_err(arr.span)) } Err(mut e) => { e.cancel(); None } } } </ins> /// Parses a block or unsafe block. pub(super) fn parse_block_expr( &mut self,

blk_mode: BlockCheckMode, mut attrs: AttrVec, ) -> PResult<'a, P<Expr>> { <ins> if self.is_array_like_block() { if let Some(arr) = self.maybe_suggest_brackets_instead_of_braces(lo, attrs.clone()) { return Ok(arr); } } </ins> if let Some(label) = opt_label { self.sess.gated_spans.gate(sym::label_break_value, label.ident.span); }

<ins> fn main() {} const FOO: [u8; 3] = { //~ ERROR this code is interpreted as a block expression 1, 2, 3 }; const BAR: [&str; 3] = {"one", "two", "three"}; //~^ ERROR this code is interpreted as a block expression fn foo() { {1, 2, 3}; //~^ ERROR this code is interpreted as a block expression } fn bar() { 1, 2, 3 //~ ERROR expected one of } </ins>

<ins> error: this code is interpreted as a block expression, not an array --> $DIR/issue-87830-try-brackets-for-arrays.rs:3:22 | LL |   const FOO: [u8; 3] = { |  ______________________^ LL | |     1, 2, 3 LL | | }; | |_^ | = note: to define an array, one would use square brackets instead of curly braces help: try using [] instead of {} | LL ~ const FOO: [u8; 3] = [ LL |     1, 2, 3 LL ~ ]; | error: this code is interpreted as a block expression, not an array --> $DIR/issue-87830-try-brackets-for-arrays.rs:7:24 | LL | const BAR: [&str; 3] = {"one", "two", "three"}; |                        ^^^^^^^^^^^^^^^^^^^^^^^ | = note: to define an array, one would use square brackets instead of curly braces help: try using [] instead of {} | LL | const BAR: [&str; 3] = ["one", "two", "three"]; |                        ~                     ~ error: this code is interpreted as a block expression, not an array --> $DIR/issue-87830-try-brackets-for-arrays.rs:11:5 | LL |     {1, 2, 3}; |     ^^^^^^^^^ | = note: to define an array, one would use square brackets instead of curly braces help: try using [] instead of {} | LL |     [1, 2, 3]; |     ~       ~ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `,` --> $DIR/issue-87830-try-brackets-for-arrays.rs:16:6 | LL |     1, 2, 3 |      ^ expected one of `.`, `;`, `?`, `}`, or an operator error: aborting due to 4 previous errors </ins>