From 37e59b9239095bf8b0e0d1ae9952707593395956 Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Thu, 14 Apr 2016 13:25:14 -0700 Subject: [PATCH] Accommodate the case where dup lang items are entirely external. Fixes #32961 --- src/librustc/middle/lang_items.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 86531ced8df..83929c17ca3 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -189,13 +189,19 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { match self.items.items[item_index] { Some(original_def_id) if original_def_id != item_def_id => { let cstore = &self.session.cstore; - 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)); + let name = LanguageItems::item_name(item_index); + let mut err = match self.ast_map.span_if_local(item_def_id) { + Some(span) => struct_span_err!( + self.session, + span, + E0152, + "duplicate lang item found: `{}`.", + name), + None => self.session.struct_err(&format!( + "duplicate lang item in crate `{}`: `{}`.", + cstore.crate_name(item_def_id.krate), + name)), + }; if let Some(span) = self.ast_map.span_if_local(original_def_id) { span_note!(&mut err, span, "first defined here.");