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 gist or copy the files
- Run
cargo checkorcargo run - Observe the E0716 compilation 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
// 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?;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?;- octocrab: 0.36.0
- Rust: 1.75.0+
- OS: Any