@@ -383,6 +383,11 @@ struct DiagnosticMetadata<'ast> {
383
383
/// Only used for better errors on `fn(): fn()`.
384
384
current_type_ascription : Vec < Span > ,
385
385
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
+
386
391
/// Only used for better errors on `let <pat>: <expr, not type>;`.
387
392
current_let_binding : Option < ( Span , Option < Span > , Option < Span > ) > ,
388
393
@@ -1859,6 +1864,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1859
1864
let instead = res. is_some ( ) ;
1860
1865
let suggestion =
1861
1866
if res. is_none ( ) { this. report_missing_type_error ( path) } else { None } ;
1867
+ // get_from_node_id
1862
1868
1863
1869
this. r . use_injections . push ( UseError {
1864
1870
err,
@@ -2242,6 +2248,15 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2242
2248
self . ribs [ ValueNS ] . push ( Rib :: new ( NormalRibKind ) ) ;
2243
2249
}
2244
2250
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
+ }
2245
2260
// Descend into the block.
2246
2261
for stmt in & block. stmts {
2247
2262
if let StmtKind :: Item ( ref item) = stmt. kind {
@@ -2255,6 +2270,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2255
2270
2256
2271
self . visit_stmt ( stmt) ;
2257
2272
}
2273
+ self . diagnostic_metadata . current_block_could_be_bare_struct_literal = prev;
2258
2274
2259
2275
// Move back up.
2260
2276
self . parent_scope . module = orig_module;
0 commit comments