Fix Rust agent build break on newer nightly by upgrading printf-compat#37
Fix Rust agent build break on newer nightly by upgrading printf-compat#37
printf-compat#37Conversation
Co-authored-by: chvancooten <25614522+chvancooten@users.noreply.github.com>
printf-compat
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughUpdated printf-compat dependency from 0.1.1 to 0.3.1 and modified beacon_api module to pass arguments directly to printf_compat::format instead of using as_va_list(), resolving nightly trait compilation errors. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@client-rs/src/app/coff_loader/beacon_api.rs`:
- Around line 460-464: The calls to printf_compat::format currently pass the raw
variadic VaListImpl (`args`) but the 0.3.x API expects core::ffi::VaList; update
both call sites that invoke printf_compat::format (the one using
printf_compat::output::fmt_write(&mut s) and the other similar call later) to
pass args.as_va_list() instead of args so the variadic arguments are converted
to the required core::ffi::VaList type.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
client-rs/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
client-rs/Cargo.tomlclient-rs/src/app/coff_loader/beacon_api.rs
| let bytes_written = printf_compat::format( | ||
| fmt, | ||
| args.as_va_list(), | ||
| args, | ||
| printf_compat::output::fmt_write(&mut s), | ||
| ); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
printf-compat 0.3 rust crate format function signature VaListMut
💡 Result:
In printf-compat 0.3.x, the formatter function takes core::ffi::VaList, not VaListMut:
pub unsafe fn format(
format: *const c_char,
args: core::ffi::VaList<'_>,
handler: impl FnMut(Argument<'_>) -> c_int,
) -> c_int[1]
If what you have is the Rust variadic “...” parameter (a VaListImpl), convert it to a VaList with as_va_list() and pass that to printf_compat::format:
#![feature(c_variadic)]
use core::ffi::{c_char, c_int, VaListImpl};
use printf_compat::{format, output};
unsafe extern "C" fn my_printf(fmt: *const c_char, mut ap: ...) -> c_int {
// ap is VaListImpl; convert to VaList for printf-compat:
let args = ap.as_va_list(); // -> VaList
format(fmt, args, output::discard())
}VaListImpl::as_va_list(&mut self) -> VaList<...> is the intended bridge here. [2]
Sources:
[1] printf_compat::format signature (docs.rs) (docs.rs)
[2] std::ffi::VaListImpl::as_va_list docs (doc.rust-lang.org)
Citations:
- 1: https://docs.rs/printf-compat/0.3.1/printf_compat/fn.format.html
- 2: https://doc.rust-lang.org/std/ffi/struct.VaListImpl.html?utm_source=openai
🏁 Script executed:
# Examine the beacon_api.rs file at the mentioned lines
# First, let's check the file exists and get its size
wc -l client-rs/src/app/coff_loader/beacon_api.rs
# Read the code around lines 460-464 (beacon_format_printf)
echo "=== Lines 452-477 (beacon_format_printf) ==="
sed -n '452,477p' client-rs/src/app/coff_loader/beacon_api.rs
# Read the code around lines 579 (beacon_printf)
echo "=== Lines 574-586 (beacon_printf) ==="
sed -n '574,586p' client-rs/src/app/coff_loader/beacon_api.rsRepository: chvancooten/NimPlant
Length of output: 1116
Add .as_va_list() conversion to variadic arguments.
The printf_compat::format() function in version 0.3.x requires core::ffi::VaList, not the raw variadic VaListImpl. Both call sites (lines 462 and 579) must convert args before passing it:
let bytes_written = printf_compat::format(
fmt,
args.as_va_list(),
printf_compat::output::fmt_write(&mut s),
);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@client-rs/src/app/coff_loader/beacon_api.rs` around lines 460 - 464, The
calls to printf_compat::format currently pass the raw variadic VaListImpl
(`args`) but the 0.3.x API expects core::ffi::VaList; update both call sites
that invoke printf_compat::format (the one using
printf_compat::output::fmt_write(&mut s) and the other similar call later) to
pass args.as_va_list() instead of args so the variadic arguments are converted
to the required core::ffi::VaList type.
Rust agent compilation (
python3 nimplant.py compile exe rust) was failing in Docker withprintf-compaterrors (VaArgSafetrait andVaListlifetime/API mismatches) on newer nightly toolchains. The failure path was in COFF loader printf handling used by risky-mode functionality.Dependency update (root cause)
client-rsoptional dependency:printf-compat: 0.1.1 -> 0.3.1Cargo.lockto align transitive deps required by the newer crate.API compatibility updates in COFF loader
beacon_api.rsto matchprintf-compat0.3.x API:argsdirectly toprintf_compat::format(...)args.as_va_list()usage at both call sites.Scope
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Summary by CodeRabbit