Open nikvoid opened 6 months ago
Follow-up: type cycle when using transmute on mutable reference to get pointer
fn bug() -> *mut Ext {
let inner = wrap(Regular, opaque());
let boxed = Box::new(Buffered(inner));
// *mut Stream -> *mut Ext, this should be fine
transform_to_ext(unsafe { std::mem::transmute(Box::leak(boxed)) })
}
error[E0391]: cycle detected when computing type of `Stream::{opaque#0}`
--> src/main.rs:8:39
|
8 | type Stream = Buffered<Inner<Regular, impl Tr>>;
| ^^^^^^^
|
note: ...which requires computing type of opaque `Stream::{opaque#0}`...
--> src/main.rs:8:39
|
8 | type Stream = Buffered<Inner<Regular, impl Tr>>;
| ^^^^^^^
note: ...which requires type-checking `bug`...
--> src/main.rs:27:1
|
27 | fn bug() -> *mut Ext {
| ^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `*mut Buffered<Inner<Regular, Stream::{opaque#0}>>`...
= note: ...which requires normalizing `*mut Buffered<Inner<Regular, Stream::{opaque#0}>>`...
= note: ...which again requires computing type of `Stream::{opaque#0}`, completing the cycle
note: cycle used when checking that `Stream::{opaque#0}` is well-formed
--> src/main.rs:8:39
|
8 | type Stream = Buffered<Inner<Regular, impl Tr>>;
| ^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
Another follow-up: this works
fn workaround() -> *mut Ext {
fn eyepatch() -> *mut Stream {
let inner = wrap(Regular, opaque());
let boxed = Box::new(Buffered(inner));
Box::leak(boxed) as *mut _
}
transform_to_ext(eyepatch())
}
fn bug() -> *mut Ext {
let inner = wrap(Regular, opaque());
let boxed = Box::new(Buffered(inner));
// *mut Stream -> *mut Ext, this should be fine
transform_to_ext(Box::leak(boxed) as *mut Stream)
}
This is attempting to define the type of the Stream
TAIT, but it doesn't follow the rule that the TAIT must be mentioned in the signature of the function. Adding where Stream:
to the where clause should fix it, but that's kind of a hack.
We're (@oli-obk / me / @traviscross, among others) are thinking about changing the rules for defining TAITs anyways (e.g. a #[defines]
attribute), so maybe this hack will be good enough for now.
Thanks for pointing it out, this hack looks better than inner function
I tried this code:
(1) I originally encountered this issue with pointers
(2) If you remove pointers, there is the same-ish error, but with more (pointless for me though) diagnostics:
I expected to see this happen: no errors
Instead, this happened: (1)
(2)
Meta
rustc --version --verbose
: