]> git.lizzy.rs Git - rust.git/commit
Auto merge of #105409 - compiler-errors:closure-infer-cycle, r=jackh726
authorbors <bors@rust-lang.org>
Thu, 5 Jan 2023 03:59:31 +0000 (03:59 +0000)
committerbors <bors@rust-lang.org>
Thu, 5 Jan 2023 03:59:31 +0000 (03:59 +0000)
commit03b9e1d154ecf8e04656fdf0179a28cd8ef333c5
tree8c1b70fb5f8b03c7d47813924f1f0ca8c09438f0
parentd26242d35faf50aa9c873fa3c7c15e5564384baa
parentfa2f31b97178c3a66d6e5f91fa597711f585fd3b
Auto merge of #105409 - compiler-errors:closure-infer-cycle, r=jackh726

Don't deduce a signature that makes a closure cyclic

Sometimes when elaborating supertrait bounds for closure signature inference, we end up deducing a closure signature that is cyclical because either a parameter or the return type references a projection mentioning `Self` that also has escaping bound vars, which means that it's not eagerly replaced with an inference variable.

Interestingly, this is not *just* related to my PR that elaborates supertrait bounds for closure signature deduction. The committed test `supertrait-hint-cycle-3.rs` shows **stable** code that is fixed by this PR:

```rust
trait Foo<'a> {
    type Input;
}

impl<F: Fn(u32)> Foo<'_> for F {
    type Input = u32;
}

fn needs_super<F: for<'a> Fn(<F as Foo<'a>>::Input) + for<'a> Foo<'a>>(_: F) {}

fn main() {
    needs_super(|_: u32| {});
}
```

Fixes #105401
Fixes #105396

r? types
compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs