@@ -134,7 +134,9 @@ pub fn report_error<'tcx, 'mir>(
134134) -> Option < i64 > {
135135 use InterpError :: * ;
136136
137- let ( title, labels, helps) = match & e. kind ( ) {
137+ let mut msg = vec ! [ ] ;
138+
139+ let ( title, helps) = match & e. kind ( ) {
138140 MachineStop ( info) => {
139141 let info = info. downcast_ref :: < TerminationInfo > ( ) . expect ( "invalid MachineStop payload" ) ;
140142 use TerminationInfo :: * ;
@@ -146,7 +148,6 @@ pub fn report_error<'tcx, 'mir>(
146148 Deadlock => Some ( "deadlock" ) ,
147149 MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None ,
148150 } ;
149- let mut labels = vec ! [ ] ;
150151 #[ rustfmt:: skip]
151152 let helps = match info {
152153 UnsupportedInIsolation ( _) =>
@@ -155,9 +156,7 @@ pub fn report_error<'tcx, 'mir>(
155156 ( None , format!( "or pass `-Zmiri-isolation-error=warn to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning" ) ) ,
156157 ] ,
157158 ExperimentalUb { url, help, .. } => {
158- if let Some ( help) = help {
159- labels. push ( help. clone ( ) ) ;
160- }
159+ msg. extend ( help. clone ( ) ) ;
161160 vec ! [
162161 ( None , format!( "this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental" ) ) ,
163162 ( None , format!( "see {} for further information" , url) )
@@ -172,7 +171,7 @@ pub fn report_error<'tcx, 'mir>(
172171 vec ! [ ( Some ( * span) , format!( "the `{}` symbol is defined here" , link_name) ) ] ,
173172 _ => vec ! [ ] ,
174173 } ;
175- ( title, labels , helps)
174+ ( title, helps)
176175 }
177176 _ => {
178177 #[ rustfmt:: skip]
@@ -210,20 +209,19 @@ pub fn report_error<'tcx, 'mir>(
210209 ] ,
211210 _ => vec ! [ ] ,
212211 } ;
213- ( Some ( title) , vec ! [ ] , helps)
212+ ( Some ( title) , helps)
214213 }
215214 } ;
216215
217216 let stacktrace = ecx. generate_stacktrace ( ) ;
218217 let ( stacktrace, was_pruned) = prune_stacktrace ( ecx, stacktrace) ;
219218 e. print_backtrace ( ) ;
220- let msg = e. to_string ( ) ;
219+ msg. insert ( 0 , e. to_string ( ) ) ;
221220 report_msg (
222221 * ecx. tcx ,
223222 DiagLevel :: Error ,
224- & if let Some ( title) = title { format ! ( "{}: {}" , title, msg) } else { msg. clone ( ) } ,
223+ & if let Some ( title) = title { format ! ( "{}: {}" , title, msg[ 0 ] ) } else { msg[ 0 ] . clone ( ) } ,
225224 msg,
226- labels,
227225 helps,
228226 & stacktrace,
229227 ) ;
@@ -263,12 +261,14 @@ pub fn report_error<'tcx, 'mir>(
263261
264262/// Report an error or note (depending on the `error` argument) with the given stacktrace.
265263/// Also emits a full stacktrace of the interpreter stack.
264+ /// We want to present a multi-line span message for some errors. Diagnostics do not support this
265+ /// directly, so we pass the lines as a `Vec<String>` and display each line after the first with an
266+ /// additional `span_label` or `note` call.
266267fn report_msg < ' tcx > (
267268 tcx : TyCtxt < ' tcx > ,
268269 diag_level : DiagLevel ,
269270 title : & str ,
270- span_msg : String ,
271- labels : Vec < String > ,
271+ span_msg : Vec < String > ,
272272 mut helps : Vec < ( Option < SpanData > , String ) > ,
273273 stacktrace : & [ FrameInfo < ' tcx > ] ,
274274) {
@@ -279,18 +279,19 @@ fn report_msg<'tcx>(
279279 DiagLevel :: Note => tcx. sess . diagnostic ( ) . span_note_diag ( span, title) ,
280280 } ;
281281
282+ let first_line = span_msg. get ( 0 ) . cloned ( ) . unwrap_or_default ( ) ;
282283 // Show main message.
283284 if span != DUMMY_SP {
284- err. span_label ( span, span_msg ) ;
285- for label in labels {
286- err. span_label ( span, label ) ;
285+ err. span_label ( span, first_line ) ;
286+ for line in span_msg . iter ( ) . skip ( 1 ) {
287+ err. span_label ( span, line ) ;
287288 }
288289 } else {
289290 // Make sure we show the message even when it is a dummy span.
290- err. note ( & span_msg ) ;
291+ err. note ( & first_line ) ;
291292 err. note ( "(no span available)" ) ;
292- for label in labels {
293- err. note ( & label ) ;
293+ for line in span_msg . iter ( ) . skip ( 1 ) {
294+ err. note ( & line ) ;
294295 }
295296 }
296297
@@ -428,7 +429,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
428429 _ => ( "tracking was triggered" , DiagLevel :: Note ) ,
429430 } ;
430431
431- report_msg ( * this. tcx , diag_level, title, msg , vec ! [ ] , vec ! [ ] , & stacktrace) ;
432+ report_msg ( * this. tcx , diag_level, title, vec ! [ msg ] , vec ! [ ] , & stacktrace) ;
432433 }
433434 } ) ;
434435 }
0 commit comments