Skip to content

Commit 142214d

Browse files
committed
Auto merge of #30411 - mitaa:multispan, r=nrc
This allows to render multiple spans on one line, or to splice multiple replacements into a code suggestion. fixes #28124
2 parents 552bf75 + 727f959 commit 142214d

File tree

10 files changed

+1187
-434
lines changed

10 files changed

+1187
-434
lines changed

src/librustc/session/mod.rs

+44-44
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use session::search_paths::PathKind;
1515
use util::nodemap::{NodeMap, FnvHashMap};
1616

1717
use syntax::ast::{NodeId, NodeIdAssigner, Name};
18-
use syntax::codemap::Span;
18+
use syntax::codemap::{Span, MultiSpan};
1919
use syntax::errors::{self, DiagnosticBuilder};
2020
use syntax::errors::emitter::{Emitter, BasicEmitter, EmitterWriter};
2121
use syntax::errors::json::JsonEmitter;
@@ -47,7 +47,7 @@ pub struct Session {
4747
pub cstore: Rc<for<'a> CrateStore<'a>>,
4848
pub parse_sess: ParseSess,
4949
// For a library crate, this is always none
50-
pub entry_fn: RefCell<Option<(NodeId, codemap::Span)>>,
50+
pub entry_fn: RefCell<Option<(NodeId, Span)>>,
5151
pub entry_type: Cell<Option<config::EntryFnType>>,
5252
pub plugin_registrar_fn: Cell<Option<ast::NodeId>>,
5353
pub default_sysroot: Option<PathBuf>,
@@ -57,7 +57,7 @@ pub struct Session {
5757
pub local_crate_source_file: Option<PathBuf>,
5858
pub working_dir: PathBuf,
5959
pub lint_store: RefCell<lint::LintStore>,
60-
pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
60+
pub lints: RefCell<NodeMap<Vec<(lint::LintId, Span, String)>>>,
6161
pub plugin_llvm_passes: RefCell<Vec<String>>,
6262
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
6363
pub crate_types: RefCell<Vec<config::CrateType>>,
@@ -81,36 +81,36 @@ pub struct Session {
8181
}
8282

8383
impl Session {
84-
pub fn struct_span_warn<'a>(&'a self,
85-
sp: Span,
86-
msg: &str)
87-
-> DiagnosticBuilder<'a> {
84+
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
85+
sp: S,
86+
msg: &str)
87+
-> DiagnosticBuilder<'a> {
8888
self.diagnostic().struct_span_warn(sp, msg)
8989
}
90-
pub fn struct_span_warn_with_code<'a>(&'a self,
91-
sp: Span,
92-
msg: &str,
93-
code: &str)
94-
-> DiagnosticBuilder<'a> {
90+
pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
91+
sp: S,
92+
msg: &str,
93+
code: &str)
94+
-> DiagnosticBuilder<'a> {
9595
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
9696
}
9797
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
9898
self.diagnostic().struct_warn(msg)
9999
}
100-
pub fn struct_span_err<'a>(&'a self,
101-
sp: Span,
102-
msg: &str)
103-
-> DiagnosticBuilder<'a> {
100+
pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
101+
sp: S,
102+
msg: &str)
103+
-> DiagnosticBuilder<'a> {
104104
match split_msg_into_multilines(msg) {
105105
Some(ref msg) => self.diagnostic().struct_span_err(sp, msg),
106106
None => self.diagnostic().struct_span_err(sp, msg),
107107
}
108108
}
109-
pub fn struct_span_err_with_code<'a>(&'a self,
110-
sp: Span,
111-
msg: &str,
112-
code: &str)
113-
-> DiagnosticBuilder<'a> {
109+
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
110+
sp: S,
111+
msg: &str,
112+
code: &str)
113+
-> DiagnosticBuilder<'a> {
114114
match split_msg_into_multilines(msg) {
115115
Some(ref msg) => self.diagnostic().struct_span_err_with_code(sp, msg, code),
116116
None => self.diagnostic().struct_span_err_with_code(sp, msg, code),
@@ -119,46 +119,46 @@ impl Session {
119119
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
120120
self.diagnostic().struct_err(msg)
121121
}
122-
pub fn struct_span_fatal<'a>(&'a self,
123-
sp: Span,
124-
msg: &str)
125-
-> DiagnosticBuilder<'a> {
122+
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
123+
sp: S,
124+
msg: &str)
125+
-> DiagnosticBuilder<'a> {
126126
self.diagnostic().struct_span_fatal(sp, msg)
127127
}
128-
pub fn struct_span_fatal_with_code<'a>(&'a self,
129-
sp: Span,
130-
msg: &str,
131-
code: &str)
132-
-> DiagnosticBuilder<'a> {
128+
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
129+
sp: S,
130+
msg: &str,
131+
code: &str)
132+
-> DiagnosticBuilder<'a> {
133133
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
134134
}
135135
pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
136136
self.diagnostic().struct_fatal(msg)
137137
}
138138

139-
pub fn span_fatal(&self, sp: Span, msg: &str) -> ! {
139+
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
140140
panic!(self.diagnostic().span_fatal(sp, msg))
141141
}
142-
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
142+
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) -> ! {
143143
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
144144
}
145145
pub fn fatal(&self, msg: &str) -> ! {
146146
panic!(self.diagnostic().fatal(msg))
147147
}
148-
pub fn span_err_or_warn(&self, is_warning: bool, sp: Span, msg: &str) {
148+
pub fn span_err_or_warn<S: Into<MultiSpan>>(&self, is_warning: bool, sp: S, msg: &str) {
149149
if is_warning {
150150
self.span_warn(sp, msg);
151151
} else {
152152
self.span_err(sp, msg);
153153
}
154154
}
155-
pub fn span_err(&self, sp: Span, msg: &str) {
155+
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
156156
match split_msg_into_multilines(msg) {
157157
Some(msg) => self.diagnostic().span_err(sp, &msg),
158158
None => self.diagnostic().span_err(sp, msg)
159159
}
160160
}
161-
pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
161+
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
162162
match split_msg_into_multilines(msg) {
163163
Some(msg) => self.diagnostic().span_err_with_code(sp, &msg, code),
164164
None => self.diagnostic().span_err_with_code(sp, msg, code)
@@ -199,32 +199,32 @@ impl Session {
199199
}
200200
}
201201
}
202-
pub fn span_warn(&self, sp: Span, msg: &str) {
202+
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
203203
self.diagnostic().span_warn(sp, msg)
204204
}
205-
pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
205+
pub fn span_warn_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
206206
self.diagnostic().span_warn_with_code(sp, msg, code)
207207
}
208208
pub fn warn(&self, msg: &str) {
209209
self.diagnostic().warn(msg)
210210
}
211-
pub fn opt_span_warn(&self, opt_sp: Option<Span>, msg: &str) {
211+
pub fn opt_span_warn<S: Into<MultiSpan>>(&self, opt_sp: Option<S>, msg: &str) {
212212
match opt_sp {
213213
Some(sp) => self.span_warn(sp, msg),
214214
None => self.warn(msg),
215215
}
216216
}
217-
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
217+
pub fn opt_span_bug<S: Into<MultiSpan>>(&self, opt_sp: Option<S>, msg: &str) -> ! {
218218
match opt_sp {
219219
Some(sp) => self.span_bug(sp, msg),
220220
None => self.bug(msg),
221221
}
222222
}
223223
/// Delay a span_bug() call until abort_if_errors()
224-
pub fn delay_span_bug(&self, sp: Span, msg: &str) {
224+
pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
225225
self.diagnostic().delay_span_bug(sp, msg)
226226
}
227-
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
227+
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
228228
self.diagnostic().span_bug(sp, msg)
229229
}
230230
pub fn bug(&self, msg: &str) -> ! {
@@ -233,10 +233,10 @@ impl Session {
233233
pub fn note_without_error(&self, msg: &str) {
234234
self.diagnostic().note_without_error(msg)
235235
}
236-
pub fn span_note_without_error(&self, sp: Span, msg: &str) {
236+
pub fn span_note_without_error<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
237237
self.diagnostic().span_note_without_error(sp, msg)
238238
}
239-
pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
239+
pub fn span_unimpl<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
240240
self.diagnostic().span_unimpl(sp, msg)
241241
}
242242
pub fn unimpl(&self, msg: &str) -> ! {
@@ -273,7 +273,7 @@ impl Session {
273273
}
274274
// This exists to help with refactoring to eliminate impossible
275275
// cases later on
276-
pub fn impossible_case(&self, sp: Span, msg: &str) -> ! {
276+
pub fn impossible_case<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
277277
self.span_bug(sp, &format!("impossible case reached: {}", msg));
278278
}
279279
pub fn verbose(&self) -> bool { self.opts.debugging_opts.verbose }

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
991991
&format!("to force the closure to take ownership of {} \
992992
(and any other referenced variables), \
993993
use the `move` keyword, as shown:",
994-
cmt_path_or_string),
994+
cmt_path_or_string),
995995
suggestion)
996996
.emit();
997997
}

src/librustc_driver/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc::front::map as hir_map;
3232
use rustc::session::{self, config};
3333
use std::rc::Rc;
3434
use syntax::{abi, ast};
35-
use syntax::codemap::{Span, CodeMap, DUMMY_SP};
35+
use syntax::codemap::{MultiSpan, CodeMap, DUMMY_SP};
3636
use syntax::errors;
3737
use syntax::errors::emitter::Emitter;
3838
use syntax::errors::{Level, RenderSpan};
@@ -78,14 +78,14 @@ fn remove_message(e: &mut ExpectErrorEmitter, msg: &str, lvl: Level) {
7878

7979
impl Emitter for ExpectErrorEmitter {
8080
fn emit(&mut self,
81-
_sp: Option<Span>,
81+
_sp: Option<&MultiSpan>,
8282
msg: &str,
8383
_: Option<&str>,
8484
lvl: Level) {
8585
remove_message(self, msg, lvl);
8686
}
8787

88-
fn custom_emit(&mut self, _sp: RenderSpan, msg: &str, lvl: Level) {
88+
fn custom_emit(&mut self, _sp: &RenderSpan, msg: &str, lvl: Level) {
8989
remove_message(self, msg, lvl);
9090
}
9191
}

src/librustc_trans/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl SharedEmitter {
109109
}
110110

111111
impl Emitter for SharedEmitter {
112-
fn emit(&mut self, sp: Option<codemap::Span>,
112+
fn emit(&mut self, sp: Option<&codemap::MultiSpan>,
113113
msg: &str, code: Option<&str>, lvl: Level) {
114114
assert!(sp.is_none(), "SharedEmitter doesn't support spans");
115115

@@ -120,7 +120,7 @@ impl Emitter for SharedEmitter {
120120
});
121121
}
122122

123-
fn custom_emit(&mut self, _sp: errors::RenderSpan, _msg: &str, _lvl: Level) {
123+
fn custom_emit(&mut self, _sp: &errors::RenderSpan, _msg: &str, _lvl: Level) {
124124
panic!("SharedEmitter doesn't support custom_emit");
125125
}
126126
}

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,8 @@ fn report_cast_to_unsized_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
10721072
match fcx.tcx().sess.codemap().span_to_snippet(t_span) {
10731073
Ok(s) => {
10741074
err.span_suggestion(t_span,
1075-
"try casting to a `Box` instead:",
1076-
format!("Box<{}>", s));
1075+
"try casting to a `Box` instead:",
1076+
format!("Box<{}>", s));
10771077
},
10781078
Err(_) =>
10791079
span_help!(err, t_span, "did you mean `Box<{}>`?", tstr),

0 commit comments

Comments
 (0)