Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #33354

Merged
merged 60 commits into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3eef083
libsyntax/pp: minor modernizations
birkenfeld May 1, 2016
4186169
libsyntax/pp: replace manual ring buffer with a VecDeque
birkenfeld May 1, 2016
b51698a
match check: note "catchall" patterns in unreachable error
birkenfeld May 1, 2016
ffba7b7
typeck: remove confusing suggestion for calling a fn type
birkenfeld May 1, 2016
0e89f55
E0269: add suggestion to check for trailing semicolons
birkenfeld May 1, 2016
d20b406
diagnostics for E0432: imports are relative to crate root
birkenfeld May 1, 2016
9e23000
lexer: do not display char confusingly in error message
birkenfeld May 2, 2016
38c8836
docs: Changed docs for `size_of` to describe size as a stride offset
cramertj May 2, 2016
9fe3c06
libstd: correct the link to functions in io module documentation
Ryman May 2, 2016
a20ee76
revamp MultiSpan and introduce new snippet code
nikomatsakis Apr 20, 2016
e7c7a18
adapt JSON to new model
nikomatsakis Apr 20, 2016
5b150cf
add borrowck info inline in main snippet
nikomatsakis Apr 20, 2016
11dc974
refactor to use new snippet code and model
nikomatsakis Apr 20, 2016
d9a947c
use new `note_expected_found` API
nikomatsakis Apr 20, 2016
e416518
update test cases to reflect new messages
nikomatsakis Apr 20, 2016
1ff1887
thread tighter span for closures around
nikomatsakis Apr 20, 2016
489a6c9
replace fileline_{help,note} with {help,note}
nikomatsakis Apr 20, 2016
41a652e
WIP factor out RudimentaryEmitter
nikomatsakis Apr 20, 2016
71c6f81
change errors from Yellow to Magenta
nikomatsakis Apr 20, 2016
4714394
delete the json-errors test
nikomatsakis Apr 20, 2016
9d022f2
rewrite span-length to include strings
nikomatsakis Apr 20, 2016
1067850
refactor the Emitter trait
nikomatsakis Apr 21, 2016
8013eeb
fix error message in librustc_driver tests
nikomatsakis Apr 21, 2016
5adfe5b
Nit: comments should be uppercase letter
nikomatsakis Apr 26, 2016
9a9c9af
Fix whitespace
nikomatsakis Apr 26, 2016
e56121c
Do not import variants from RenderedLineKind
nikomatsakis Apr 26, 2016
d58a4be
Nit: do not import variants from Style
nikomatsakis Apr 26, 2016
d5529f0
Nit: do not use RLK
nikomatsakis Apr 26, 2016
f6496cd
Nit: address various style nits
nikomatsakis Apr 26, 2016
94841be
Nit: in emitter.rs
nikomatsakis Apr 26, 2016
24f4b15
Nit: use last_mut better
nikomatsakis Apr 26, 2016
1fdbfcd
only emit `^` at the start of a multi-line error
nikomatsakis Apr 26, 2016
883b969
Nit: add comment
nikomatsakis Apr 27, 2016
5db4d62
Nit: remove push_primary_span, which was never called
nikomatsakis Apr 27, 2016
ba12ed0
fix tests better
nikomatsakis Apr 27, 2016
8a9ad72
Nit: use Range::contains
nikomatsakis Apr 27, 2016
790043b
fix snippet tests MORE!
nikomatsakis Apr 27, 2016
89d086b
change color of warning to YELLOW
nikomatsakis Apr 27, 2016
49dfac4
move "lint level defined here" into secondary note
nikomatsakis Apr 27, 2016
84cb56f
Add back in a 'old school' error format
Apr 28, 2016
79f61a4
Finish up with 'old school' error mode
Apr 29, 2016
5974e5b
Fix up error-pattern style test
Apr 29, 2016
2ba5fac
fix rebase flaws
nikomatsakis Apr 29, 2016
95576b8
update unit tests
nikomatsakis Apr 30, 2016
64e0819
patch travis failure
nikomatsakis Apr 30, 2016
f359aa2
Fix unicode test to use original error format
sophiajt Apr 30, 2016
9d151a7
do not fail if len(rendered_lines) is == 1
nikomatsakis May 2, 2016
db8a9a9
avoid double panic
nikomatsakis May 2, 2016
71e6329
rustc: Handle concurrent `create_dir` requests
alexcrichton May 2, 2016
9355a91
assert we get at least two rendered lines back
nikomatsakis May 2, 2016
40199f6
Rollup merge of #32756 - nikomatsakis:borrowck-snippet, r=nrc
Manishearth May 2, 2016
308f10c
Rollup merge of #33309 - birkenfeld:pp, r=nrc
Manishearth May 2, 2016
1d6cc19
Rollup merge of #33320 - birkenfeld:issue31573, r=arielb1
Manishearth May 2, 2016
c4d950d
Rollup merge of #33323 - birkenfeld:issue-31221, r=Manishearth
Manishearth May 2, 2016
68c29e0
Rollup merge of #33324 - birkenfeld:issue-30497, r=GuillaumeGomez
Manishearth May 2, 2016
0ee84c7
Rollup merge of #33325 - birkenfeld:issue-31341, r=jseyfried
Manishearth May 2, 2016
7e88dc7
Rollup merge of #33332 - alexcrichton:handle-more-races, r=michaelwoe…
Manishearth May 2, 2016
ac19fdc
Rollup merge of #33334 - birkenfeld:issue29088, r=Manishearth
Manishearth May 2, 2016
d6c6bbf
Rollup merge of #33335 - cramertj:master, r=alexcrichton
Manishearth May 2, 2016
638cf9f
Rollup merge of #33346 - Ryman:patch-4, r=alexcrichton
Manishearth May 2, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adapt JSON to new model
Each Span now carries a `is_primary` boolean along with an optional
label. If there are multiple labels for a span, it will appear multiple
times.
  • Loading branch information
