use codemap::{self, COMMAND_LINE_SP, DUMMY_SP, Pos, Span, MultiSpan};
use diagnostics;
+use errors::check_old_skool;
use errors::{Level, RenderSpan, CodeSuggestion, DiagnosticBuilder};
use errors::RenderSpan::*;
use errors::Level::*;
}
fn emit_struct(&mut self, db: &DiagnosticBuilder) {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
let db_span = FullSpan(db.span.clone());
self.emit_message(&FullSpan(db.span.clone()),
&db.message,
registry: Option<diagnostics::registry::Registry>,
code_map: Rc<codemap::CodeMap>)
-> EmitterWriter {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
if color_config.use_color() {
let dst = Destination::from_stderr();
EmitterWriter { dst: dst,
registry: Option<diagnostics::registry::Registry>,
code_map: Rc<codemap::CodeMap>)
-> EmitterWriter {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
EmitterWriter { dst: Raw(dst),
registry: registry,
cm: code_map,
code: Option<&str>)
-> io::Result<()> {
if !topic.is_empty() {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
if !old_school {
write!(dst, "{}: ", topic)?;
}
None => diag.bug(&msg()),
}
}
+
+/// True if we should use the old-skool error format style. This is
+/// the default setting until the new errors are deemed stable enough
+/// for general use.
+///
+/// FIXME(#33240)
+#[cfg(not(test))]
+fn check_old_skool() -> bool {
+ use std::env;
+ env::var("RUST_NEW_ERROR_FORMAT").is_err()
+}
+
+/// For unit tests, use the new format.
+#[cfg(test)]
+fn check_old_skool() -> bool {
+ false
+}
// Code for annotating snippets.
use codemap::{CharPos, CodeMap, FileMap, LineInfo, Span};
+use errors::check_old_skool;
use std::cmp;
use std::rc::Rc;
use std::mem;
}
fn render_file_lines(&self, codemap: &Rc<CodeMap>) -> Vec<RenderedLine> {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
+
// As a first step, we elide any instance of more than one
// continuous unannotated line.
}
fn render_line(&self, line: &Line) -> Vec<RenderedLine> {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
let source_string = self.file.get_line(line.line_index)
.unwrap_or("");
let source_kind = RenderedLineKind::SourceText {
}
fn prepend_prefixes(rendered_lines: &mut [RenderedLine]) {
- let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
- Ok(_) => false,
- Err(_) => true,
- };
+ let old_school = check_old_skool();
if old_school {
return;
}
println!("text=\n{}", text);
assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> vec.push(vec.pop().unwrap());
|> --- --- - previous borrow ends here
|> | |
|> | |
|> | b
|> a
->>>>>> bar.rs
+ ::: bar.rs
17 |> vec.push();
|> --- - f
|> |
println!("text=\n{}", text);
assert_eq!(&text[..], &r#"
->>>>>> foo.rs
+ ::: foo.rs
3 |> let name = find_id(&data, 22).unwrap();
|> ---- immutable borrow begins here
...
println!("text=r#\"\n{}\".trim_left()", text);
assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> vec.push(vec.pop().unwrap());
|> -------- ------ D
|> ||
println!("text=r#\"\n{}\".trim_left()", text);
assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> vec.push(vec.pop().unwrap());
|> --- --- - previous borrow ends here
|> | |
let text: String = make_string(&lines);
println!("text=r#\"\n{}\".trim_left()", text);
assert_eq!(&text[..], &r#"
->>>>>> foo.rs
+ ::: foo.rs
4 |> let mut vec2 = vec;
|> --- `vec` moved here because it has type `collections::vec::Vec<i32>`
...
let text: String = make_string(&lines);
println!("text=&r#\"\n{}\n\"#[1..]", text);
assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> let mut vec = vec![0, 1, 2];
|> --- ---
4 |> let mut vec2 = vec;
let text: String = make_string(&lines);
println!("r#\"\n{}\"", text);
assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> fn foo(x: u32) {
|> -
"#[1..]);
let text: String = make_string(&lines);
println!("r#\"\n{}\"", text);
assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
2 |> fn foo(x: u32) {
|> --------------
|> | |
let text: String = make_string(&lines);
println!("r#\"\n{}\"", text);
assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
2 |> fn foo(x: u32) {
|> --------------
|> | |
let text: String = make_string(&lines);
println!("r#\"\n{}\"", text);
assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
3 |> let closure = || {
|> - foo
4 |> inner