File tree 3 files changed +26
-18
lines changed
3 files changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -318,18 +318,20 @@ fn f() {
318
318
319
319
expect ! [ [ r#"
320
320
fn f() {
321
- $crate::panicking::panic_fmt(
322
- builtin#lang(Arguments::new_v1_formatted)(
323
- &[
324
- "cc",
325
- ],
326
- &[],
327
- &[],
328
- unsafe {
329
- builtin#lang(UnsafeArg::new)()
330
- },
331
- ),
332
- );
321
+ {
322
+ $crate::panicking::panic_fmt(
323
+ builtin#lang(Arguments::new_v1_formatted)(
324
+ &[
325
+ "cc",
326
+ ],
327
+ &[],
328
+ &[],
329
+ unsafe {
330
+ builtin#lang(UnsafeArg::new)()
331
+ },
332
+ ),
333
+ );
334
+ };
333
335
}"# ] ]
334
336
. assert_eq ( & body. pretty_print ( & db, def) )
335
337
}
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ impl Evaluator<'_> {
49
49
if self . not_special_fn_cache . borrow ( ) . contains ( & def) {
50
50
return Ok ( false ) ;
51
51
}
52
+
52
53
let function_data = self . db . function_data ( def) ;
53
54
let is_intrinsic = match & function_data. abi {
54
55
Some ( abi) => * abi == Interned :: new_str ( "rust-intrinsic" ) ,
@@ -311,16 +312,20 @@ impl Evaluator<'_> {
311
312
312
313
fn detect_lang_function ( & self , def : FunctionId ) -> Option < LangItem > {
313
314
use LangItem :: * ;
314
- let candidate = self . db . lang_attr ( def. into ( ) ) ?;
315
+ let attrs = self . db . attrs ( def. into ( ) ) ;
316
+
317
+ if attrs. by_key ( "rustc_const_panic_str" ) . exists ( ) {
318
+ // `#[rustc_const_panic_str]` is treated like `lang = "begin_panic"` by rustc CTFE.
319
+ return Some ( LangItem :: BeginPanic ) ;
320
+ }
321
+
322
+ let candidate = attrs. by_key ( "lang" ) . string_value ( ) . and_then ( LangItem :: from_str) ?;
315
323
// We want to execute these functions with special logic
316
324
// `PanicFmt` is not detected here as it's redirected later.
317
325
if [ BeginPanic , SliceLen , DropInPlace ] . contains ( & candidate) {
318
326
return Some ( candidate) ;
319
327
}
320
- if self . db . attrs ( def. into ( ) ) . by_key ( "rustc_const_panic_str" ) . exists ( ) {
321
- // `#[rustc_const_panic_str]` is treated like `lang = "begin_panic"` by rustc CTFE.
322
- return Some ( LangItem :: BeginPanic ) ;
323
- }
328
+
324
329
None
325
330
}
326
331
Original file line number Diff line number Diff line change @@ -1378,8 +1378,9 @@ mod panic {
1378
1378
// Special-case the single-argument case for const_panic.
1379
1379
( "{}" , $arg: expr $( , ) ?) => ( {
1380
1380
#[ rustc_const_panic_str] // enforce a &&str argument in const-check and hook this by const-eval
1381
+ #[ rustc_do_not_const_check] // hooked by const-eval
1381
1382
const fn panic_cold_display < T : $crate:: fmt:: Display > ( arg : & T ) -> ! {
1382
- loop { }
1383
+ $crate :: panicking :: panic_display ( arg )
1383
1384
}
1384
1385
panic_cold_display ( & $arg) ;
1385
1386
} ) ,
You can’t perform that action at this time.
0 commit comments