Skip to content

Add error file for E0152 #31957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use util::nodemap::FnvHashMap;

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;
Expand Down Expand Up @@ -158,7 +157,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for LanguageItemCollector<'a, 'tcx> {
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))
}
}
}
Expand All @@ -180,15 +179,26 @@ impl<'a, 'tcx> LanguageItemCollector<'a, '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.
Expand All @@ -205,17 +215,18 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {

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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/compile-fail/duplicate_entry_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}

Expand Down