Skip to content

Commit

Permalink
experimenting
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 1, 2016
1 parent f9c0319 commit 9946f84
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
25 changes: 14 additions & 11 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down Expand Up @@ -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 ",
Expand All @@ -379,6 +379,7 @@ impl<'tcx> Method<'tcx> {
};
let args = self.fty.sig.inputs().0.iter()
.map(|t| format!("{:?}", t)).collect::<Vec<_>>().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()
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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 {
" = <DEFAULT>"
} 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)
}
}
Expand All @@ -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())
}
Expand Down
24 changes: 14 additions & 10 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,12 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
.collect::<Vec<_>>().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();
}
Expand Down

0 comments on commit 9946f84

Please sign in to comment.