-
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
Unions require Copy fields, but ignore regions in the check #98102
Comments
But you can't actually instantiate a fn main() {
let s = 123;
let v = Foo { s: &s };
Bar { v };
} results in— error[E0597]: `s` does not live long enough --> src/main.rs:12:22 | 12 | let v = Foo { s: &s }; | ^^ borrowed value does not live long enough 13 | Bar { v }; | - copying this value requires that `s` is borrowed for `'static` 14 | } | - `s` dropped here while still borrowed For more information about this error, try `rustc --explain E0597`. |
Removing A-diagnostics because I don' t think this is a diagnostics issue necessarily. I can modify the check that we use for checking the union's field are @rustbot claim |
Yeah. I think it's a breaking change potentially to change this now, so it might not be worth making any movement here. I think in practice there's no risk here, since I believe any Copy impl does forbid all Drop impls, since Drop must be implemented modulo regions always. |
You can instantiate it, and even work with it, but you can't move the maybe- fn main() {
let mut s = 123;
let v = Foo { s: &mut s };
let v = v; // Works if I comment this line
}
|
@Mark-Simulacrum: In #55149 (comment), @joshtriplett said:
I think promoting this to do a copy check considering regions is probably still worth considering here? |
It's probably worth a crater run, at least, but I'm not sure how that comment is relevant. It would be (IMO) the right behavior, but it would also be a breaking change in theory, at least, which makes me reluctant to move ahead with it. |
I can't find a way to instantiate with only safe code. Doing it via unsafe code (at least the ways I've thought about, like Is there actually some unsoundness here that I've overlooked? If so this should be |
fn main() {
let s = 123;
let union = Bar { v: Foo { s: &s } };
} But I don't think this deserves I-unsound since the moment you'll try to move the inner |
In a second thought, I'm not sure: you can impl |
Apologies, I can't have had enough coffee yet. Of course this isn't a soundness issue: it's only about ensuring that destructors are run, or that one is explicitly acknowledging with |
Triage: There doesn't seem to be anything actionable here? Closing. |
Why is this not actionable? Someone should probably implement this check. |
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4cc269cb234497a007039d6ddbc41943
It seems to me that the above code should probably be rejected, since in general
Foo<'a>
doesn't implement Copy in the above code.The compiler check is checking for "is_copy_modulo_regions" specifically https://github.com/rust-lang/rust/blob/master/compiler/rustc_passes/src/stability.rs#L780, which seems like it probably shouldn't be modulo regions?
The text was updated successfully, but these errors were encountered: