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 current octocrab API forces users to store intermediate values to avoid lifetime issues, which goes against the ergonomic builder pattern that Rust developers expect.
- Clone this repository or copy the files
- Run
cargo checkorcargo run - Observe the E0716 compilation error (when uncommented)
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// Store the intermediate value to extend its lifetime
let issues_client = client.issues(owner, repo);
let issue_builder = issues_client
.create(title)
.body(body)
.labels(labels);
issue_builder.send().await?;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?;After implementing the workaround, the code passes all clippy lints including clippy::pedantic:
cargo clippy -- -W clippy::pedanticThe workaround does not introduce any clippy warnings or errors, making it a clean solution for the lifetime issue.
- octocrab: 0.36.0
- Rust: 1.75.0+
- OS: Any