Skip to content

Commit aefa25e

Browse files
committed
wip: print complete multiline span
1 parent 9946f84 commit aefa25e

File tree

5 files changed

+53
-25
lines changed

5 files changed

+53
-25
lines changed

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ impl<'tcx> Method<'tcx> {
388388
};
389389

390390
// unsafe fn name<'a, T>(args) -> ReturnType
391-
//format!("{}fn {}{}({}){};", unsafety, name, type_args, args, return_signature)
392-
format!("{}fn {}", unsafety, self.fty.sig.0)//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)
393393
}
394394
}
395395

src/librustc_errors/emitter.rs

+27-16
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,26 @@ impl EmitterWriter {
109109
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
110110
file: Rc<FileMap>,
111111
line_index: usize,
112-
ann: Annotation) {
112+
annotation: Option<Annotation>) {
113113

114+
let ann = match annotation {
115+
Some(ref ann) => vec![ann.clone()],
116+
None => vec![]
117+
};
114118
for slot in file_vec.iter_mut() {
115119
// Look through each of our files for the one we're adding to
116120
if slot.file.name == file.name {
117121
// See if we already have a line for it
118122
for line_slot in &mut slot.lines {
119-
if line_slot.line_index == line_index {
120-
line_slot.annotations.push(ann);
123+
if line_slot.line_index == line_index && annotation.is_some() {
124+
line_slot.annotations.push(annotation.unwrap());
121125
return;
122126
}
123127
}
124128
// We don't have a line yet, create one
125129
slot.lines.push(Line {
126130
line_index: line_index,
127-
annotations: vec![ann],
131+
annotations: ann,
128132
});
129133
slot.lines.sort();
130134
return;
@@ -135,7 +139,7 @@ impl EmitterWriter {
135139
file: file,
136140
lines: vec![Line {
137141
line_index: line_index,
138-
annotations: vec![ann],
142+
annotations: ann,
139143
}],
140144
});
141145
}
@@ -169,17 +173,24 @@ impl EmitterWriter {
169173
hi.col = CharPos(lo.col.0 + 1);
170174
}
171175

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-
});
176+
add_annotation_to_file(&mut output,
177+
lo.file.clone(),
178+
lo.line,
179+
Some(Annotation {
180+
start_col: lo.col.0,
181+
end_col: hi.col.0,
182+
is_primary: span_label.is_primary,
183+
is_minimized: is_minimized,
184+
label: span_label.label.clone(),
185+
}));
186+
if start != end {
187+
// Add the rest of the lines, without any annotation
188+
for line in start+1..end {
189+
add_annotation_to_file(&mut output,
190+
lo.file.clone(),
191+
line,
192+
None);
193+
}
183194
}
184195
}
185196
}

src/librustc_typeck/check/mod.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1113,22 +1113,33 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11131113
}
11141114

11151115
if !missing_items.is_empty() {
1116-
let mut err = struct_span_err!(tcx.sess, impl_span, E0046,
1116+
let codemap = tcx.sess.codemap();
1117+
let start = codemap.lookup_line(impl_span.lo);
1118+
let end = codemap.lookup_line(impl_span.hi);
1119+
let sp = if let (Ok(start), Ok(end)) = (start, end) {
1120+
if start.line != end.line {
1121+
impl_span.start_point()
1122+
} else {
1123+
impl_span
1124+
}
1125+
} else {
1126+
impl_span
1127+
};
1128+
let mut err = struct_span_err!(tcx.sess, sp, E0046,
11171129
"not all trait items implemented, missing: `{}`",
11181130
missing_items.iter()
11191131
.map(|trait_item| trait_item.name().to_string())
11201132
.collect::<Vec<_>>().join("`, `"));
1121-
err.span_label(impl_span, &format!("missing `{}` in implementation",
1133+
err.span_label(sp, &format!("missing `{}` in implementation",
11221134
missing_items.iter()
11231135
.map(|name| name.name().to_string())
11241136
.collect::<Vec<_>>().join("`, `"))
11251137
);
11261138
for trait_item in missing_items {
1127-
err.note(&format!("definition {}", trait_item.signature(tcx)));
1128-
//err.note(&format!("node {:?}", tcx.map.trait_item.signature(tcx)));
11291139
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();
1140+
err.span_label(span, &"missing definition in implementation");
1141+
} else {
1142+
err.note(&format!("infered definition: `{}`", trait_item.signature(tcx)));
11321143
}
11331144
}
11341145
err.emit();

src/libsyntax/codemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ impl CodeMap {
342342
}
343343

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

348348
let files = self.files.borrow();

src/libsyntax_pos/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ impl Span {
8080
Span { lo: BytePos(lo), hi: self.hi, expn_id: self.expn_id}
8181
}
8282

83+
/// Returns a new span representing just the start-point of this span
84+
pub fn start_point(self) -> Span {
85+
let lo = cmp::min(self.lo.0, self.hi.0 - 1);
86+
Span { lo: BytePos(lo), hi: BytePos(lo), expn_id: self.expn_id}
87+
}
88+
8389
/// Returns `self` if `self` is not the dummy span, and `other` otherwise.
8490
pub fn substitute_dummy(self, other: Span) -> Span {
8591
if self.source_equal(&DUMMY_SP) { other } else { self }

0 commit comments

Comments
 (0)