rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.62k stars 1.49k forks source link

r-a gets confused with nested anonymous type params when additional where bounds are involved #17173

Open Veykril opened 2 weeks ago

Veykril commented 2 weeks ago
pub trait Lookup {
    type Data;
    fn lookup(&self) -> Self::Data;
}
pub trait ItemTreeLoc {
    type Id;
}
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>)
where
    (): Sized, // error below disappears if this is removed
{
    id.lookup(); // no method `lookup` on type `impl ItemTreeLoc<Id = ()>
}
Veykril commented 2 weeks ago

Test fixture that currently fails


//- minicore: sized
pub trait Lookup {
    type Data;
    fn lookup(&self) -> Self::Data;
}
pub trait ItemTreeLoc {
    type Id;
}
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>)
                //^^ impl Lookup<Data = impl ItemTreeLoc<Id = ()>>
where
    (): Sized,
{}
Veykril commented 2 weeks ago

Something is still wrong here

#[test]
fn nested_anon_generics_and_where_bounds_17173() {
    check_types(
        r#"
//- minicore: sized, fn
pub trait Lookup {
    type Data;
    fn lookup(&self) -> Self::Data;
}
pub trait ItemTreeLoc {
    type Id;
}
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>,
                //^^ impl Lookup<Data = impl ItemTreeLoc<Id = ()>>
                enabled_params: impl Fn(),
              //^^^^^^^^^^^^^^  impl Fn()
                )
where
    (): Sized,
{}
"#,
    );
}

The impl Fn() is being recognized as impl ItemTreeLoc<Id = ()>

lnicola commented 1 week ago

This was fixed in #17176, right?