Skip to content

Implementing Copy can be a breaking change #126179

Open
@Jules-Bertholet

Description

@Jules-Bertholet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions