@@ -3349,7 +3349,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3349
3349
pieces_len_id,
3350
3350
rt_args_slice_ptr_id,
3351
3351
rt_args_len_id,
3352
- _fmt_placeholders_slice_ptr_id ,
3352
+ fmt_placeholders_slice_ptr_id ,
3353
3353
fmt_placeholders_len_id,
3354
3354
] if ( pieces_len, rt_args_count) == ( !0 , !0 ) => {
3355
3355
let [ pieces_len, rt_args_len, fmt_placeholders_len] = match [
@@ -3369,56 +3369,40 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3369
3369
}
3370
3370
} ;
3371
3371
3372
- // FIXME(eddyb) simplify the logic below after
3373
- // https://github.com/rust-lang/rust/pull/139131
3374
- // (~1.88) as it makes `&[rt::Placeholder]`
3375
- // constant (via promotion to 'static).
3376
-
3377
- // HACK(eddyb) this accounts for all of these:
3378
- // - `rt::Placeholder` copies into array: 2 insts each
3379
- // - `rt::UnsafeArg::new()` call: 1 inst
3380
- // - runtime args array->slice ptr cast: 1 inst
3381
- // - placeholders array->slice ptr cast: 1 inst
3382
- let extra_insts = try_rev_take ( 3 + fmt_placeholders_len * 2 ) . ok_or_else ( || {
3372
+ let prepare_args_insts = try_rev_take ( 3 ) . ok_or_else ( || {
3383
3373
FormatArgsNotRecognized (
3384
3374
"fmt::Arguments::new_v1_formatted call: ran out of instructions" . into ( ) ,
3385
3375
)
3386
3376
} ) ?;
3387
- let rt_args_slice_ptr_id = match extra_insts[ ..] {
3388
- [ .., Inst :: Bitcast ( out_id, in_id) , Inst :: Bitcast ( ..) ]
3389
- if out_id == rt_args_slice_ptr_id =>
3390
- {
3391
- in_id
3392
- }
3393
- _ => {
3394
- let mut insts = extra_insts;
3395
- insts. extend ( fmt_args_new_call_insts) ;
3396
- return Err ( FormatArgsNotRecognized ( format ! (
3397
- "fmt::Arguments::new_v1_formatted call sequence ({insts:?})" ,
3398
- ) ) ) ;
3399
- }
3400
- } ;
3401
-
3402
- // HACK(eddyb) even worse, each call made to
3403
- // `rt::Placeholder::new(...)` takes anywhere
3404
- // between 8 and 16 instructions each, due
3405
- // to `rt::Count`'s `enum` representation.
3406
- for _ in 0 ..fmt_placeholders_len {
3407
- try_rev_take ( 4 ) . and_then ( |_| {
3408
- for _ in 0 ..2 {
3409
- if let [ Inst :: Bitcast ( ..) , _] = try_rev_take ( 2 ) ?[ ..] {
3410
- try_rev_take ( 4 ) ?;
3411
- }
3377
+ let ( rt_args_slice_ptr_id, _fmt_placeholders_slice_ptr_id) =
3378
+ match prepare_args_insts[ ..] {
3379
+ [
3380
+ // HACK(eddyb) `rt::UnsafeArg::new()` call
3381
+ // (`unsafe` ZST "constructor").
3382
+ Inst :: Call ( _, _, ref rt_unsafe_arg_call_args) ,
3383
+ Inst :: Bitcast (
3384
+ rt_args_cast_out_id,
3385
+ rt_args_cast_in_id,
3386
+ ) ,
3387
+ Inst :: Bitcast (
3388
+ placeholders_cast_out_id,
3389
+ placeholders_cast_in_id,
3390
+ ) ,
3391
+ ] if rt_unsafe_arg_call_args. is_empty ( )
3392
+ && rt_args_cast_out_id == rt_args_slice_ptr_id
3393
+ && placeholders_cast_out_id
3394
+ == fmt_placeholders_slice_ptr_id =>
3395
+ {
3396
+ ( rt_args_cast_in_id, placeholders_cast_in_id)
3412
3397
}
3413
- Some ( ( ) )
3414
- } )
3415
- . ok_or_else ( || {
3416
- FormatArgsNotRecognized (
3417
- "fmt::rt::Placeholder::new call: ran out of instructions"
3418
- . into ( ) ,
3419
- )
3420
- } ) ?;
3421
- }
3398
+ _ => {
3399
+ let mut insts = prepare_args_insts;
3400
+ insts. extend ( fmt_args_new_call_insts) ;
3401
+ return Err ( FormatArgsNotRecognized ( format ! (
3402
+ "fmt::Arguments::new_v1_formatted call sequence ({insts:?})" ,
3403
+ ) ) ) ;
3404
+ }
3405
+ } ;
3422
3406
3423
3407
decoded_format_args
3424
3408
. has_unknown_fmt_placeholder_to_args_mapping =
@@ -3707,7 +3691,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3707
3691
let force_warn = |span, msg| -> rustc_errors:: Diag < ' _ , ( ) > {
3708
3692
rustc_errors:: Diag :: new (
3709
3693
self . tcx . dcx ( ) ,
3710
- rustc_errors:: Level :: ForceWarning ( None ) ,
3694
+ rustc_errors:: Level :: ForceWarning ,
3711
3695
msg,
3712
3696
)
3713
3697
. with_span ( span)
0 commit comments