Repository navigation
fix(printf): printf -v locale binds run the sv_locale funnel (Refs #3009) - #3057
Merged
Merged
Conversation
…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.
This was referenced Nov 8, 2026
caomengxuan666
marked this pull request as ready for review
November 8, 2026 02:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 锚点)
builtin_bind_variable (vname, ...)后调stupidly_hack_special_variables (vname)——特殊变量后果按 -v 操作数原名 触发,不按 nameref 解析后的目标名。
sv_locale→ locale.c:194set_locale_var:LC_ALL 非空做真实 setlocale 尝试,失败在 locale.c:226/228 警告;类别变量仅 LC_ALL
为空时尝试,失败在 locale.c:301/303 警告(值取
get_locale_var优先级读);LANG 走
set_lang,永不警告。crate::locale::locale_assignment_warning)与其他通道都已接好;只有 printf 自带的
assign_printf_output(src/builtins/printf.rs)直写 VarTable,只手工补了 bind 的部分后果
(nameref 解析、readonly/noassign、att 转换、sv_path flush),漏了
sv_locale 一族:process-env 镜像(LC_COLLATE: plain (unexported) assignment does not re-collate glob order or [[ < ]] (#1512 follow-up) #1531 后果)与 setlocale 尝试+警告
([bug] Missing setlocale warning for invalid LC_ALL (startup env and assignment) #1692 后果)都没跑。与 printf: remaining locale faces (byte_mode, \u gate, decimal_point) read the process env, not the variable-table guard #2979 同属 funnel 旁路写家族,本单是警告面残余。
修法
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 / badsubscript)不调。
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)
——败的恰为 5 个 printf 警告细胞;修后 8 passed / 0 failed。
local / read / tempenv / for / 算术 × 存在与不存在的 locale,含 nameref、
%n、元素、连绑丢后缀诸形):修后与 GNU 5.3.20 逐格 diff 只剩 2 格
修前既存、本单面外的差异(算术赋值旁路、for 循环双警告),已在车道
REPORT 里列为残余面上报;printf 全部格逐字节一致。
0 failed / 4 ignored。
issue2965 14/0。
RUSTFLAGS="-D warnings" cargo check --locked --lib --binsrc=0;hygiene clean;改动文件 rustfmt --check 过;无 CR。
车道 REPORT:
~/workspace/fix-3009/REPORT.md(含三条残余面的探针证据)。