Implementing `Copy` can be a breaking change
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#[derive(Clone)]
struct Foo<'a>(&'a ());
// Uncomment this line and the code stops compiling
//impl Copy for Foo<'static> {}
struct Bar<'a>(Foo<'a>);
fn do_thing<'a>(b: Bar<'a>) {
drop(b.0);
}
I expected to see this happen: Uncommenting the line in question does not break the code, as implementing Copy should not be a breaking change
Instead, this happened:
error: lifetime may not live long enough
--> src/lib.rs:10:10
|
9 | fn do_thing<'a>(b: Bar<'a>) {
| -- lifetime `'a` defined here
10 | drop(b.0);
| ^^^ copying this value requires that `'a` must outlive `'static`
Meta
Regressed in 1.42 according to Godbolt.
@rustbot label A-borrow-checker A-lifetimes A-traits T-types regression-from-stable-to-stable
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the src/lib.rs reproducer and compare compilation with and without the Copy implementation, as in the report and its Godbolt regression check. Investigate the borrow-checker, lifetime, and trait behavior implicated by the diagnostic. Done means the reproducer compiles after implementing Copy for Foo<'static> without requiring 'a to outlive 'static.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100