Ejemplo
quote 1.0.47: quote::quote
Muestra verificada para cargo quote 1.0.47: quote::quote. El contrato se ejecutó en rust 1 · linux alpine/x64 · docker y pasó.
sha256:dac7ab6a545c2d3b96074b7a5554cc962745bb9c79559c6748fe25961257720b
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
linux · musl x64 cargo
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-09-14 |
Caso
HOW- Objetivo
- verify quote::quote in pkg:cargo/quote@1.0.47
- Paquetes
- Símbolos
-
- quote::quote
- Creado
- 2026-09-14T07:48:15Z
Contrato
- quote::quote! produces a TokenStream representing valid Rust syntax
- quote::quote! interpolates variables and expressions using hash syntax
- quote::quote! supports repeated sequences with repetition syntax and separators
- quote::quote! composably nests TokenStreams produced by other quote! invocations
- quote::quote! generates an empty TokenStream when given an empty token body
Archivos
- Cargo.lock
- Cargo.toml
- NOTES.md
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Código fuente
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "quote-verify"
version = "0.1.0"
dependencies = [
"quote",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[package]
name = "quote-verify"
version = "0.1.0"
edition = "2021"
publish = false
[lib]
path = "src/lib.rs"
[[bin]]
name = "contract"
path = "test/contract.rs"
[dependencies]
quote = "=1.0.47"
# CSX Sample Notes: `quote::quote` Macro Quasiquoting, Variable Interpolation, and Repetition
## Search Known Solution Result
- `search_known_solution` returned `NO_SAFE_MATCH` for `quote::quote` in `pkg:cargo/quote@1.0.47`.
- **Why this sample is distinct**: Focuses specifically on the macro `quote::quote!` syntax contracts: generating `TokenStream` instances from Rust tokens, variable and literal interpolation via `#variable`, repetition patterns with separators (`#( ... ),*`), nesting TokenStreams produced by other `quote!` invocations, and handling empty token streams.
## What a Model Would Have Written Instead
A model might attempt manual string formatting or string concatenation to generate Rust code instead of leveraging the `quote!` macro, failing to produce a structured `TokenStream` and losing compiler span and hygiene information. Alternatively, models often misformat repetition syntax by omitting outer delimiters or improper placement of separators.
## How the Wrong Version Fails
String concatenation produces plain strings rather than `proc_macro2::TokenStream`, which cannot be directly emitted by procedural macro derive functions without re-parsing. Invalid repetition syntax causes macro expansion errors during compilation.
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify quote::quote in pkg:cargo/quote@1.0.47
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/quote@1.0.47
Demonstrate these symbols/APIs:
- quote::quote
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:7da83a66d1dd86ebba6777537fb96927b4731d02bc8965255b920b1bb5b72167","contract":["quote::quote! produces a TokenStream representing valid Rust syntax","quote::quote! interpolates variables and expressions using hash syntax","quote::quote! supports repeated sequences with repetition syntax and separators","quote::quote! composably nests TokenStreams produced by other quote! invocations","quote::quote! generates an empty TokenStream when given an empty token body"],"goal":"verify quote::quote in pkg:cargo/quote@1.0.47","kind":"HOW","packages":["pkg:cargo/quote@1.0.47"],"schemaVersion":1,"symbols":["quote::quote"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/quote@1.0.47"],"schemaVersion":1,"subject":"pkg:cargo/quote@1.0.47","symbols":["quote::quote"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify quote::quote in pkg:cargo/quote@1.0.47",
"kind": "HOW",
"packages": [
"pkg:cargo/quote@1.0.47"
],
"symbols": [
"quote::quote"
]
}
use quote::{format_ident, quote};
/// Generates a simple function TokenStream using quote!.
pub fn generate_function(fn_name: &str, return_val: i32) -> String {
let name = format_ident!("{}", fn_name);
let tokens = quote! {
fn #name() -> i32 {
#return_val
}
};
tokens.to_string()
}
/// Demonstrates quote! variable interpolation with primitive types and identifiers.
pub fn generate_variable_binding(var_name: &str, value: i64) -> String {
let var = format_ident!("{}", var_name);
let tokens = quote! {
let #var = #value;
};
tokens.to_string()
}
/// Demonstrates quote! repetition syntax `#( ... ),*` over an iterable sequence.
pub fn generate_vector_literal(items: &[i32]) -> String {
let tokens = quote! {
vec![#( #items ),*]
};
tokens.to_string()
}
/// Demonstrates quote! composing nested TokenStreams produced by quote!.
pub fn generate_nested_block(inner_code: &str) -> String {
let inner_ident = format_ident!("{}", inner_code);
let inner = quote! {
#inner_ident();
};
let outer = quote! {
if true {
#inner
}
};
outer.to_string()
}
/// Demonstrates quote! generating an empty TokenStream.
pub fn generate_empty() -> String {
let empty = quote! {};
empty.to_string()
}
use quote::{format_ident, quote};
use quote_verify::{
generate_empty, generate_function, generate_nested_block, generate_variable_binding,
generate_vector_literal,
};
fn main() {
// 1. quote::quote! produces a TokenStream representing valid Rust syntax
let fn_str = generate_function("compute_result", 100);
assert!(
fn_str.contains("fn compute_result () -> i32"),
"must contain function signature, got: {fn_str}"
);
assert!(
fn_str.contains("100"),
"must contain return value 100, got: {fn_str}"
);
// 2. quote::quote! interpolates variables and expressions using hash syntax
let binding_str = generate_variable_binding("counter", 42);
assert_eq!(
binding_str, "let counter = 42i64 ;",
"must interpolate variable name and integer literal with type suffix"
);
let id = format_ident!("greeting");
let msg = "hello world";
let direct_tokens = quote! {
let #id: &str = #msg;
};
assert_eq!(
direct_tokens.to_string(),
"let greeting : & str = \"hello world\" ;"
);
// 3. quote::quote! supports repeated sequences with repetition syntax and separators
let numbers = vec![10i32, 20i32, 30i32];
let vec_str = generate_vector_literal(&numbers);
assert_eq!(
vec_str, "vec ! [10i32 , 20i32 , 30i32]",
"must format repeated tokens separated by commas"
);
let ids = vec![format_ident!("a"), format_ident!("b")];
let struct_tokens = quote! {
struct Fields {
#(pub #ids: usize,)*
}
};
assert_eq!(
struct_tokens.to_string(),
"struct Fields { pub a : usize , pub b : usize , }"
);
// 4. quote::quote! composably nests TokenStreams produced by other quote! invocations
let nested_str = generate_nested_block("cleanup");
assert_eq!(
nested_str, "if true { cleanup () ; }",
"must nest inner TokenStream into outer quote! expression"
);
// 5. quote::quote! generates an empty TokenStream when given an empty token body
let empty_tokens = quote! {};
assert_eq!(empty_tokens.to_string(), "");
assert!(empty_tokens.is_empty(), "empty quote! must be empty");
let empty_str = generate_empty();
assert_eq!(empty_str, "");
println!("All quote::quote contract assertions passed.");
}
Seeder de origen
anónimo