Skip to content

Commit 9f3ca33

Browse files
authored
Rollup merge of #51921 - japaric:panic-impl-error, r=nagisa
improve the error message when `#[panic_implementation]` is missing closes #51341 r? @nagisa cc @phil-opp
2 parents 7d8831e + ee52862 commit 9f3ca33

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/librustc/middle/weak_lang_items.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ fn verify<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
112112
if missing.contains(&lang_items::$item) &&
113113
!whitelisted(tcx, lang_items::$item) &&
114114
items.$name().is_none() {
115-
tcx.sess.err(&format!("language item required, but not found: `{}`",
116-
stringify!($name)));
117-
115+
if lang_items::$item == lang_items::PanicImplLangItem {
116+
tcx.sess.err(&format!("`#[panic_implementation]` function required, \
117+
but not found"));
118+
} else {
119+
tcx.sess.err(&format!("language item required, but not found: `{}`",
120+
stringify!($name)));
121+
}
118122
}
119123
)*
120124
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 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+
// error-pattern: `#[panic_implementation]` function required, but not found
12+
13+
#![feature(lang_items)]
14+
#![no_main]
15+
#![no_std]
16+
17+
#[lang = "eh_personality"]
18+
fn eh() {}

src/test/compile-fail/weak-lang-item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
// aux-build:weak-lang-items.rs
12-
// error-pattern: language item required, but not found: `panic_impl`
12+
// error-pattern: `#[panic_implementation]` function required, but not found
1313
// error-pattern: language item required, but not found: `eh_personality`
1414
// ignore-wasm32-bare compiled with panic=abort, personality not required
1515

0 commit comments

Comments
 (0)