提交 81e03236 编写于 作者: B bors

Auto merge of #31957 - GuillaumeGomez:error_display, r=brson

Add error file for E0152

It completes #31818.

However it is not complete yet:
 * test will need to be updated
 * the file name displayed is a bit too unclear.

I'm not sure yet what's the "correct" file name to display. If anyone has an idea on this, it'd be very appreciated.

r? @brson
......@@ -32,7 +32,6 @@
use syntax::ast;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{DUMMY_SP, Span};
use syntax::parse::token::InternedString;
use rustc_front::intravisit::Visitor;
use rustc_front::hir;
......@@ -158,7 +157,7 @@ fn visit_item(&mut self, item: &hir::Item) {
let item_index = self.item_refs.get(&value[..]).cloned();
if let Some(item_index) = item_index {
self.collect_item(item_index, self.ast_map.local_def_id(item.id), item.span)
self.collect_item(item_index, self.ast_map.local_def_id(item.id))
}
}
}
......@@ -180,15 +179,26 @@ pub fn new(session: &'a Session, ast_map: &'a hir_map::Map<'tcx>)
}
pub fn collect_item(&mut self, item_index: usize,
item_def_id: DefId, span: Span) {
item_def_id: DefId) {
// Check for duplicates.
match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => {
let cstore = &self.session.cstore;
span_err!(self.session, span, E0152,
"duplicate entry for `{}`, first definition found in `{}`",
LanguageItems::item_name(item_index),
cstore.crate_name(item_def_id.krate));
let span = self.ast_map.span_if_local(item_def_id)
.expect("we should have found local duplicate earlier");
let mut err = struct_span_err!(self.session,
span,
E0152,
"duplicate lang item found: `{}`.",
LanguageItems::item_name(item_index));
if let Some(span) = self.ast_map.span_if_local(original_def_id) {
span_note!(&mut err, span,
"first defined here.");
} else {
err.note(&format!("first defined in crate `{}`.",
cstore.crate_name(original_def_id.krate)));
}
err.emit();
}
_ => {
// OK.
......@@ -205,17 +215,18 @@ pub fn collect_local_language_items(&mut self, krate: &hir::Crate) {
pub fn collect_external_language_items(&mut self) {
let cstore = &self.session.cstore;
for cnum in cstore.crates() {
for (index, item_index) in cstore.lang_items(cnum) {
let def_id = DefId { krate: cnum, index: index };
self.collect_item(item_index, def_id, DUMMY_SP);
self.collect_item(item_index, def_id);
}
}
}
pub fn collect(&mut self, krate: &hir::Crate) {
self.collect_local_language_items(krate);
self.collect_external_language_items();
self.collect_local_language_items(krate);
}
}
......
......@@ -8,14 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test for issue #31788
// note-pattern: first defined in crate `std`.
// error-pattern: duplicate entry for `panic_fmt`, first definition found in `std`
// Test for issue #31788 and E0152
#![feature(lang_items)]
#[lang = "panic_fmt"]
fn panic_fmt() -> ! {
//~^ ERROR: duplicate lang item found: `panic_fmt`.
loop {}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册