nikomatsakis committed May 2, 2016
commit e7c7a18d94cf672d6a031455d091e0bebe1a6b7c
202 changes: 83 additions & 119 deletions src/libsyntax/errors/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// FIXME spec the JSON output properly.


use codemap::{self, Span, MacroBacktrace, MultiSpan, CodeMap};
use codemap::{self, MacroBacktrace, Span, SpanLabel, MultiSpan, CodeMap};
use diagnostics::registry::Registry;
use errors::{Level, DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion};
use errors::emitter::Emitter;
Expand Down Expand Up @@ -53,20 +53,13 @@ impl JsonEmitter {
}

impl Emitter for JsonEmitter {
fn emit(&mut self, span: Option<&MultiSpan>, msg: &str, code: Option<&str>, level: Level) {
fn emit(&mut self, span: &MultiSpan, msg: &str, code: Option<&str>, level: Level) {
let data = Diagnostic::new(span, msg, code, level, self);
if let Err(e) = writeln!(&mut self.dst, "{}", as_json(&data)) {
panic!("failed to print diagnostics: {:?}", e);
}
}

fn custom_emit(&mut self, sp: &RenderSpan, msg: &str, level: Level) {
let data = Diagnostic::from_render_span(sp, msg, level, self);
if let Err(e) = writeln!(&mut self.dst, "{}", as_json(&data)) {
panic!("failed to print diagnostics: {:?}", e);
}
}

fn emit_struct(&mut self, db: &DiagnosticBuilder) {
let data = Diagnostic::from_diagnostic_builder(db, self);
if let Err(e) = writeln!(&mut self.dst, "{}", as_json(&data)) {
Expand Down Expand Up @@ -104,8 +97,13 @@ struct DiagnosticSpan {
/// 1-based, character offset.
column_start: usize,
column_end: usize,
/// Is this a "primary" span -- meaning the point, or one of the points,
/// where the error occurred?
is_primary: bool,
/// Source text from the start of line_start to the end of line_end.
text: Vec<DiagnosticSpanLine>,
/// Label that should be placed at this location (if any)
label: Option<String>,
/// If we are suggesting a replacement, this will contain text
/// that should be sliced in atop this span. You may prefer to
/// load the fully rendered version from the parent `Diagnostic`,
Expand Down Expand Up @@ -148,7 +146,7 @@ struct DiagnosticCode {
}

impl<'a> Diagnostic<'a> {
fn new(msp: Option<&MultiSpan>,
fn new(msp: &MultiSpan,
msg: &'a str,
code: Option<&str>,
level: Level,
Expand All @@ -158,35 +156,20 @@ impl<'a> Diagnostic<'a> {
message: msg,
code: DiagnosticCode::map_opt_string(code.map(|c| c.to_owned()), je),
level: level.to_str(),
spans: msp.map_or(vec![], |msp| DiagnosticSpan::from_multispan(msp, je)),
spans: DiagnosticSpan::from_multispan(msp, je),
children: vec![],
rendered: None,
}
}

fn from_render_span(span: &RenderSpan,
msg: &'a str,
level: Level,
je: &JsonEmitter)
-> Diagnostic<'a> {
Diagnostic {
message: msg,
code: None,
level: level.to_str(),
spans: DiagnosticSpan::from_render_span(span, je),
children: vec![],
rendered: je.render(span),
}
}

fn from_diagnostic_builder<'c>(db: &'c DiagnosticBuilder,
je: &JsonEmitter)
-> Diagnostic<'c> {
Diagnostic {
message: &db.message,
code: DiagnosticCode::map_opt_string(db.code.clone(), je),
level: db.level.to_str(),
spans: db.span.as_ref().map_or(vec![], |sp| DiagnosticSpan::from_multispan(sp, je)),
spans: DiagnosticSpan::from_multispan(&db.span, je),
children: db.children.iter().map(|c| {
Diagnostic::from_sub_diagnostic(c, je)
}).collect(),
Expand All @@ -201,8 +184,7 @@ impl<'a> Diagnostic<'a> {
level: db.level.to_str(),
spans: db.render_span.as_ref()
.map(|sp| DiagnosticSpan::from_render_span(sp, je))
.or_else(|| db.span.as_ref().map(|s| DiagnosticSpan::from_multispan(s, je)))
.unwrap_or(vec![]),
.unwrap_or_else(|| DiagnosticSpan::from_multispan(&db.span, je)),
children: vec![],
rendered: db.render_span.as_ref()
.and_then(|rsp| je.render(rsp)),
Expand All @@ -211,44 +193,68 @@ impl<'a> Diagnostic<'a> {
}

impl DiagnosticSpan {
fn from_span(span: Span, suggestion: Option<&String>, je: &JsonEmitter)
-> DiagnosticSpan {
fn from_span_label(span: SpanLabel,
suggestion: Option<&String>,
je: &JsonEmitter)
-> DiagnosticSpan {
Self::from_span_etc(span.span,
span.is_primary,
span.label,
suggestion,
je)
}

fn from_span_etc(span: Span,
is_primary: bool,
label: Option<String>,
suggestion: Option<&String>,
je: &JsonEmitter)
-> DiagnosticSpan {
// obtain the full backtrace from the `macro_backtrace`
// helper; in some ways, it'd be better to expand the
// backtrace ourselves, but the `macro_backtrace` helper makes
// some decision, such as dropping some frames, and I don't
// want to duplicate that logic here.
let backtrace = je.cm.macro_backtrace(span).into_iter();
DiagnosticSpan::from_span_and_backtrace(span, suggestion, backtrace, je)
DiagnosticSpan::from_span_full(span,
is_primary,
label,
suggestion,
backtrace,
je)
}

fn from_span_and_backtrace(span: Span,
suggestion: Option<&String>,
mut backtrace: vec::IntoIter<MacroBacktrace>,
je: &JsonEmitter)
-> DiagnosticSpan {
fn from_span_full(span: Span,
is_primary: bool,
label: Option<String>,
suggestion: Option<&String>,
mut backtrace: vec::IntoIter<MacroBacktrace>,
je: &JsonEmitter)
-> DiagnosticSpan {
let start = je.cm.lookup_char_pos(span.lo);
let end = je.cm.lookup_char_pos(span.hi);
let backtrace_step =
backtrace.next()
.map(|bt| {
let call_site =
Self::from_span_and_backtrace(bt.call_site,
None,
backtrace,
je);
let def_site_span = bt.def_site_span.map(|sp| {
Self::from_span_and_backtrace(sp,
None,
vec![].into_iter(),
je)
});
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.macro_decl_name,
def_site_span: def_site_span,
})
});
let backtrace_step = backtrace.next().map(|bt| {
let call_site =
Self::from_span_full(bt.call_site,
false,
None,
None,
backtrace,
je);
let def_site_span = bt.def_site_span.map(|sp| {
Self::from_span_full(sp,
false,
None,
None,
vec![].into_iter(),
je)
});
Box::new(DiagnosticSpanMacroExpansion {
span: call_site,
macro_decl_name: bt.macro_decl_name,
def_site_span: def_site_span,
})
});
DiagnosticSpan {
file_name: start.file.name.clone(),
byte_start: span.lo.0,
Expand All @@ -257,53 +263,42 @@ impl DiagnosticSpan {
line_end: end.line,
column_start: start.col.0 + 1,
column_end: end.col.0 + 1,
is_primary: is_primary,
text: DiagnosticSpanLine::from_span(span, je),
suggested_replacement: suggestion.cloned(),
expansion: backtrace_step,
label: label,
}
}

fn from_multispan(msp: &MultiSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
msp.spans.iter().map(|&span| Self::from_span(span, None, je)).collect()
msp.span_labels()
.into_iter()
.map(|span_str| Self::from_span_label(span_str, None, je))
.collect()
}

fn from_suggestion(suggestion: &CodeSuggestion, je: &JsonEmitter)
-> Vec<DiagnosticSpan> {
assert_eq!(suggestion.msp.spans.len(), suggestion.substitutes.len());
suggestion.msp.spans.iter()
.zip(&suggestion.substitutes)
.map(|(&span, suggestion)| {
DiagnosticSpan::from_span(span, Some(suggestion), je)
})
.collect()
assert_eq!(suggestion.msp.span_labels().len(), suggestion.substitutes.len());
suggestion.msp.span_labels()
.into_iter()
.zip(&suggestion.substitutes)
.map(|(span_label, suggestion)| {
DiagnosticSpan::from_span_label(span_label,
Some(suggestion),
je)
})
.collect()
}

fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
match *rsp {
RenderSpan::FileLine(ref msp) |
RenderSpan::FullSpan(ref msp) => {
DiagnosticSpan::from_multispan(msp, je)
}
RenderSpan::Suggestion(ref suggestion) => {
DiagnosticSpan::from_suggestion(suggestion, je)
}
RenderSpan::EndSpan(ref msp) => {
msp.spans.iter().map(|&span| {
let end = je.cm.lookup_char_pos(span.hi);
DiagnosticSpan {
file_name: end.file.name.clone(),
byte_start: span.hi.0,
byte_end: span.hi.0,
line_start: end.line,
line_end: end.line,
column_start: end.col.0 + 1,
column_end: end.col.0 + 1,
text: DiagnosticSpanLine::from_span_end(span, je),
suggested_replacement: None,
expansion: None,
}
}).collect()
}
RenderSpan::FullSpan(ref msp) =>
DiagnosticSpan::from_multispan(msp, je),
RenderSpan::Suggestion(ref suggestion) =>
DiagnosticSpan::from_suggestion(suggestion, je),
}
}
}
Expand Down Expand Up @@ -340,34 +335,6 @@ impl DiagnosticSpanLine {
})
.unwrap_or(vec![])
}

/// Create a list of DiagnosticSpanLines from span - the result covers all
/// of `span`, but the highlight is zero-length and at the end of `span`.
fn from_span_end(span: Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
je.cm.span_to_lines(span)
.map(|lines| {
let fm = &*lines.file;
lines.lines.iter()
.enumerate()
.map(|(i, line)| {
// Invariant - CodeMap::span_to_lines
// will not return extra context lines
// - the last line returned is the last
// line of `span`.
let highlight = if i == lines.lines.len() - 1 {
(line.end_col.0 + 1, line.end_col.0 + 1)
} else {
(0, 0)
};
DiagnosticSpanLine::line_from_filemap(fm,
line.line_index,
highlight.0,
highlight.1)
})
.collect()
})
.unwrap_or(vec![])
}
}

impl DiagnosticCode {
Expand Down Expand Up @@ -396,9 +363,6 @@ impl JsonEmitter {
RenderSpan::Suggestion(ref suggestion) => {
Some(suggestion.splice_lines(&self.cm))
}
RenderSpan::EndSpan(_) => {
None
}
}
}
}
Expand Down
Loading