Skip to content

Commit 837efd1

Browse files
committed
feat(rationale): Step through why this needs to be in rustc
1 parent 717bacd commit 837efd1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

text/3503-frontmatter.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,26 @@ When choosing the syntax, our care-abouts are
168168
- Leave the door open in case we want to reuse the syntax for embedded lockfiles
169169
- Leave the door open for single-file `lib`s
170170

171+
### Why add to Rust syntax, rather than letting Cargo handle it
172+
173+
The most naive way for cargo to handle this is for cargo to strip the manifest, write the Rust file to a temporary file, and compile that.
174+
This is what has traditionally been done with various iterations of "cargo script".
175+
176+
This provides a second-class experience which runs counter to one of the design goals
177+
- Error messages, `cargo metadata`, etc point to the stripped source with an "odd" path, rather than the real source
178+
- Every tool that plans to support it would need to be updated to do stripping (`cargo fmt`, `cargo clippy`, etc)
179+
180+
A key part in there is "plan to support".
181+
We'd need to build up buy-in for tools to be supporting a Cargo-only syntax.
182+
This becomes more difficult when the tool in question tries to be Cargo-agnostic.
183+
By having Cargo-agnostic external tool syntax in Rust, this mostly becomes transparent.
184+
185+
We could build a special relationship with rustc to support this.
186+
For example, rustdoc passes code to rustc on stdin and sets `UNSTABLE_RUSTDOC_TEST_PATH` and `UNSTABLE_RUSTDOC_TEST_LINE` to control how errors are rendered.
187+
We could then also special case the messages inside of cargo.
188+
This both adds a major support burden to keep this house of lies standing but still falls short when it comes to tooling support.
189+
Now every tool that wants to support the Cargo-only syntax has to build their own house of lies.
190+
171191
### Frontmatter
172192

173193
This proposed syntax builds off of the precedence of Rust having syntax specialized for an external tool

0 commit comments

Comments
 (0)