Skip to content

Commit 9946f84

Browse files
committed
experimenting
1 parent f9c0319 commit 9946f84

File tree

5 files changed

+36
-25
lines changed

5 files changed

+36
-25
lines changed

src/librustc/ty/mod.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -244,27 +244,27 @@ impl<'tcx> ImplOrTraitItem<'tcx> {
244244
match node.span() {
245245
Some(span) => match tcx.sess.codemap().span_to_oneline_snippet(span) {
246246
Ok(snippet) => snippet,
247-
Err(_) => item.signature(),
247+
Err(_) => item.signature(tcx),
248248
},
249-
None => item.signature(),
249+
None => item.signature(tcx),
250250
}
251251
}
252-
None => item.signature(),
252+
None => item.signature(tcx),
253253
}
254254
}
255-
TypeTraitItem(ref item) => item.signature(),
255+
TypeTraitItem(ref item) => item.signature(tcx),
256256
ConstTraitItem(ref item) => {
257257
match tcx.map.get_if_local(item.def_id) {
258258
Some(node) => {
259259
match node.span() {
260260
Some(span) => match tcx.sess.codemap().span_to_oneline_snippet(span) {
261261
Ok(snippet) => snippet,
262-
Err(_) => item.signature(),
262+
Err(_) => item.signature(tcx),
263263
},
264-
None => item.signature(),
264+
None => item.signature(tcx),
265265
}
266266
}
267-
None => item.signature(),
267+
None => item.signature(tcx),
268268
}
269269
}
270270
}
@@ -362,7 +362,7 @@ impl<'tcx> Method<'tcx> {
362362
}
363363
}
364364

365-
pub fn signature(&self) -> String {
365+
pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
366366
let name = self.name.to_string();
367367
let unsafety = match self.fty.unsafety {
368368
hir::Unsafety::Unsafe => "unsafe ",
@@ -379,6 +379,7 @@ impl<'tcx> Method<'tcx> {
379379
};
380380
let args = self.fty.sig.inputs().0.iter()
381381
.map(|t| format!("{:?}", t)).collect::<Vec<_>>().join(", ");
382+
//let return_type = format!("{}", tcx.item_name(self.fty.sig.output().0.def_id).as_str());
382383
let return_type = format!("{:?}", self.fty.sig.output().0);
383384
let return_signature = if &return_type == "()" {
384385
"".to_string()
@@ -387,7 +388,8 @@ impl<'tcx> Method<'tcx> {
387388
};
388389

389390
// unsafe fn name<'a, T>(args) -> ReturnType
390-
format!("{}fn {}{}({}){};", unsafety, name, type_args, args, return_signature)
391+
//format!("{}fn {}{}({}){};", unsafety, name, type_args, args, return_signature)
392+
format!("{}fn {}", unsafety, self.fty.sig.0)//name, type_args, args, return_signature)
391393
}
392394
}
393395

@@ -417,13 +419,14 @@ pub struct AssociatedConst<'tcx> {
417419
}
418420

419421
impl<'tcx> AssociatedConst<'tcx> {
420-
pub fn signature(&self) -> String {
422+
pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
421423
// const FOO: Type = DEFAULT;
422424
let value = if self.has_value {
423425
" = <DEFAULT>"
424426
} else {
425427
""
426428
};
429+
//format!("const {}: {}{};", self.name.to_string(), tcx.item_name(self.ty.def_id).as_str(), value)
427430
format!("const {}: {:?}{};", self.name.to_string(), self.ty, value)
428431
}
429432
}
@@ -439,7 +442,7 @@ pub struct AssociatedType<'tcx> {
439442
}
440443

441444
impl<'tcx> AssociatedType<'tcx> {
442-
pub fn signature(&self) -> String {
445+
pub fn signature<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
443446
//// type Type;
444447
format!("type {};", self.name.to_string())
445448
}

src/librustc_errors/emitter.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ impl EmitterWriter {
151151
let mut hi = cm.lookup_char_pos(span_label.span.hi);
152152
let mut is_minimized = false;
153153

154+
let start = lo.line;
155+
let end = hi.line + 1;
154156
// If the span is multi-line, simplify down to the span of one character
155157
if lo.line != hi.line {
156158
hi.line = lo.line;
@@ -167,16 +169,18 @@ impl EmitterWriter {
167169
hi.col = CharPos(lo.col.0 + 1);
168170
}
169171

170-
add_annotation_to_file(&mut output,
171-
lo.file,
172-
lo.line,
173-
Annotation {
174-
start_col: lo.col.0,
175-
end_col: hi.col.0,
176-
is_primary: span_label.is_primary,
177-
is_minimized: is_minimized,
178-
label: span_label.label.clone(),
179-
});
172+
for line in start..end {
173+
add_annotation_to_file(&mut output,
174+
lo.file.clone(),
175+
line,
176+
Annotation {
177+
start_col: lo.col.0,
178+
end_col: hi.col.0,
179+
is_primary: span_label.is_primary,
180+
is_minimized: is_minimized,
181+
label: span_label.label.clone(),
182+
});
183+
}
180184
}
181185
}
182186
output

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub mod registry;
5252
pub mod styled_buffer;
5353
mod lock;
5454

55-
use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION };
55+
use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION};
5656
use syntax_pos::{MacroBacktrace};
5757

5858
#[derive(Clone)]

src/librustc_typeck/check/compare_method.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
8787
err.span_label(span, & format!("`{}` used in trait",
8888
trait_m.explicit_self));
8989
}
90-
err.note(&format!("Expected signature: {}", trait_m.signature()));
91-
err.note(&format!(" Found signature: {}", impl_m.signature()));
90+
9291
err.emit();
9392
return;
9493
}

src/librustc_typeck/check/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,12 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11241124
.collect::<Vec<_>>().join("`, `"))
11251125
);
11261126
for trait_item in missing_items {
1127-
err.note(&(trait_item.signature(tcx)));
1127+
err.note(&format!("definition {}", trait_item.signature(tcx)));
1128+
//err.note(&format!("node {:?}", tcx.map.trait_item.signature(tcx)));
1129+
if let Some(span) = tcx.map.span_if_local(trait_item.def_id()) {
1130+
//struct_span_err!(tcx.sess, span, E0046, "definition").emit();
1131+
err.span_note(span, "definition");//.emit();
1132+
}
11281133
}
11291134
err.emit();
11301135
}

0 commit comments

Comments
 (0)