Open
Description
The following code should compile. However we infer two conflicting hidden types, Opaque<A> := Opaque<A>
and Opaque<B> := u8
, causing an error:
#![feature(type_alias_impl_trait)]
type Opaque<T> = impl Sized;
fn test<A, B>(
arg: Vec<(Opaque<A>, u8)>,
) -> impl IntoIterator<Item = (Opaque<A>, Opaque<B>)> {
arg
//~^ ERROR concrete type differs from previous defining opaque type use
//~| expected `Opaque<T>`, got `u8`
}
Another case to show that it is not enough to naively ignore the recursive definition, as it may have different arguments (Opaque<'a, 'b> := Opaque<'static, 'static>
).
#![feature(type_alias_impl_trait)]
type Opaque<'a, 'b> = impl Sized + 'a + 'b;
//~^ ERROR concrete type differs from previous defining opaque type use
//~| expected `Opaque<'static, 'static>`, got `()`
// `Opaque<'a, 'b> := ()`
fn get_one<'a, 'b>() -> Opaque<'a, 'b> {}
// `Opaque<'a, 'b> := Opaque<'static, 'static>`
fn get_iter<'a, 'b>() -> impl IntoIterator<Item = Opaque<'a, 'b>> {
Some(get_one())
}
Normally when we encounter an equality Opaque<A> == Opaque<A>
, we equate substs and never register a hidden type.
The only way we infer an opaque type to be recursive in borrowck is through replace_opaque_types_with_inference_vars
here:
rust/compiler/rustc_trait_selection/src/traits/project.rs
Lines 319 to 328 in 82c5732
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo