Skip to content

Commit

Permalink
Rollup merge of #123794 - oli-obk:define_opaque_types2, r=lcnr
Browse files Browse the repository at this point in the history
More DefineOpaqueTypes::Yes

This accepts more code on stable. It is now possible to have match arms return a function item `foo::<ConcreteType>` and a function item `foo::<OpaqueTypeInDefiningScope>` in another, and that will constrain `OpaqueTypeInDefiningScope` to have the hidden type `ConcreteType`. So the following function will now compile, but on master it errors with a type mismatch on the second match arm

```rust
// The function item whose generic params we want to merge.
fn foo<T>(t: T) -> T { t }
// Helper ensuring we can constrain `T` on `F` without explicitly specifying it
fn bind<T, F: FnOnce(T) -> T>(_: T, f: F) -> F { f }

fn k() -> impl Sized {
    let x = match true {
        true => {
            // `f` is `FnDef(foo, [infer_var])`
            let f = foo;
            // Get a value of an opaque type on stable
            let t = k();
            // this returns `FnDef(foo, [k::return])`
            bind(t, f)
        }
        false => foo::<()>,
    };
    todo!()
}
```

r? ``@compiler-errors``

cc rust-lang/rust#116652
  • Loading branch information
fmease committed Apr 24, 2024
2 parents 28c86a1 + 58ce713 commit c8d2b81
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit c8d2b81

Please sign in to comment.