From aefa25e0df5065cca88fd7dfe92fe239d5cadbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 30 Sep 2016 22:40:34 -0700 Subject: [PATCH] wip: print complete multiline span --- src/librustc/ty/mod.rs | 4 +-- src/librustc_errors/emitter.rs | 43 ++++++++++++++++++++------------ src/librustc_typeck/check/mod.rs | 23 ++++++++++++----- src/libsyntax/codemap.rs | 2 +- src/libsyntax_pos/lib.rs | 6 +++++ 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e0aee6998dd27..7d2972a9ed705 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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) } } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 197adbe742596..553a3dce0e41b 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -109,22 +109,26 @@ impl EmitterWriter { fn add_annotation_to_file(file_vec: &mut Vec, file: Rc, line_index: usize, - ann: Annotation) { + annotation: Option) { + 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; @@ -135,7 +139,7 @@ impl EmitterWriter { file: file, lines: vec![Line { line_index: line_index, - annotations: vec![ann], + annotations: ann, }], }); } @@ -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); + } } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1cb94cb35ff06..31b639872e2b1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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::>().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::>().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(); diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 57cb57d465c10..863af152afce1 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -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> { + pub fn lookup_line(&self, pos: BytePos) -> Result> { let idx = self.lookup_filemap_idx(pos); let files = self.files.borrow(); diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 13dcf7b188b70..b840d98de53d6 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -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 }