@@ -383,6 +383,11 @@ struct DiagnosticMetadata<'ast> {
383383 /// Only used for better errors on `fn(): fn()`.
384384 current_type_ascription : Vec < Span > ,
385385
386+ /// Only used for better errors on `let x = { foo: bar };`.
387+ /// In the case of a parse error with `let x = { foo: bar, };`, this isn't needed, it's only
388+ /// needed for cases where this parses as a correct type ascription.
389+ current_block_could_be_bare_struct_literal : Option < Span > ,
390+
386391 /// Only used for better errors on `let <pat>: <expr, not type>;`.
387392 current_let_binding : Option < ( Span , Option < Span > , Option < Span > ) > ,
388393
@@ -1859,6 +1864,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18591864 let instead = res. is_some ( ) ;
18601865 let suggestion =
18611866 if res. is_none ( ) { this. report_missing_type_error ( path) } else { None } ;
1867+ // get_from_node_id
18621868
18631869 this. r . use_injections . push ( UseError {
18641870 err,
@@ -2242,6 +2248,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
22422248 self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
22432249 }
22442250
2251+ let prev = self . diagnostic_metadata . current_block_could_be_bare_struct_literal . take ( ) ;
2252+ if let ( true , [ Stmt { kind : StmtKind :: Expr ( expr) , .. } ] ) =
2253+ ( block. could_be_bare_literal , & block. stmts [ ..] )
2254+ {
2255+ if let ExprKind :: Type ( ..) = expr. kind {
2256+ self . diagnostic_metadata . current_block_could_be_bare_struct_literal =
2257+ Some ( block. span ) ;
2258+ }
2259+ }
22452260 // Descend into the block.
22462261 for stmt in & block. stmts {
22472262 if let StmtKind :: Item ( ref item) = stmt. kind {
@@ -2255,6 +2270,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
22552270
22562271 self . visit_stmt ( stmt) ;
22572272 }
2273+ self . diagnostic_metadata . current_block_could_be_bare_struct_literal = prev;
22582274
22592275 // Move back up.
22602276 self . parent_scope . module = orig_module;
0 commit comments