@@ -156,23 +156,32 @@ impl BorrowExplanation {
156156 err. span_label ( body. source_info ( drop_loc) . span , message) ;
157157
158158 if let Some ( info) = & local_decl. is_block_tail {
159- // FIXME: use span_suggestion instead, highlighting the
160- // whole block tail expression.
161- let msg = if info. tail_result_is_ignored {
162- "The temporary is part of an expression at the end of a block. \
163- Consider adding semicolon after the expression so its temporaries \
164- are dropped sooner, before the local variables declared by the \
165- block are dropped."
159+ if info. tail_result_is_ignored {
160+ err. span_suggestion_verbose (
161+ info. span . shrink_to_hi ( ) ,
162+ "consider adding semicolon after the expression so its \
163+ temporaries are dropped sooner, before the local variables \
164+ declared by the block are dropped",
165+ ";" . to_string ( ) ,
166+ Applicability :: MaybeIncorrect ,
167+ ) ;
166168 } else {
167- "The temporary is part of an expression at the end of a block. \
168- Consider forcing this temporary to be dropped sooner, before \
169- the block's local variables are dropped. \
170- For example, you could save the expression's value in a new \
171- local variable `x` and then make `x` be the expression \
172- at the end of the block."
169+ err. note (
170+ "the temporary is part of an expression at the end of a \
171+ block;\n consider forcing this temporary to be dropped sooner, \
172+ before the block's local variables are dropped",
173+ ) ;
174+ err. multipart_suggestion (
175+ "for example, you could save the expression's value in a new \
176+ local variable `x` and then make `x` be the expression at the \
177+ end of the block",
178+ vec ! [
179+ ( info. span. shrink_to_lo( ) , "let x = " . to_string( ) ) ,
180+ ( info. span. shrink_to_hi( ) , "; x" . to_string( ) ) ,
181+ ] ,
182+ Applicability :: MaybeIncorrect ,
183+ ) ;
173184 } ;
174-
175- err. note ( msg) ;
176185 }
177186 }
178187 }
0 commit comments