What this thread does
Do first: enable #![deny(unsafe_code)] and inspect the move site and last use before adding a clone.
Short answer
As of November 2026, use Rust 1.99.1. Change a consuming parameter to a borrow when the callee needs access rather than ownership. For threads that must be joined within one operation, scoped threads can borrow non-static data; the scope joins those threads before returning, but thread-local destructors may still be running (E0382, scope).
Choose / don't choose
- Borrow: choose temporary read access with
&Tor exclusive mutation with&mut T; don't return a reference to a local that is about to drop. - Move: choose genuine ownership transfer or a thread that may outlive the caller; don't use cloning to hide an unclear ownership boundary.
- Scoped thread: choose borrowed inputs whose owner outlives the scope; don't choose it for detached/background execution (scope, spawn).
Not for: enforcing a broader opinionated Clippy policy; see beautifulrust-clippy-enforcement-expect-used-config.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
unsafe_code | deny via crate attribute; rejects unsafe blocks in this crate | Current Rust docs | rustc lint |
clippy::redundant_clone | Nursery lint, allow by default; consider warnings for this lint | Current Clippy docs | lint, usage, lint flags |
[lints].workspace | true in each member to inherit a root [workspace.lints] policy | Current Cargo docs | workspace lints |
--all-targets | Include library, binaries, examples, tests and benchmarks in the check | Current Cargo docs | cargo check |
A lint gate covers the current crate/member policy, not an assertion that dependencies contain no unsafe code. deny can be locally overridden; use forbid if policy must prohibit that override (lint levels, Cargo lint scope).
Order of operations
1. For E0382, identify the consuming call. If ownership need not transfer, change it to accept a reference and pass &value; retain the owner through its last borrow. If ownership must transfer, reorder the final use or return ownership explicitly before considering a copy (E0382). 2. For E0597, move the owner to an enclosing scope or shorten the borrow. E0597 occurs because a value was dropped while it was still borrowed (E0597). 3. For borrowed thread input, create data before thread::scope. The relationship is 'env: 'scope: borrowed environment outlives the scope, and every scoped thread’s main function finishes before scope returns; thread-local destructors may still be running. Data created inside too-short inner lifetimes still cannot escape (scope). 4. Compile supported targets and run Clippy after edits. Inspect clone suggestions against the actual move/borrow relationship before applying them.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
E0382 | Reuse after ownership moved | Borrow if transfer is unnecessary, or redesign the ownership boundary | compiler explanation |
does not live long enough | Borrow survives its owner | Extend owner scope or shorten reference lifetime | E0597 |
redundant clone suggestion breaks compilation | Reported false positive with moved data | Inspect and compile the suggested edit; narrowly allow a demonstrated false positive | Jonathas-Conceicao report |
Missing
- Clippy's clone analysis is conservative; silence does not establish minimum allocations.
- The historical lint report does not establish a current compiler regression.
Checked
2026-11-12; Rust release, error-code, thread, lint, Cargo and Clippy docs read; Jonathas-Conceicao's dated report read. No compiler or Clippy commands executed.
Started from a post by @Rust project, packaged by the editor. Original post