Open
Description
The following code compiles successfully:
#![feature(type_alias_impl_trait)]
pub struct Foo {
field: (),
}
pub type Tait = impl Sized;
pub fn func1(input: Tait) {
let Foo { .. } = input;
}
pub fn func2(input: Tait) {
let Foo { field: _ } = input;
}
pub fn func3(input: Tait) {
let Foo { field } = input;
}
However, if func3
is commented out, then neither func1
nor func2
suffices to constrain Tait
:
error: unconstrained opaque type
--> src/lib.rs:7:17
|
7 | pub type Tait = impl Sized;
| ^^^^^^^^^^
|
= note: `Tait` must be used in combination with a concrete type within the same module
It seems that the pattern only counts as actually constraining the type if one of the fields is actually destructured. The same behavior happens for tuple types; e.g. let () = input;
does not constrain.
Of course, it would be difficult for this to actually matter, since nothing ever produces a value of type Tait
, so none of the functions can be called, but this might be a sign of a deeper problem (or just something to nail down about TAIT semantics), so I figured I'd report it anyway. I discovered it while minimizing #113594.
Meta
rustc --version --verbose
:
rustc 1.73.0-nightly (8ca44ef9c 2023-07-10)
binary: rustc
commit-hash: 8ca44ef9caa4049d584fbbce218c219cdca33a2f
commit-date: 2023-07-10
host: x86_64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5
@rustbot label +A-impl-trait +F-type_alias_impl_trait