Skip to content

Commit c044791

Browse files
committed
Auto merge of #26910 - nrc:ice-lang-item, r=@huonw
2 parents 07be629 + 7fb8208 commit c044791

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/librustc/middle/fast_reject.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ pub fn simplify_type(tcx: &ty::ctxt,
7171
}
7272
ty::TyBox(_) => {
7373
// treat like we would treat `Box`
74-
let def_id = tcx.lang_items.owned_box().unwrap();
75-
Some(StructSimplifiedType(def_id))
74+
match tcx.lang_items.require_owned_box() {
75+
Ok(def_id) => Some(StructSimplifiedType(def_id)),
76+
Err(msg) => tcx.sess.fatal(&msg),
77+
}
7678
}
7779
ty::TyClosure(def_id, _) => {
7880
Some(ClosureSimplifiedType(def_id))

src/librustc/middle/lang_items.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ impl LanguageItems {
9090
}
9191
}
9292

93+
pub fn require_owned_box(&self) -> Result<ast::DefId, String> {
94+
self.require(OwnedBoxLangItem)
95+
}
96+
9397
pub fn from_builtin_kind(&self, bound: ty::BuiltinBound)
9498
-> Result<ast::DefId, String>
9599
{

src/librustc_typeck/coherence/orphan.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
7777
self.check_def_id(item, data.principal_def_id());
7878
}
7979
ty::TyBox(..) => {
80-
self.check_def_id(item, self.tcx.lang_items.owned_box().unwrap());
80+
match self.tcx.lang_items.require_owned_box() {
81+
Ok(trait_id) => self.check_def_id(item, trait_id),
82+
Err(msg) => self.tcx.sess.span_fatal(item.span, &msg),
83+
}
8184
}
8285
ty::TyChar => {
8386
self.check_primitive_impl(def_id,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we don't ICE when we are missing the owned_box lang item.
12+
13+
// error-pattern: requires `owned_box` lang_item
14+
15+
#![no_std]
16+
#![feature(lang_items, no_std, box_syntax)]
17+
18+
extern crate core;
19+
20+
fn main() {
21+
let x = box 1i32;
22+
}
23+
24+
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
25+
#[lang = "eh_personality"] extern fn eh_personality() {}
26+
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }

0 commit comments

Comments
 (0)