@@ -4378,9 +4378,10 @@ impl<'a> Parser<'a> {
43784378 Ok ( Some ( self . mk_item ( span, ident, ItemKind :: MacroDef ( def) , vis. clone ( ) , attrs. to_vec ( ) ) ) )
43794379 }
43804380
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 > > {
43844385 maybe_whole ! ( self , NtStmt , |x| Some ( x) ) ;
43854386
43864387 let attrs = self . parse_outer_attributes ( ) ?;
@@ -4586,20 +4587,15 @@ impl<'a> Parser<'a> {
45864587 if self . eat ( & token:: Semi ) {
45874588 stmt_span = stmt_span. with_hi ( self . prev_span . hi ( ) ) ;
45884589 }
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+ }
46034599 }
46044600 Err ( mut e) => {
46054601 self . recover_stmt_ ( SemiColonMode :: Break , BlockMode :: Ignore ) ;
0 commit comments