-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
repeat expression do not honor lt bounds of copy #95477
Comments
considering that fn pass<'a: 'a>(x: Foo<'a>) -> Foo<'a> {
x
}
fn duplicate<'a>(x: Foo<'a>) -> [Foo<'a>; 100] {
[pass::<'a>(x); 100]
} also errors it seems like we somehow treat functions without any arguments in a special (and incorrect) way? @RalfJung I know that we've recently stabilized some additional exprs for repeat expressions, do you know more here? |
Ah no, we just decide whether to copy or move things depending on whether they implement here's a version which duplicates fn inner<'a, F: FnOnce() -> Foo<'a>>(f: F) -> [Foo<'a>; 2] {
[f(); 2]
}
struct NeverCopy<T>(T);
impl<T> NeverCopy<T> {
fn inner(self) -> T {
self.0
}
}
fn duplicate<'a>(foo: NeverCopy<Foo<'a>>) -> [Foo<'a>; 2] {
inner(move || foo.inner())
} but that isn't really too relevant considering that optionally |
I think that is a general issue with
This looks exactly the same to me as the original example? |
Cc @oli-obk @nikomatsakis who might know more about MIR generation and |
Actually this might be a duplicate of #88901 ? |
Yea it's probably a duplicate or variant of that issue. This modulo-regions scheme is such a compiler footgun... I keep encountering it. |
The original code requires the creation of a new |
Yes, our general strategy for Copy is:
If I had my druthers, we would have required that Copy impls were always applicable, but we did not, and so we opted for the above compromise (I could dredge up the issue, but it hardly matters). We do generally consider it a soundness issue to fail to enforce those rules. (That said, I've been working on a revised type system that I think might make the whole "modulo-regions" scheme far less necessary or important... but that's for another time.) |
Yeah, that seems to not be working in some cases. |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-low |
this compiles both with and without
feature(nll)
. Note thatmk_foo
creates a value of typeFoo<'a>
which may not be copied.Moving
mk_foo::<'a>()
into a local errors as expected:this results in
The text was updated successfully, but these errors were encountered: