Skip to content

Commit 08287c1

Browse files
committed
Toggle span highlighting on -Zteach
1 parent 871856e commit 08287c1

File tree

8 files changed

+33
-18
lines changed

8 files changed

+33
-18
lines changed

src/librustc/session/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,13 @@ pub fn build_session_with_codemap(sopts: config::Options,
904904

905905
let emitter: Box<Emitter> = match (sopts.error_format, emitter_dest) {
906906
(config::ErrorOutputType::HumanReadable(color_config), None) => {
907-
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), false))
907+
Box::new(EmitterWriter::stderr(color_config,
908+
Some(codemap.clone()),
909+
false,
910+
sopts.debugging_opts.teach))
908911
}
909912
(config::ErrorOutputType::HumanReadable(_), Some(dst)) => {
910-
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false))
913+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), false, false))
911914
}
912915
(config::ErrorOutputType::Json(pretty), None) => {
913916
Box::new(JsonEmitter::stderr(Some(registry), codemap.clone(), pretty))
@@ -916,10 +919,10 @@ pub fn build_session_with_codemap(sopts: config::Options,
916919
Box::new(JsonEmitter::new(dst, Some(registry), codemap.clone(), pretty))
917920
}
918921
(config::ErrorOutputType::Short(color_config), None) => {
919-
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true))
922+
Box::new(EmitterWriter::stderr(color_config, Some(codemap.clone()), true, false))
920923
}
921924
(config::ErrorOutputType::Short(_), Some(dst)) => {
922-
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true))
925+
Box::new(EmitterWriter::new(dst, Some(codemap.clone()), true, false))
923926
}
924927
};
925928

@@ -1095,11 +1098,11 @@ pub enum IncrCompSession {
10951098
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
10961099
let emitter: Box<Emitter> = match output {
10971100
config::ErrorOutputType::HumanReadable(color_config) => {
1098-
Box::new(EmitterWriter::stderr(color_config, None, false))
1101+
Box::new(EmitterWriter::stderr(color_config, None, false, false))
10991102
}
11001103
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
11011104
config::ErrorOutputType::Short(color_config) => {
1102-
Box::new(EmitterWriter::stderr(color_config, None, true))
1105+
Box::new(EmitterWriter::stderr(color_config, None, true, false))
11031106
}
11041107
};
11051108
let handler = errors::Handler::with_emitter(true, false, emitter);
@@ -1110,11 +1113,11 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
11101113
pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
11111114
let emitter: Box<Emitter> = match output {
11121115
config::ErrorOutputType::HumanReadable(color_config) => {
1113-
Box::new(EmitterWriter::stderr(color_config, None, false))
1116+
Box::new(EmitterWriter::stderr(color_config, None, false, false))
11141117
}
11151118
config::ErrorOutputType::Json(pretty) => Box::new(JsonEmitter::basic(pretty)),
11161119
config::ErrorOutputType::Short(color_config) => {
1117-
Box::new(EmitterWriter::stderr(color_config, None, true))
1120+
Box::new(EmitterWriter::stderr(color_config, None, true, false))
11181121
}
11191122
};
11201123
let handler = errors::Handler::with_emitter(true, false, emitter);

src/librustc_driver/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ pub fn run<F>(run_compiler: F) -> isize
163163
let emitter =
164164
errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
165165
None,
166-
true);
166+
true,
167+
false);
167168
let handler = errors::Handler::with_emitter(true, false, Box::new(emitter));
168169
handler.emit(&MultiSpan::new(),
169170
"aborting due to previous error(s)",
@@ -1241,6 +1242,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
12411242
let emitter =
12421243
Box::new(errors::emitter::EmitterWriter::stderr(errors::ColorConfig::Auto,
12431244
None,
1245+
false,
12441246
false));
12451247
let handler = errors::Handler::with_emitter(true, false, emitter);
12461248

src/librustc_errors/emitter.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct EmitterWriter {
106106
dst: Destination,
107107
cm: Option<Rc<CodeMapper>>,
108108
short_message: bool,
109+
teach: bool,
109110
}
110111

111112
struct FileWithAnnotatedLines {
@@ -117,32 +118,37 @@ struct FileWithAnnotatedLines {
117118
impl EmitterWriter {
118119
pub fn stderr(color_config: ColorConfig,
119120
code_map: Option<Rc<CodeMapper>>,
120-
short_message: bool)
121+
short_message: bool,
122+
teach: bool)
121123
-> EmitterWriter {
122124
if color_config.use_color() {
123125
let dst = Destination::from_stderr();
124126
EmitterWriter {
125127
dst,
126128
cm: code_map,
127-
short_message: short_message,
129+
short_message,
130+
teach,
128131
}
129132
} else {
130133
EmitterWriter {
131134
dst: Raw(Box::new(io::stderr())),
132135
cm: code_map,
133-
short_message: short_message,
136+
short_message,
137+
teach,
134138
}
135139
}
136140
}
137141

138142
pub fn new(dst: Box<Write + Send>,
139143
code_map: Option<Rc<CodeMapper>>,
140-
short_message: bool)
144+
short_message: bool,
145+
teach: bool)
141146
-> EmitterWriter {
142147
EmitterWriter {
143148
dst: Raw(dst),
144149
cm: code_map,
145-
short_message: short_message,
150+
short_message,
151+
teach,
146152
}
147153
}
148154

@@ -551,13 +557,14 @@ impl EmitterWriter {
551557
code_offset + annotation.start_col,
552558
style);
553559
}
554-
_ => {
560+
_ if self.teach => {
555561
buffer.set_style_range(line_offset,
556562
code_offset + annotation.start_col,
557563
code_offset + annotation.end_col,
558564
style,
559565
annotation.is_primary);
560-
}
566+
}
567+
_ => {}
561568
}
562569
}
563570

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl Handler {
297297
cm: Option<Rc<CodeMapper>>,
298298
flags: HandlerFlags)
299299
-> Handler {
300-
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false));
300+
let emitter = Box::new(EmitterWriter::stderr(color_config, cm, false, false));
301301
Handler::with_emitter_and_flags(emitter, flags)
302302
}
303303

src/librustdoc/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
239239
));
240240
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()),
241241
Some(codemap.clone()),
242+
false,
242243
false);
243244
let old = io::set_panic(Some(box Sink(data.clone())));
244245
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));

src/libsyntax/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Diagnostic {
188188
}
189189
let buf = BufWriter::default();
190190
let output = buf.clone();
191-
EmitterWriter::new(Box::new(buf), Some(je.cm.clone()), false).emit(db);
191+
EmitterWriter::new(Box::new(buf), Some(je.cm.clone()), false, false).emit(db);
192192
let output = Arc::try_unwrap(output.0).unwrap().into_inner().unwrap();
193193
let output = String::from_utf8(output).unwrap();
194194

src/libsyntax/parse/lexer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@ mod tests {
17451745
fn mk_sess(cm: Rc<CodeMap>) -> ParseSess {
17461746
let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()),
17471747
Some(cm.clone()),
1748+
false,
17481749
false);
17491750
ParseSess {
17501751
span_diagnostic: errors::Handler::with_emitter(true, false, Box::new(emitter)),

src/libsyntax/test_snippet.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
6262

6363
let emitter = EmitterWriter::new(Box::new(Shared { data: output.clone() }),
6464
Some(code_map.clone()),
65+
false,
6566
false);
6667
let handler = Handler::with_emitter(true, false, Box::new(emitter));
6768
handler.span_err(msp, "foo");

0 commit comments

Comments
 (0)