@@ -4378,9 +4378,10 @@ impl<'a> Parser<'a> {
4378
4378
Ok ( Some ( self . mk_item ( span, ident, ItemKind :: MacroDef ( def) , vis. clone ( ) , attrs. to_vec ( ) ) ) )
4379
4379
}
4380
4380
4381
- fn parse_stmt_without_recovery ( & mut self ,
4382
- macro_legacy_warnings : bool )
4383
- -> PResult < ' a , Option < Stmt > > {
4381
+ fn parse_stmt_without_recovery (
4382
+ & mut self ,
4383
+ macro_legacy_warnings : bool ,
4384
+ ) -> PResult < ' a , Option < Stmt > > {
4384
4385
maybe_whole ! ( self , NtStmt , |x| Some ( x) ) ;
4385
4386
4386
4387
let attrs = self . parse_outer_attributes ( ) ?;
@@ -4586,20 +4587,15 @@ impl<'a> Parser<'a> {
4586
4587
if self . eat ( & token:: Semi ) {
4587
4588
stmt_span = stmt_span. with_hi ( self . prev_span . hi ( ) ) ;
4588
4589
}
4589
- let sugg = pprust:: to_string ( |s| {
4590
- use crate :: print:: pprust:: INDENT_UNIT ;
4591
- s. ibox ( INDENT_UNIT ) ;
4592
- s. bopen ( ) ;
4593
- s. print_stmt ( & stmt) ;
4594
- s. bclose_maybe_open ( stmt. span , false )
4595
- } ) ;
4596
- e. span_suggestion (
4597
- stmt_span,
4598
- "try placing this code inside a block" ,
4599
- sugg,
4600
- // speculative, has been misleading in the past (closed Issue #46836)
4601
- Applicability :: MaybeIncorrect
4602
- ) ;
4590
+ if let Ok ( snippet) = self . sess . source_map ( ) . span_to_snippet ( stmt_span) {
4591
+ e. span_suggestion (
4592
+ stmt_span,
4593
+ "try placing this code inside a block" ,
4594
+ format ! ( "{{ {} }}" , snippet) ,
4595
+ // speculative, has been misleading in the past (#46836)
4596
+ Applicability :: MaybeIncorrect ,
4597
+ ) ;
4598
+ }
4603
4599
}
4604
4600
Err ( mut e) => {
4605
4601
self . recover_stmt_ ( SemiColonMode :: Break , BlockMode :: Ignore ) ;
0 commit comments