Skip to content

Instantly share code, notes, and snippets.

@GarthDB
Created September 10, 2025 19:42
Show Gist options
  • Select an option

  • Save GarthDB/74ef5ced13909164de54416c7e63c730 to your computer and use it in GitHub Desktop.

Select an option

Save GarthDB/74ef5ced13909164de54416c7e63c730 to your computer and use it in GitHub Desktop.

Octocrab E0716 Lifetime Issue Reproduction

This is a minimal reproduction of the E0716: temporary value dropped while borrowed error that occurs when using octocrab's builder pattern for creating GitHub issues.

The Problem

The current octocrab API forces users to store intermediate values to avoid lifetime issues, which goes against the ergonomic builder pattern that Rust developers expect.

How to Reproduce

  1. Clone this gist or copy the files
  2. Run cargo check or cargo run
  3. Observe the E0716 compilation error

Expected Error

error[E0716]: temporary value dropped while borrowed
  --> src/main.rs:25:29
   |
25 |     let mut issue_builder = client.issues(owner, repo).create(title);
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                     - temporary value is freed at the end of this statement
   |                             |
   |                             creates a temporary value which is freed while still in use
...
28 |     issue_builder = issue_builder.body(body);
   |                     ^^^^^^^^^^^^^ borrow later used here

Current Workaround

// Store the intermediate value to extend its lifetime
let issues_client = client.issues(owner, repo);
let mut issue_builder = issues_client.create(title);
issue_builder = issue_builder.body(body);
issue_builder = issue_builder.labels(labels);
issue_builder.send().await?;

Proposed Solution

The octocrab library should return owned types from builder methods instead of references, allowing for ergonomic method chaining:

// This should work without lifetime issues
let issue = client.issues(owner, repo)
    .create(title)
    .body(body)
    .labels(labels)
    .send()
    .await?;

Related

Environment

  • octocrab: 0.36.0
  • Rust: 1.75.0+
  • OS: Any
[package]
name = "octocrab-e0716-reproduction"
version = "0.1.0"
edition = "2021"
description = "Minimal reproduction of E0716 lifetime issue in octocrab builder pattern"
[workspace]
[[bin]]
name = "main"
path = "main.rs"
[dependencies]
octocrab = "0.36"
tokio = { version = "1.0", features = ["full"] }
// Octocrab E0716 "temporary value dropped while borrowed" reproduction
//
// This demonstrates the lifetime issue when using octocrab's builder pattern
// for creating GitHub issues. The problem forces users to write non-idiomatic
// Rust code to work around the lifetime constraints.
//
// Issue: https://github.com/XAMPPRocky/octocrab/issues/new
//
// Run with: cargo run
// Expected: E0716 compilation error
use octocrab::Octocrab;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Octocrab::builder()
.personal_token("your_token_here".to_string())
.build()?;
let owner = "octocrab-rs";
let repo = "octocrab";
let title = "Test Issue";
let body = "This is a test issue body";
let labels = vec!["bug".to_string(), "enhancement".to_string()];
// ❌ THIS FAILS WITH E0716: temporary value dropped while borrowed
// The issue is that client.issues(owner, repo) returns a temporary value
// that gets dropped at the end of the statement, but issue_builder still
// holds a reference to it.
let mut issue_builder = client.issues(owner, repo).create(title);
// ^^^^^^^^^^^^^ temporary value is freed at the end of this statement
issue_builder = issue_builder.body(body);
// ^^^^^^^^^^^^^ borrow later used here
issue_builder = issue_builder.labels(labels);
// issue_builder.send().await?; // This would also fail
// ✅ WORKAROUND: Store the intermediate value to extend its lifetime
// This works but is less ergonomic and goes against Rust builder patterns
/*
let issues_client = client.issues(owner, repo);
let mut issue_builder = issues_client.create(title);
issue_builder = issue_builder.body(body);
issue_builder = issue_builder.labels(labels);
issue_builder.send().await?;
*/
println!("This example demonstrates the E0716 lifetime issue in octocrab");
Ok(())
}
#!/bin/bash
echo "Testing octocrab E0716 reproduction..."
echo "Running: cargo check"
cargo check
echo ""
echo "Expected: E0716 compilation error"
echo "If you see the error above, the reproduction is working!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment