-
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
can't store static references in a Unique indirectly #22655
Comments
My suspicion (which I removed from the first post because I'm not quite sure if it's the reason) is that it has to do with variance. Creating my own |
(More) reduced test case (reduced in that it's isolated from the stdlib): use std::marker::PhantomData;
unsafe impl<T: Send + ?Sized> Send for Unique<T> { }
unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { }
pub struct Unique<T:?Sized> {
pointer: *const T,
_marker: PhantomData<T>,
}
pub struct Node<V> {
vals: V,
edges: Unique<Node<V>>,
}
fn is_send<T: Send>() {}
fn main() {
is_send::<Node<&'static ()>>();
} there is in fact an interaction with variance. The problem is that the "infinite cycle" detection doesn't seem to be kicking in here because an endless set of new region variables are being generated. This is probably due to the variance of |
(Er, the variance of various things. :) |
So I've kind of thought this through. I think the right fix is to enhance the trait matching system to understand that there is in fact no need to keep generating new constraints. This seems to be a bit complicated (it interacts with, among other things, #21974). The short-term pragmatic fix is probably to modify MarkerTrait to be invariant, not contravariant. This is stricter than necessary but probably not terrible. The implication is that if one knows that e.g. |
I plan to work around this problem for now by changing the definition of |
…iveness, but is necessary for now to work around rust-lang#22806. Fixes rust-lang#22655.
…ecursion, r=pnkfelix Change MarkerTrait to be invariant. This is a (small) loss of expressiveness, but is necessary for now to work around rust-lang#22806. Fixes rust-lang#22655. r? @pnkfelix
…ecursion, r=pnkfelix Change MarkerTrait to be invariant. This is a (small) loss of expressiveness, but is necessary for now to work around rust-lang#22806. Fixes rust-lang#22655. r? @pnkfelix
EDIT: Removed talk of variance, since it doesn't seem to be the cause and it was unnecessarily longer due to it.
It seems to me like 801bc48 is an attempt to introduce the second approach from the unresolved questions of RFC 738.
It seems to me that the commit is actually a breaking change, because it broke my code without my changing it. Consider this reduced example (thanks to @p1start for helping me to reduce it further).
This overflows on the recursive requirement evaluation:
I attempted to bump the recursion limit to 2046 even and it just told me to try again with 4096, so I figure it's just going to infinitely recurse if allowed.
This only seems to happen if I use a
&'static
reference, so I think that has something to do with it.@p1start came up with an example that actually hangs rustc completely when using a recursive type:
The real-world scenario that led me to this bug was a
BTreeMap
with&'static str
keys:The text was updated successfully, but these errors were encountered: