@@ -9,12 +9,13 @@ use rustc::traits::ProjectionMode;
9
9
use rustc:: traits;
10
10
use rustc:: ty:: subst:: Subst ;
11
11
use rustc:: ty;
12
+ use rustc_errors;
12
13
use std:: borrow:: Cow ;
13
14
use std:: env;
14
15
use std:: mem;
15
16
use std:: str:: FromStr ;
16
17
use syntax:: ast:: { self , LitKind } ;
17
- use syntax:: codemap:: { ExpnInfo , Span , ExpnFormat } ;
18
+ use syntax:: codemap:: { ExpnFormat , ExpnInfo , MultiSpan , Span } ;
18
19
use syntax:: errors:: DiagnosticBuilder ;
19
20
use syntax:: ptr:: P ;
20
21
@@ -490,6 +491,25 @@ pub fn span_lint_and_then<'a, T: LintContext, F>(cx: &'a T, lint: &'static Lint,
490
491
}
491
492
}
492
493
494
+ /// Create a suggestion made from several `span → replacement`.
495
+ ///
496
+ /// Note: in the JSON format (used by `compiletest_rs`), the help message will appear once per
497
+ /// replacement. In human-readable format though, it only appears once before the whole suggestion.
498
+ pub fn multispan_sugg ( db : & mut DiagnosticBuilder , help_msg : String , sugg : & [ ( Span , & str ) ] ) {
499
+ let sugg = rustc_errors:: RenderSpan :: Suggestion ( rustc_errors:: CodeSuggestion {
500
+ msp : MultiSpan :: from_spans ( sugg. iter ( ) . map ( |& ( span, _) | span) . collect ( ) ) ,
501
+ substitutes : sugg. iter ( ) . map ( |& ( _, subs) | subs. to_owned ( ) ) . collect ( ) ,
502
+ } ) ;
503
+
504
+ let sub = rustc_errors:: SubDiagnostic {
505
+ level : rustc_errors:: Level :: Help ,
506
+ message : help_msg,
507
+ span : MultiSpan :: new ( ) ,
508
+ render_span : Some ( sugg) ,
509
+ } ;
510
+ db. children . push ( sub) ;
511
+ }
512
+
493
513
/// Return the base type for references and raw pointers.
494
514
pub fn walk_ptrs_ty ( ty : ty:: Ty ) -> ty:: Ty {
495
515
match ty. sty {
0 commit comments