Repository navigation
Conversation
Quest-Claim: ae01a44aeb894132
A `pub` constant of an integer, `bool`, `char`, or `&str` is a Go `const`; any other is a function returning a fresh value at each call, as each use of Rust's is. A static is one Go variable that translated code and Go callers share, assigned in an `init` when its value reaches back to it. Upper-case names are camel cased per word (`MAX_LEN` as `MaxLen`). A `static mut`, a static with interior mutability, a foreign or thread-local static, a generic associated constant, and a reference into part of a static stay refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Summary
Finishes quest/m4/go/consts.md, planned in moq-dev/rust2#630 from moq-dev/rust2#614's follow-ups. rust2-go now exports every
pubconstant and static, associated constants included, instead of refusing each at its span, so a crate that has any translates with no config.const_eval_poly) and lowered throughlower/consts.rs, the same path an operand's value takes.bool,char, or&strconstant becomes a Goconst(const MaxLen = uint8(200)). A&strbecomes an untyped Go string.func Origin() TalliesTotal), so each use gets a fresh value.&Var.Letters[1:4]), so it aliases the static as Rust's does.init(), because Go rejects a variable whose initializer refers to it. Nested allocations inside a static are read as constant memory.MAX_LENbecomesMaxLen,Counter::MAXbecomesCounterMax. The owner path keeps moq-dev/rust2#614's rule.static mut, a static of a type with interior mutability (atomics), a thread-local or foreign static, an associated constant of a generic type, and a reference into part of a static (&S.1).static TABLE: &[u16]. Before, only&strwas read from memory.Fx::newbuilds the lowering context, and a constant or static root lowers in an empty MIR body. This is how a root reachesconst_valueoutside any function. Statics have no cross-crate MIR to borrow a body from.Choices made without asking
var. The quest recommended avar. The OpenAI review on #630 asked that a constant stay a fresh value at each use while a static is shared storage. With avar, one Go caller'sitems.Origin.Sum = 9, or a method called on&items.Origin, would change what later Go callers read. A function makes that impossible. The cost is call syntax:items.Origin().charcounts as a Go basic type beside integers,bool, and&str:const Letter = rune(233).Freezeis refused outright. No interior-mutable type translates today, and a static one is alwaysSync, meaning atomics or locks. So "interior mutability translation refuses" reads as every!Freezestatic.Tests
fixtures/itemsgainspubconstants of every basic type,i64::MINincluded, plus non-basic constants and associated ones. It also gainspubstatics: a struct, a&[u16], a&str, an array, and a slice of part of another static. Two private statics form a cycle, and a dependency crate contributes a constant and a static.tests/exports/main.goreads the exports from Go, andfixtures.rscompares its output with native values.const, so the build fails if any of them is not a Go constant.Origin()andCountStart()results and shows the next call is fresh.Hitsand shows translatedRunreads the write.Lettersand showsTailsees it.fixtures/rejectloses itspub constcase and gains each refusal above.Public API
What a translation exports. Crates with
pubconstants or statics now translate. Before, each was a compile error. Nothing that translated before changes.Caused by
None: moq-dev/rust2#614 refused these on purpose as new codegen.
Validation
just cipasses on 973b3d5.Suggested follow-ups
const SECOND: &u8 = &HALVES.1), as&Var.F1. It is refused, as a second reference into constant memory at another offset already is. Recommendation: drop. No consumer needs it, and quest/m4/go/coverage.md already tracks the constant-memory case.Models
Size: M
Implementer: Claude Code, claude-opus-5-5, high effort
Review
Rewritten by
quest reviewafter each round.(Written by Claude Opus 5.5 with high effort)
🤖 Generated with Claude Code