Skip to content

fix(printf): printf -v locale binds run the sv_locale funnel (Refs #3009) - #3057

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3009-printf-v-locale-warning
Nov 8, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3009-printf-v-locale-warning

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #3009 — UNVERIFIED-BY-CAPTAIN(车道自验,待队长中央复核)

症状

printf -v LC_ALL de_DE.UTF-8; echo ok:GNU 发 stderr 警告
warning: setlocale: LC_ALL: cannot change locale (de_DE.UTF-8): No such file or directory
(stdout ok,rc=0),rubash 静默。普通赋值 / declare / export / readonly /
read / for / local / tempenv 通道两边都警告——只有 printf -v 旁路。

根因(GNU 锚点)

修法

  • 新增 note_printf_locale_bind:操作数是 locale 家族名时,先
    sync_shell_assignment_process_env 镜像(与 declare 等通道同形),再调
    共享漏斗 locale_assignment_warning(operand, env_vars),警告以 printf
    的 diagnostic_prefix 写出。
  • assign_printf_output 三个成功存储出口(nameref 空 cell 臂、数组元素
    臂、标量臂)各调一次,键一律用操作数原名:经 nameref 写 LC_ALL、
    LC_ALL[0] 元素绑定都与 GNU 一样静默;失败出口(readonly / bad
    subscript)不调。
  • 未碰 src/lexer/continuation.rs、docs/api-ledger.md;printf.rs 内
    Residual diagnostic_prefix copies still pair frame line with top-level script name (printf/set/declare/setattr/kill/alias/help/shift/exit/shopt) #3048 登记的 diagnostic_prefix 残余拷贝未顺带转换(不在本单面内)。

本 PR 删除了什么

无删除。净行数:+259/−0(src/builtins/printf.rs +40、
tests/issue3009_printf_v_locale_warning.rs +219)。

车道自验(基底 e8a3d01)

  • 回归钉 8 格:基底(钉移植到 base worktree)3 passed / 5 failed
    ——败的恰为 5 个 printf 警告细胞;修后 8 passed / 0 failed。
  • GNU 对照探针 22 格(printf -v / 普通赋值 / declare / export / readonly /
    local / read / tempenv / for / 算术 × 存在与不存在的 locale,含 nameref、
    %n、元素、连绑丢后缀诸形):修后与 GNU 5.3.20 逐格 diff 只剩 2 格
    修前既存、本单面外的差异(算术赋值旁路、for 循环双警告),已在车道
    REPORT 里列为残余面上报;printf 全部格逐字节一致。
  • 全量 lib 双边逐数一致:修后树与基底 worktree 均为 1197 passed /
    0 failed / 4 ignored
    。
  • 邻茎全绿:issue1692 5/0、issue1531 1/0、issue2979 11/0、issue1870 5/0、
    issue2965 14/0。
  • RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0;
    hygiene clean;改动文件 rustfmt --check 过;无 CR。

车道 REPORT:~/workspace/fix-3009/REPORT.md(含三条残余面的探针证据)。

…efs #3009)

GNU printf.def PRETURN runs builtin_bind_variable + stupidly_hack_special_variables(vname), so a bad locale name bound via printf -v warns exactly like an assignment (locale.c set_locale_var). 8 cells in the rubash#1692 harness shape: 5 printf warning cells, mixed-channel and declare/plain control cells, nameref/%n/array-element silent guards. Fail-first on base e8a3d01: 3 passed / 5 failed (the 5 printf cells).
assign_printf_output wrote the VarTable directly and re-implemented only part of bind_variable's consequences (nameref resolution, readonly, att conversion, sv_path flush) — sv_locale was missing, so printf -v LC_ALL <bad> stayed silent where GNU warns.

GNU anchors: printf.def PRETURN (builtin_bind_variable + stupidly_hack_special_variables keyed on the literal -v operand name), variables.c:6269 sv_locale, locale.c:194 set_locale_var, warnings at locale.c:226/228 and 301/303.

Fix: note_printf_locale_bind runs, at each successful store exit of assign_printf_output, the same pair every other bind channel runs — sync_shell_assignment_process_env (rubash#1531 mirror) + the shared crate::locale::locale_assignment_warning funnel (rubash#1692) — keyed on the operand name as written, so a nameref bind into LC_ALL and an LC_ALL[0] element bind stay silent exactly like GNU. printf.rs net +40 lines.
@caomengxuan666
caomengxuan666 merged commit 963f8a3 into master Nov 8, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant