The following currently passes the structural match check and causes an ICE later on:
(now that #72153 has landed, this emits an error)
#![feature(const_fn, type_alias_impl_trait)]
type F = impl Send;
// This does not implement structural match
struct A;
const fn value(a: A) -> F {
a
}
const V: F = value(A);
fn main() {
match value(A) {
V => println!("hey"),
}
}
I believe we have to either leak the structural match property of opaque types,
(similar to Send and Sync afaict) or forbid this entirely.
I am in favor of the second option for now. It should not be a breaking change to go from the
second to the first later on.
This issue concerns the implementation in #72153
@eddyb @pnkfelix @RalfJung
The same problem probably also exists for Generator and GeneratorWitness, which are currently implicitly accepted.
I believe we have to either leak the structural match property of opaque types,
(similar to Send and Sync afaict)
I don't know what "leak" means.
But forbidding it for now seems best. :D
This is what I've meant with "leak":
fn test<T: Sync>(_: T) {}
fn ok() -> impl Eq {
7
}
fn not_ok() -> impl Eq {
std::cell::Cell::new(7)
}
fn main() {
test(ok());
// This works, `ok` returns a type implementing `Sync`.
//
// Note that we do not explicitly mention `Send` in the return type of `ok`.
test(not_ok());
// This fails, `not_ok` returns a type not implementing `Sync`.
}
Ah I see -- auto traits are "leaked" through opaque ("impl Trait") types.
Structural(Partial)Eq are not auto traits though and likely can't be...
Structural(Partial)Eqare not auto traits though and likely can't be...
I don't see the connection between auto traits and leaking through opaque types rn.
At least to my understanding we theoretically could completely leak the actual type and allow stuff like
fn int() -> impl Send {
7
}
fn main() {
let _x: i32 = int().wrapping_add(7);
}
I don't see the connection between auto traits and leaking through opaque types rn.
AFAIK all auto traits currently leak through opaque types (Send/Sync are not special) and nothing else does. That seems like a pretty direct connection to me?^^
Didn't know we leak Unpin :eyes:
In case there is a use case where we want to change this, we can open a new issue.
Most helpful comment
AFAIK all auto traits currently leak through opaque types (
Send/Syncare not special) and nothing else does. That seems like a pretty direct connection to me?^^