-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing Copy
can be a breaking change
#126179
Comments
The example from the blogpost has two |
Adding a copy impl for a specific lifetime is not something that should ever be done, and a bug in the program. |
Removing the regression labels since this was intentional (if you disagree feel free to re-add) |
Looking through discussion on the PR and on Zulip, I haven't found any evidence that this is the case. @rustbot label regression-from-stable-to-stable |
That's would perhaps be a reasonable position to take, but it's not one the language team has ever FCPed AFAIK. |
I don't think we need a lang FCP to decide that implementing copy for only some lifetimes is nonsense^^ |
The documentation of |
Minimizing further: #[derive(Clone)]
struct W<T>(T);
impl Copy for W<&'static ()> {}
fn test<'a>(x: W<&'a ()>) {
let _x = x;
//~^ ERROR lifetime may not live long enough
//~| NOTE copying this value requires that `'a` must outlive `'static`
} This is, I would imagine, a result of the fact that "lifetimes don't participate in trait selection". E.g.: struct W<T>(T);
trait OnW {
fn method(&self) {}
}
trait OnWStatic {
fn method(&self) {}
}
impl<'a> OnW for W<&'a ()> {}
impl OnWStatic for &W<&'static ()> {}
fn test<'a>(x: W<&'a ()>) {
(&&x).method();
//~^ ERROR borrowed data escapes outside of function
//~| NOTE `x` escapes the function body here
//~| NOTE argument requires that `'a` must outlive `'static`
} See Trait solving > Selection in the dev guide:
Given this, programs such as the above seem unlikely to be accepted in Rust for the foreseeable future. |
Going to remove the prioritization label, by reading the comments I don't see an actionable here. But If this is a regression please change my mind. @rustbot label -I-prioritize -regression-from-stable-to-stable |
My understanding is, this issue stems from the fact that moving vs copying a non- |
I tried this code:
I expected to see this happen: Uncommenting the line in question does not break the code, as implementing
Copy
should not be a breaking changeInstead, this happened:
Meta
Regressed in 1.42 according to Godbolt.
@rustbot label A-borrow-checker A-lifetimes A-traits T-types regression-from-stable-to-stable
The text was updated successfully, but these errors were encountered: