CodeSampleX

Пример

syn 3.0.3: syn::File

Проверенный пример — cargo syn 3.0.3: syn::File. Контракт выполнен на rust 1 · linux alpine/x64 · docker и пройден: syn::parse_file parses Rust source…

sha256:4ed38959bcb026f9b3a249da383175a068036cf68a173180385106861691003b

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux · alpine · musl x64 cargo

Среды запусков проверки

Окружение Контракт Этапы Запуск
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-17

Кейс

HOW
Цель
verify syn::File in pkg:cargo/syn@3.0.3
Пакеты
Символы
  • syn::File
Создан
2026-09-17T03:24:02Z

Контракт

  1. syn::parse_file parses Rust source containing a shebang into syn::File with shebang field populated
  2. syn::parse_file extracts inner attributes into attrs on syn::File
  3. syn::parse_file parses top-level declarations into items on syn::File
  4. syn::parse_str parses Rust source without shebang directly into syn::File
  5. syn::parse_file parses an empty source into syn::File with empty attrs and items
  6. syn::parse_file returns an error when Rust syntax is invalid

Файлы

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

Cargo.lock
# 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 = "sample-syn"
version = "1.0.0"
dependencies = [
 "syn",
]

[[package]]
name = "syn"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab72a15cf68d77cb0987d3684aa8a45c5ef827e8cb49ee2f30bfd7ba2feb519f"
Cargo.toml
[package]
name = "sample-syn"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
syn = { version = "=3.0.3", features = ["full", "extra-traits"] }

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
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 syn::File in pkg:cargo/syn@3.0.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/syn@3.0.3
Demonstrate these symbols/APIs:
  - syn::File

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.
csx.json
{"case":{"caseId":"case:sha256:aaee1188e85ea4c0aa08bbd05e28c488cd19e9ea0bf4f7dc9e4502d983f07a6a","contract":["syn::parse_file parses Rust source containing a shebang into syn::File with shebang field populated","syn::parse_file extracts inner attributes into attrs on syn::File","syn::parse_file parses top-level declarations into items on syn::File","syn::parse_str parses Rust source without shebang directly into syn::File","syn::parse_file parses an empty source into syn::File with empty attrs and items","syn::parse_file returns an error when Rust syntax is invalid"],"goal":"verify syn::File in pkg:cargo/syn@3.0.3","kind":"HOW","packages":["pkg:cargo/syn@3.0.3"],"schemaVersion":1,"symbols":["syn::File"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/syn@3.0.3"],"schemaVersion":1,"subject":"pkg:cargo/syn@3.0.3","symbols":["syn::File"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify syn::File in pkg:cargo/syn@3.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/syn@3.0.3"
  ],
  "symbols": [
    "syn::File"
  ]
}
src/lib.rs
//! Clean-room verification sample for syn::File.

pub use syn::*;
test/contract.rs
use syn::{parse_file, parse_str, File, Item};

fn main() {
    // 1. syn::parse_file parses Rust source containing a shebang into syn::File with shebang field populated
    let source_with_shebang = "#!/usr/bin/env rustx\nfn main() {}\n";
    let file_shebang: File = parse_file(source_with_shebang).expect("failed to parse file with shebang");
    assert_eq!(file_shebang.shebang.as_deref(), Some("#!/usr/bin/env rustx"));
    assert_eq!(file_shebang.items.len(), 1);

    // 2. syn::parse_file extracts inner attributes into attrs on syn::File
    let source_with_attrs = "#![allow(dead_code)]\n#![warn(missing_docs)]\nfn dummy() {}\n";
    let file_attrs: File = parse_file(source_with_attrs).expect("failed to parse file with inner attributes");
    assert!(file_attrs.shebang.is_none());
    assert_eq!(file_attrs.attrs.len(), 2);

    // 3. syn::parse_file parses top-level declarations into items on syn::File
    let source_items = r#"
        struct Point {
            x: f64,
            y: f64,
        }

        impl Point {
            fn origin() -> Self {
                Point { x: 0.0, y: 0.0 }
            }
        }

        fn compute(p: &Point) -> f64 {
            p.x + p.y
        }
    "#;
    let file_items: File = parse_file(source_items).expect("failed to parse file with multiple items");
    assert_eq!(file_items.items.len(), 3);
    match &file_items.items[0] {
        Item::Struct(s) => assert_eq!(s.ident, "Point"),
        _ => panic!("expected Item::Struct"),
    }
    match &file_items.items[1] {
        Item::Impl(_) => {}
        _ => panic!("expected Item::Impl"),
    }
    match &file_items.items[2] {
        Item::Fn(f) => assert_eq!(f.sig.ident, "compute"),
        _ => panic!("expected Item::Fn"),
    }

    // 4. syn::parse_str parses Rust source without shebang directly into syn::File
    let source_simple = "const BUFFER_SIZE: usize = 1024;";
    let file_parsed: File = parse_str(source_simple).expect("failed to parse_str into syn::File");
    assert!(file_parsed.shebang.is_none());
    assert_eq!(file_parsed.items.len(), 1);
    match &file_parsed.items[0] {
        Item::Const(c) => assert_eq!(c.ident, "BUFFER_SIZE"),
        _ => panic!("expected Item::Const"),
    }

    // 5. syn::parse_file parses an empty source into syn::File with empty attrs and items
    let empty_source = "";
    let file_empty: File = parse_file(empty_source).expect("failed to parse empty file");
    assert!(file_empty.shebang.is_none());
    assert!(file_empty.attrs.is_empty());
    assert!(file_empty.items.is_empty());

    // 6. syn::parse_file returns an error when Rust syntax is invalid
    let invalid_source = "fn invalid syntax {[[[";
    let parse_result = parse_file(invalid_source);
    assert!(parse_result.is_err(), "expected syntax error on invalid Rust source");

    println!("All syn::File contract assertions passed successfully.");
}

Исходный сидер

аноним