Closed wdanilo closed 2 years ago
Minimized:
#![feature(type_alias_impl_trait)]
#![feature(trait_alias)]
type Foo = impl Copy;
enum Wrapper<T> {
First(T),
Second
}
fn produce() -> Wrapper<Foo> {
Wrapper::Second
}
This appears to be caused by the fact that we create a new inference variable for Foo
from Wrapper<Foo>
, but never unify it because produce
does not constrain the opaque type.
As a side note, we should probably be cheking for type errors when we collect opaque type uses, so that we don't print useless errors like:
expected `[closure@lib/optics/src/lib.rs:44:15: 44:48]`, got `[type error]`
@Aaron1011 thanks for tracking it down. Tbh, I don't see why your code is a minimized version of mine – I don't return from any function variant without the impl trait. This is just a note – I don't know the internals of rustc so I can miss a lot of info here :)
I've opened https://github.com/rust-lang/rust/pull/66431. It addresses the first 'layer' of errors, but there appear to more (thankfully, better) errors that appear after this one is no longer emitted.
This now compiles on the latest nightly.
Actually, this does not compile - I didn't use the modified _Some
function when testing.
Errors on current master:
error: non-defining opaque type use in defining scope
--> src/main.rs:64:6
|
64 | ) -> Lens<'t, CombinedOptGetter<'t, Get, SomeGetter<'t, B>, A, Option<B>, B>, A, B>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: used non-generic type `impl OptGetter<'t, Option<B>, B>` for generic parameter
--> src/main.rs:20:34
|
20 | type CombinedOptGetter<'t, Get1, Get2, A, B, C> = impl OptGetter<'t, A, C>;
| ^^^^
error: non-defining opaque type use in defining scope
--> src/main.rs:64:6
|
64 | ) -> Lens<'t, CombinedOptGetter<'t, Get, SomeGetter<'t, B>, A, Option<B>, B>, A, B>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: used non-generic type `Option<B>` for generic parameter
--> src/main.rs:20:43
|
20 | type CombinedOptGetter<'t, Get1, Get2, A, B, C> = impl OptGetter<'t, A, C>;
| ^
error: aborting due to 2 previous errors
For I was mistakenmin_type_alias_impl_trait
, I believe this is covered by #86732
The minimized example (playground:
#![feature(min_type_alias_impl_trait)]
type Foo = impl Copy;
enum Wrapper<T> {
First(T),
Second
}
fn produce() -> Wrapper<Foo> {
Wrapper::Second
}
gives what appears to me to be the correct error:
error: could not find defining uses
--> src/lib.rs:3:12
|
3 | type Foo = impl Copy;
| ^^^^^^^^^
but the diagnostics are not very good.
In particular, the value of Foo
is not constrained at all by this function. If you extend to
#![feature(min_type_alias_impl_trait)]
type Foo = impl Copy;
enum Wrapper<T> {
First(T),
Second
}
fn produce() -> Wrapper<Foo> {
Wrapper::First(22)
}
then it works.
The diagnostic for
#![feature(type_alias_impl_trait)]
type Foo = impl Copy;
enum Wrapper<T> {
First(T),
Second
}
fn produce() -> Wrapper<Foo> {
Wrapper::Second
}
is now
10 | fn produce() -> Wrapper<Foo> {
| ------------ type must be known at this point
11 | Wrapper::Second
| ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper`
|
= note: cannot satisfy `_: Copy`
help: consider specifying the generic argument
|
11 | Wrapper::<T>::Second
| +++++
I don't believe there is anything left to do here. Please open a new issue if there are issues beyond the failure to infer the type
Hi! I'm trying to write a lens library for Rust (see this for reference about lenses: https://github.com/ekmett/lens/wiki). I'm trying to write it in an zero-overhead style, so all lens-usages could be optimized away during compilation stage, thus, I'm trying to create unboxed closures and glue them together. However, a very strange error occurs here. Consider the following code:
It compiles fine. However, if you try to return
wrapper
from the_Some
function, the code will not compile and the errrors we get are not very explanatory either. With this code instead:We get: