diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 2677a483cdbb6..e0aee6998dd27 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -244,27 +244,27 @@ impl<'tcx> ImplOrTraitItem<'tcx> { match node.span() { Some(span) => match tcx.sess.codemap().span_to_oneline_snippet(span) { Ok(snippet) => snippet, - Err(_) => item.signature(), + Err(_) => item.signature(tcx), }, - None => item.signature(), + None => item.signature(tcx), } } - None => item.signature(), + None => item.signature(tcx), } } - TypeTraitItem(ref item) => item.signature(), + TypeTraitItem(ref item) => item.signature(tcx), ConstTraitItem(ref item) => { match tcx.map.get_if_local(item.def_id) { Some(node) => { match node.span() { Some(span) => match tcx.sess.codemap().span_to_oneline_snippet(span) { Ok(snippet) => snippet, - Err(_) => item.signature(), + Err(_) => item.signature(tcx), }, - None => item.signature(), + None => item.signature(tcx), } } - None => item.signature(), + None => item.signature(tcx), } } } @@ -362,7 +362,7 @@ impl<'tcx> Method<'tcx> { } } - pub fn signature(&self) -> String { + pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String { let name = self.name.to_string(); let unsafety = match self.fty.unsafety { hir::Unsafety::Unsafe => "unsafe ", @@ -379,6 +379,7 @@ impl<'tcx> Method<'tcx> { }; let args = self.fty.sig.inputs().0.iter() .map(|t| format!("{:?}", t)).collect::>().join(", "); + //let return_type = format!("{}", tcx.item_name(self.fty.sig.output().0.def_id).as_str()); let return_type = format!("{:?}", self.fty.sig.output().0); let return_signature = if &return_type == "()" { "".to_string() @@ -387,7 +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, name, type_args, args, return_signature) + format!("{}fn {}", unsafety, self.fty.sig.0)//name, type_args, args, return_signature) } } @@ -417,13 +419,14 @@ pub struct AssociatedConst<'tcx> { } impl<'tcx> AssociatedConst<'tcx> { - pub fn signature(&self) -> String { + pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String { // const FOO: Type = DEFAULT; let value = if self.has_value { " = " } else { "" }; + //format!("const {}: {}{};", self.name.to_string(), tcx.item_name(self.ty.def_id).as_str(), value) format!("const {}: {:?}{};", self.name.to_string(), self.ty, value) } } @@ -439,7 +442,7 @@ pub struct AssociatedType<'tcx> { } impl<'tcx> AssociatedType<'tcx> { - pub fn signature(&self) -> String { + pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String { //// type Type; format!("type {};", self.name.to_string()) } diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 1d7ff45b3b8a0..197adbe742596 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -151,6 +151,8 @@ impl EmitterWriter { let mut hi = cm.lookup_char_pos(span_label.span.hi); let mut is_minimized = false; + let start = lo.line; + let end = hi.line + 1; // If the span is multi-line, simplify down to the span of one character if lo.line != hi.line { hi.line = lo.line; @@ -167,16 +169,18 @@ impl EmitterWriter { hi.col = CharPos(lo.col.0 + 1); } - add_annotation_to_file(&mut output, - lo.file, - lo.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(), - }); + 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(), + }); + } } } output diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index bc599a8207656..be16bc37f4ac6 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -52,7 +52,7 @@ pub mod registry; pub mod styled_buffer; mod lock; -use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION }; +use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION}; use syntax_pos::{MacroBacktrace}; #[derive(Clone)] diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 595329e39f766..14abd6f0e211f 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -87,8 +87,7 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, err.span_label(span, & format!("`{}` used in trait", trait_m.explicit_self)); } - err.note(&format!("Expected signature: {}", trait_m.signature())); - err.note(&format!(" Found signature: {}", impl_m.signature())); + err.emit(); return; } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 14d1fe299dcc9..1cb94cb35ff06 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1124,7 +1124,12 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, .collect::>().join("`, `")) ); for trait_item in missing_items { - err.note(&(trait_item.signature(tcx))); + 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.emit(); }