Skip to content

Commit

Permalink
wip: print complete multiline span
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 1, 2016
1 parent 9946f84 commit aefa25e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ impl<'tcx> Method<'tcx> {
};

// unsafe fn name<'a, T>(args) -> ReturnType
//format!("{}fn {}{}({}){};", unsafety, name, type_args, args, return_signature)
format!("{}fn {}", unsafety, self.fty.sig.0)//name, type_args, args, return_signature)
format!("{}fn {}{}({}){};", unsafety, name, type_args, args, return_signature)
//format!("{}fn {}", unsafety, self.fty.sig.0)//name, type_args, args, return_signature)
}
}

Expand Down
43 changes: 27 additions & 16 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,26 @@ impl EmitterWriter {
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Rc<FileMap>,
line_index: usize,
ann: Annotation) {
annotation: Option<Annotation>) {

let ann = match annotation {
Some(ref ann) => vec![ann.clone()],
None => vec![]
};
for slot in file_vec.iter_mut() {
// Look through each of our files for the one we're adding to
if slot.file.name == file.name {
// See if we already have a line for it
for line_slot in &mut slot.lines {
if line_slot.line_index == line_index {
line_slot.annotations.push(ann);
if line_slot.line_index == line_index && annotation.is_some() {
line_slot.annotations.push(annotation.unwrap());
return;
}
}
// We don't have a line yet, create one
slot.lines.push(Line {
line_index: line_index,
annotations: vec![ann],
annotations: ann,
});
slot.lines.sort();
return;
Expand All @@ -135,7 +139,7 @@ impl EmitterWriter {
file: file,
lines: vec![Line {
line_index: line_index,
annotations: vec![ann],
annotations: ann,
}],
});
}
Expand Down Expand Up @@ -169,17 +173,24 @@ impl EmitterWriter {
hi.col = CharPos(lo.col.0 + 1);
}

for line in start..end {
add_annotation_to_file(&mut output,
lo.file.clone(),
line,
Annotation {
start_col: lo.col.0,
end_col: hi.col.0,
is_primary: span_label.is_primary,
is_minimized: is_minimized,
label: span_label.label.clone(),
});
add_annotation_to_file(&mut output,
lo.file.clone(),
lo.line,
Some(Annotation {
start_col: lo.col.0,
end_col: hi.col.0,
is_primary: span_label.is_primary,
is_minimized: is_minimized,
label: span_label.label.clone(),
}));
if start != end {
// Add the rest of the lines, without any annotation
for line in start+1..end {
add_annotation_to_file(&mut output,
lo.file.clone(),
line,
None);
}
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,22 +1113,33 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
}

if !missing_items.is_empty() {
let mut err = struct_span_err!(tcx.sess, impl_span, E0046,
let codemap = tcx.sess.codemap();
let start = codemap.lookup_line(impl_span.lo);
let end = codemap.lookup_line(impl_span.hi);
let sp = if let (Ok(start), Ok(end)) = (start, end) {
if start.line != end.line {
impl_span.start_point()
} else {
impl_span
}
} else {
impl_span
};
let mut err = struct_span_err!(tcx.sess, sp, E0046,
"not all trait items implemented, missing: `{}`",
missing_items.iter()
.map(|trait_item| trait_item.name().to_string())
.collect::<Vec<_>>().join("`, `"));
err.span_label(impl_span, &format!("missing `{}` in implementation",
err.span_label(sp, &format!("missing `{}` in implementation",
missing_items.iter()
.map(|name| name.name().to_string())
.collect::<Vec<_>>().join("`, `"))
);
for trait_item in missing_items {
err.note(&format!("definition {}", trait_item.signature(tcx)));
//err.note(&format!("node {:?}", tcx.map.trait_item.signature(tcx)));
if let Some(span) = tcx.map.span_if_local(trait_item.def_id()) {
//struct_span_err!(tcx.sess, span, E0046, "definition").emit();
err.span_note(span, "definition");//.emit();
err.span_label(span, &"missing definition in implementation");
} else {
err.note(&format!("infered definition: `{}`", trait_item.signature(tcx)));
}
}
err.emit();
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl CodeMap {
}

// If the relevant filemap is empty, we don't return a line number.
fn lookup_line(&self, pos: BytePos) -> Result<FileMapAndLine, Rc<FileMap>> {
pub fn lookup_line(&self, pos: BytePos) -> Result<FileMapAndLine, Rc<FileMap>> {
let idx = self.lookup_filemap_idx(pos);

let files = self.files.borrow();
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ impl Span {
Span { lo: BytePos(lo), hi: self.hi, expn_id: self.expn_id}
}

/// Returns a new span representing just the start-point of this span
pub fn start_point(self) -> Span {
let lo = cmp::min(self.lo.0, self.hi.0 - 1);
Span { lo: BytePos(lo), hi: BytePos(lo), expn_id: self.expn_id}
}

/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
pub fn substitute_dummy(self, other: Span) -> Span {
if self.source_equal(&DUMMY_SP) { other } else { self }
Expand Down

0 comments on commit aefa25e

Please sign in to comment.