CodeSampleX

示例

backtrace 0.3.76: backtrace::Backtrace

已验证示例 — cargo backtrace 0.3.76: backtrace::Backtrace. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: Backtrace::new captures stack frames and resolves…

sha256:a569ea80ca1944f6ad0a9797582cad073c701afb1634d70ac90f115ed2fc1ece

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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-20

案例

HOW
目标
verify backtrace::Backtrace in pkg:cargo/backtrace@0.3.76
包
符号
  • backtrace::Backtrace
创建时间
2026-09-20T15:21:08Z

契约

  1. Backtrace::new captures stack frames and resolves symbols
  2. Backtrace::new_unresolved captures unresolved frames and resolve populates symbol names
  3. Backtrace::frames returns non-empty slice of BacktraceFrame with instruction pointers
  4. Backtrace implements Clone and fmt::Debug formatting

文件

  • Cargo.lock
  • Cargo.toml
  • NOTES.md
  • 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 = "addr2line"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5d307320b3181d6d7954e663bd7c774a838b8220fe0593c86d9fb09f498b4b"
dependencies = [
 "gimli",
]

[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"

[[package]]
name = "backtrace"
version = "0.3.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb531853791a215d7c62a30daf0dde835f381ab5de4589cfe7c649d2cbe92bd6"
dependencies = [
 "addr2line",
 "cfg-if",
 "libc",
 "miniz_oxide",
 "object",
 "rustc-demangle",
 "windows-link",
]

[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"

[[package]]
name = "gimli"
version = "0.32.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e629b9b98ef3dd8afe6ca2bd0f89306cec16d43d907889945bc5d6687f2f13c7"

[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"

[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"

[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
 "adler2",
]

[[package]]
name = "object"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe"
dependencies = [
 "memchr",
]

[[package]]
name = "rustc-demangle"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b74b56ffa8bb2830709a538c2cbcae9aa062db0d2a42563bfb09bdaae44020eb"

[[package]]
name = "sample-backtrace"
version = "1.0.0"
dependencies = [
 "backtrace",
]

[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
Cargo.toml
[package]
name = "sample-backtrace"
version = "1.0.0"
edition = "2021"
publish = false

[dependencies]
backtrace = "=0.3.76"

[[bin]]
name = "contract"
path = "test/contract.rs"
NOTES.md
# backtrace 0.3.76 Backtrace Capture and Symbol Resolution API Contracts

## What `search_known_solution` answered
`search_known_solution` returned NO_SAFE_MATCH for pkg:cargo/backtrace@0.3.76. This sample establishes the verified contracts for backtrace::Backtrace capture, resolution, and inspection in version 0.3.76.

## What a model would have written instead
A model may assume that `Backtrace::new()` and `Backtrace::new_unresolved()` behave identically regarding symbol availability, or expect `frame.symbols()` to be populated before `resolve()` is invoked. Models also frequently assume serialization is enabled by default or attempt to parse backtrace strings manually instead of using structured frame accessors and `fmt::Debug`.

## How the wrong version fails
Accessing `frame.symbols()` on an unresolved backtrace before calling `resolve()` yields an empty slice without error, leading to silent assertion failures. Expecting manual string parsing or non-standard constructors fails compilation against the public crate API.
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 backtrace::Backtrace in pkg:cargo/backtrace@0.3.76
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/backtrace@0.3.76
Demonstrate these symbols/APIs:
  - backtrace::Backtrace

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:3121645f3ded59dc32e65f4818f4d469808242546255d7a631c6b253c60b0a82","contract":["Backtrace::new captures stack frames and resolves symbols","Backtrace::new_unresolved captures unresolved frames and resolve populates symbol names","Backtrace::frames returns non-empty slice of BacktraceFrame with instruction pointers","Backtrace implements Clone and fmt::Debug formatting"],"goal":"verify backtrace::Backtrace in pkg:cargo/backtrace@0.3.76","kind":"HOW","packages":["pkg:cargo/backtrace@0.3.76"],"schemaVersion":1,"symbols":["backtrace::Backtrace"]},"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/backtrace@0.3.76"],"schemaVersion":1,"subject":"pkg:cargo/backtrace@0.3.76","symbols":["backtrace::Backtrace"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify backtrace::Backtrace in pkg:cargo/backtrace@0.3.76",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/backtrace@0.3.76"
  ],
  "symbols": [
    "backtrace::Backtrace"
  ]
}
src/lib.rs
//! Clean-room verification sample for backtrace.

pub use backtrace::*;
test/contract.rs
use backtrace::Backtrace;

fn main() {
    // 1. Backtrace::new captures stack frames and resolves symbols
    let bt = Backtrace::new();
    let frames = bt.frames();
    assert!(!frames.is_empty(), "Backtrace::new must capture at least one frame");

    let mut resolved_any = false;
    for frame in frames {
        let _ = frame.ip();
        let _ = frame.symbol_address();
        if !frame.symbols().is_empty() {
            resolved_any = true;
        }
    }
    assert!(resolved_any, "Resolved backtrace must contain resolved symbols");

    // 2. Backtrace::new_unresolved captures unresolved frames and resolve populates symbol names
    let mut bt_unresolved = Backtrace::new_unresolved();
    let frames_before = bt_unresolved.frames();
    assert!(!frames_before.is_empty(), "Backtrace::new_unresolved must capture frames");
    assert!(
        frames_before.iter().all(|f| f.symbols().is_empty()),
        "Frames in new_unresolved must not have resolved symbols initially"
    );

    bt_unresolved.resolve();
    let frames_after = bt_unresolved.frames();
    assert!(!frames_after.is_empty(), "Frames must persist after calling resolve()");
    let resolved_after = frames_after.iter().any(|f| !f.symbols().is_empty());
    assert!(resolved_after, "Symbols must be populated after calling resolve()");

    // 3. Backtrace::frames returns non-empty slice of BacktraceFrame with instruction pointers
    let frame_slice = bt.frames();
    assert!(frame_slice.len() > 0, "frames() should return a non-empty slice");
    let first_ip = frame_slice[0].ip();
    assert!(!first_ip.is_null(), "Frame IP should not be null");

    // 4. Backtrace implements Clone and fmt::Debug formatting
    let cloned_bt = bt.clone();
    assert_eq!(bt.frames().len(), cloned_bt.frames().len(), "Cloned backtrace must match frame count");

    let debug_output = format!("{:?}", bt);
    assert!(!debug_output.is_empty(), "Debug formatting must produce non-empty output");

    println!("All backtrace::Backtrace contract assertions passed successfully.");
}

原始种子者

匿名