CodeSampleX

Exemple

syn 3.0.3: syn::ExprMatch

Échantillon vérifié pour cargo syn 3.0.3: syn::ExprMatch. Le contrat s'est exécuté sur rust 1 · linux alpine/x64 · docker et a réussi.

sha256:2fe4c49df2f4330addde88bdb5830f99da5a2a35a48d73bf7c5684cde2bbfd92

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux · alpine · musl x64 cargo

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-19

Cas

HOW
Objectif
verify syn::ExprMatch in pkg:cargo/syn@3.0.3
Paquets
Symboles
  • syn::ExprMatch
Créé
2026-09-17T15:23:20Z

Contrat

  1. syn::parse_str parses a basic match expression into syn::ExprMatch with match target and arms
  2. syn::parse_str parses match arms with pattern guards into syn::ExprMatch with Pat::Guard
  3. syn::parse_str parses match expressions with outer and inner attributes into syn::ExprMatch
  4. syn::parse_str parses match arms with multiple alternatives into Pat::Or
  5. syn::parse_str parses an empty match expression into syn::ExprMatch with empty arms
  6. syn::parse_str returns an error when match expression syntax is invalid

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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::ExprMatch 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::ExprMatch

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:04ccf32c4f7d8d3be4ac89d2b2e45612574275968c23778839fb90b1947ccf5e","contract":["syn::parse_str parses a basic match expression into syn::ExprMatch with match target and arms","syn::parse_str parses match arms with pattern guards into syn::ExprMatch with Pat::Guard","syn::parse_str parses match expressions with outer and inner attributes into syn::ExprMatch","syn::parse_str parses match arms with multiple alternatives into Pat::Or","syn::parse_str parses an empty match expression into syn::ExprMatch with empty arms","syn::parse_str returns an error when match expression syntax is invalid"],"goal":"verify syn::ExprMatch in pkg:cargo/syn@3.0.3","kind":"HOW","packages":["pkg:cargo/syn@3.0.3"],"schemaVersion":1,"symbols":["syn::ExprMatch"]},"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::ExprMatch"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify syn::ExprMatch in pkg:cargo/syn@3.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/syn@3.0.3"
  ],
  "symbols": [
    "syn::ExprMatch"
  ]
}
src/lib.rs
//! Clean-room verification sample for syn::ExprMatch.

pub use syn::*;
test/contract.rs
use syn::{parse_str, AttrStyle, Expr, ExprMatch, Pat};

fn main() {
    // 1. syn::parse_str parses a basic match expression into syn::ExprMatch with match target and arms
    let match_code = r#"
        match status {
            200 => "OK",
            404 => "Not Found",
            _ => "Unknown",
        }
    "#;
    let parsed_match: ExprMatch = parse_str(match_code).expect("failed to parse ExprMatch");
    assert_eq!(parsed_match.arms.len(), 3);
    if let Expr::Path(path) = &*parsed_match.expr {
        assert_eq!(path.path.segments[0].ident.to_string(), "status");
    } else {
        panic!("expected Expr::Path for match target");
    }

    // 2. syn::parse_str parses match arms with pattern guards into syn::ExprMatch with Pat::Guard
    let guarded_code = r#"
        match value {
            Some(x) if x > 0 => x,
            _ => 0,
        }
    "#;
    let parsed_match: ExprMatch = parse_str(guarded_code).expect("failed to parse guarded match");
    assert_eq!(parsed_match.arms.len(), 2);
    let first_arm = &parsed_match.arms[0];
    if let Pat::Guard(pat_guard) = &first_arm.pat {
        if let Pat::TupleStruct(inner_pat) = &*pat_guard.pat {
            assert_eq!(inner_pat.path.segments[0].ident.to_string(), "Some");
        } else {
            panic!("expected tuple struct inside guard pattern");
        }
    } else {
        panic!("expected Pat::Guard for guarded match arm");
    }

    // 3. syn::parse_str parses match expressions with outer and inner attributes into syn::ExprMatch
    let attr_code = r#"
        #[must_use]
        match flag {
            #![allow(unreachable_patterns)]
            true => 1,
            false => 0,
        }
    "#;
    let parsed_match: ExprMatch = parse_str(attr_code).expect("failed to parse match with attributes");
    assert_eq!(parsed_match.attrs.len(), 2);
    match &parsed_match.attrs[0].style {
        AttrStyle::Outer => {}
        _ => panic!("expected outer attribute"),
    }
    match &parsed_match.attrs[1].style {
        AttrStyle::Inner(_) => {}
        _ => panic!("expected inner attribute"),
    }

    // 4. syn::parse_str parses match arms with multiple alternatives into Pat::Or
    let or_code = r#"
        match num {
            1 | 2 | 3 => true,
            _ => false,
        }
    "#;
    let parsed_match: ExprMatch = parse_str(or_code).expect("failed to parse or-pattern match");
    assert_eq!(parsed_match.arms.len(), 2);
    if let Pat::Or(pat_or) = &parsed_match.arms[0].pat {
        assert_eq!(pat_or.cases.len(), 3);
    } else {
        panic!("expected Pat::Or for multi-case pattern");
    }

    // 5. syn::parse_str parses an empty match expression into syn::ExprMatch with empty arms
    let empty_code = "match val {}";
    let parsed_match: ExprMatch = parse_str(empty_code).expect("failed to parse empty match");
    assert!(parsed_match.arms.is_empty());

    // 6. syn::parse_str returns an error when match expression syntax is invalid
    let invalid_code = "match { => }";
    let parse_result = parse_str::<ExprMatch>(invalid_code);
    assert!(parse_result.is_err(), "expected syntax error for invalid match expression");

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

Seeder d'origine

anonyme