File tree Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Expand file tree Collapse file tree 3 files changed +26
-18
lines changed Original file line number Diff line number Diff line change @@ -318,18 +318,20 @@ fn f() {
318318
319319 expect ! [ [ r#"
320320 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+ };
333335 }"# ] ]
334336 . assert_eq ( & body. pretty_print ( & db, def) )
335337}
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ impl Evaluator<'_> {
4949 if self . not_special_fn_cache . borrow ( ) . contains ( & def) {
5050 return Ok ( false ) ;
5151 }
52+
5253 let function_data = self . db . function_data ( def) ;
5354 let is_intrinsic = match & function_data. abi {
5455 Some ( abi) => * abi == Interned :: new_str ( "rust-intrinsic" ) ,
@@ -311,16 +312,20 @@ impl Evaluator<'_> {
311312
312313 fn detect_lang_function ( & self , def : FunctionId ) -> Option < LangItem > {
313314 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) ?;
315323 // We want to execute these functions with special logic
316324 // `PanicFmt` is not detected here as it's redirected later.
317325 if [ BeginPanic , SliceLen , DropInPlace ] . contains ( & candidate) {
318326 return Some ( candidate) ;
319327 }
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+
324329 None
325330 }
326331
Original file line number Diff line number Diff line change @@ -1378,8 +1378,9 @@ mod panic {
13781378 // Special-case the single-argument case for const_panic.
13791379 ( "{}" , $arg: expr $( , ) ?) => ( {
13801380 #[ 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
13811382 const fn panic_cold_display < T : $crate:: fmt:: Display > ( arg : & T ) -> ! {
1382- loop { }
1383+ $crate :: panicking :: panic_display ( arg )
13831384 }
13841385 panic_cold_display ( & $arg) ;
13851386 } ) ,
You can’t perform that action at this time.
0 commit comments