CodeSampleX

サンプル

syn 3.0.3: syn::ExprMethodCall

検証済みサンプル — cargo syn 3.0.3: syn::ExprMethodCall. rust 1 · linux alpine/x64 · docker で contract を実行し、成功しました: syn::parse_str parses a basic method call into…

sha256:106ad4546b87d27088ad88d577df206b0c40634716469f8193947888b6fdf970

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-19

ケース

HOW
ゴール
verify syn::ExprMethodCall in pkg:cargo/syn@3.0.3
パッケージ
シンボル
  • syn::ExprMethodCall
作成日
2026-09-17T16:03:11Z

コントラクト

  1. syn::parse_str parses a basic method call into syn::ExprMethodCall with receiver and method ident
  2. syn::parse_str parses a method call with turbofish generic arguments into syn::ExprMethodCall with AngleBracketedGenericArguments
  3. syn::parse_str parses chained method calls into nested syn::ExprMethodCall receivers
  4. syn::parse_str parses method calls with multiple arguments preserving argument order
  5. syn::parse_str parses method calls with outer attributes into syn::ExprMethodCall with attrs
  6. syn::parse_str distinguishes method calls from field access returning Expr::MethodCall vs Expr::Field

ファイル

  • 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::ExprMethodCall 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::ExprMethodCall

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:800ab95f196f7ac31242049fa52650bff4cfa188091de76cffd71629b781265f","contract":["syn::parse_str parses a basic method call into syn::ExprMethodCall with receiver and method ident","syn::parse_str parses a method call with turbofish generic arguments into syn::ExprMethodCall with AngleBracketedGenericArguments","syn::parse_str parses chained method calls into nested syn::ExprMethodCall receivers","syn::parse_str parses method calls with multiple arguments preserving argument order","syn::parse_str parses method calls with outer attributes into syn::ExprMethodCall with attrs","syn::parse_str distinguishes method calls from field access returning Expr::MethodCall vs Expr::Field"],"goal":"verify syn::ExprMethodCall in pkg:cargo/syn@3.0.3","kind":"HOW","packages":["pkg:cargo/syn@3.0.3"],"schemaVersion":1,"symbols":["syn::ExprMethodCall"]},"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::ExprMethodCall"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify syn::ExprMethodCall in pkg:cargo/syn@3.0.3",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/syn@3.0.3"
  ],
  "symbols": [
    "syn::ExprMethodCall"
  ]
}
src/lib.rs
//! Clean-room verification sample for syn::ExprMethodCall.

pub use syn::*;
test/contract.rs
use syn::{parse_str, Expr, ExprField, ExprMethodCall, GenericArgument, Lit, Type};

fn main() {
    // 1. syn::parse_str parses a basic method call into syn::ExprMethodCall with receiver and method ident
    let expr: Expr = parse_str("receiver.do_something()").expect("failed to parse basic method call");
    match expr {
        Expr::MethodCall(call) => {
            assert_eq!(call.method.to_string(), "do_something");
            match *call.receiver {
                Expr::Path(ref p) => assert_eq!(p.path.segments[0].ident.to_string(), "receiver"),
                _ => panic!("expected Expr::Path for receiver"),
            }
            assert!(call.turbofish.is_none());
            assert!(call.args.is_empty());
        }
        _ => panic!("expected Expr::MethodCall"),
    }

    // 2. syn::parse_str parses a method call with turbofish generic arguments into syn::ExprMethodCall with AngleBracketedGenericArguments
    let expr: Expr = parse_str("iter.collect::<Vec<i32>>()").expect("failed to parse turbofish method call");
    match expr {
        Expr::MethodCall(call) => {
            assert_eq!(call.method.to_string(), "collect");
            let turbofish = call.turbofish.expect("expected turbofish generic arguments");
            assert_eq!(turbofish.args.len(), 1);
            match turbofish.args.first().unwrap() {
                GenericArgument::Type(Type::Path(type_path)) => {
                    assert_eq!(type_path.path.segments[0].ident.to_string(), "Vec");
                }
                _ => panic!("expected Type::Path for generic argument"),
            }
        }
        _ => panic!("expected Expr::MethodCall"),
    }

    // 3. syn::parse_str parses chained method calls into nested syn::ExprMethodCall receivers
    let expr: Expr = parse_str("builder.step_one().step_two()").expect("failed to parse chained method calls");
    match expr {
        Expr::MethodCall(outer) => {
            assert_eq!(outer.method.to_string(), "step_two");
            match *outer.receiver {
                Expr::MethodCall(inner) => {
                    assert_eq!(inner.method.to_string(), "step_one");
                    match *inner.receiver {
                        Expr::Path(p) => assert_eq!(p.path.segments[0].ident.to_string(), "builder"),
                        _ => panic!("expected Expr::Path for base receiver"),
                    }
                }
                _ => panic!("expected Expr::MethodCall for outer receiver"),
            }
        }
        _ => panic!("expected Expr::MethodCall"),
    }

    // 4. syn::parse_str parses method calls with multiple arguments preserving argument order
    let expr: Expr = parse_str("map.insert(\"key\", 42)").expect("failed to parse method call with arguments");
    match expr {
        Expr::MethodCall(call) => {
            assert_eq!(call.method.to_string(), "insert");
            assert_eq!(call.args.len(), 2);
            match (&call.args[0], &call.args[1]) {
                (Expr::Lit(lit0), Expr::Lit(lit1)) => {
                    match (&lit0.lit, &lit1.lit) {
                        (Lit::Str(s), Lit::Int(i)) => {
                            assert_eq!(s.value(), "key");
                            assert_eq!(i.base10_parse::<i32>().unwrap(), 42);
                        }
                        _ => panic!("expected Lit::Str and Lit::Int arguments"),
                    }
                }
                _ => panic!("expected Expr::Lit arguments"),
            }
        }
        _ => panic!("expected Expr::MethodCall"),
    }

    // 5. syn::parse_str parses method calls with outer attributes into syn::ExprMethodCall with attrs
    let expr: Expr = parse_str("#[inline] target.run()").expect("failed to parse method call with attribute");
    match expr {
        Expr::MethodCall(call) => {
            assert_eq!(call.attrs.len(), 1);
            assert_eq!(call.method.to_string(), "run");
        }
        _ => panic!("expected Expr::MethodCall"),
    }

    // 6. syn::parse_str distinguishes method calls from field access returning Expr::MethodCall vs Expr::Field
    let field_expr: Expr = parse_str("obj.field").expect("failed to parse field access");
    assert!(matches!(field_expr, Expr::Field(ExprField { .. })));
    let method_expr: Expr = parse_str("obj.method()").expect("failed to parse method call");
    assert!(matches!(method_expr, Expr::MethodCall(ExprMethodCall { .. })));

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

オリジンシーダー

匿名