Skip to content

TAIT: "unconstrained opaque type" error even if it's constrained #96572

Description

@Dirbaio

This is allowed:

    type T = impl Copy;
    let foo: T = (1u32, 2u32);

But this isn't:

    type T = impl Copy;  // error: unconstrained opaque type
    let foo: T = (1u32, 2u32);
    let (a, b) = foo;

It seems strange to me that adding code causes a type that was previously properly constrained to not longer be so. I'm not sure if it's a diagnostics issue, or if it should indeed be allowed...

See playground

rustc 1.62.0-nightly (a707f40 2022-04-29)

@rustbot label A-impl-trait F-type_alias_impl_trait

Activity

  1. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Apr 30, 2022
  2. self-assigned this
    on May 3, 2022
  3. oli-obk commented on May 3, 2022

    @oli-obk
    Contributor

    UPDATE: the below ICE is fixed now!

    I don't think we can really allow this. No pattern but a straight up binding is a valid pattern for an opaque type. If you actually give that pattern a type

    #![feature(type_alias_impl_trait)]
    
    fn main() {
        type T = impl Copy;
        let foo: T = (1u32, 2u32);
        let (a, b): (u32, u32) = foo;
    }

    then we get a lot of ICEs from borrowck. The interesting ones are

    error: internal compiler error: broken MIR in DefId(0:3 ~ inference[4f8b]::main) ((_1.0: u32)): can't project out of PlaceTy { ty: main::T, variant_index: None }
      --> /home/ubuntu/rust5/src/test/ui/type-alias-impl-trait/inference.rs:6:10
       |
    LL |     let (a, b): (u32, u32) = foo;
       |          ^
       |
       = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:855:31
    
    error: internal compiler error: broken MIR in DefId(0:3 ~ inference[4f8b]::main) ((_1.1: u32)): can't project out of PlaceTy { ty: main::T, variant_index: None }
      --> /home/ubuntu/rust5/src/test/ui/type-alias-impl-trait/inference.rs:6:13
       |
    LL |     let (a, b): (u32, u32) = foo;
       |             ^
       |
       = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:855:31
    

    These happen because we assume that if a pattern type checks, that we can actually destructure the thing that was moved into the pattern. Unfortunately for opaque types that isn't true.

    I guess the simple solution would be to just forbid it. We could try to allow it, but I'm not sure how to do that in general without just throwing more logic into match checking and mir building. Just patching the type of foo as seen in the pattern logic could work though... basically only touch mir typeck and verification/sanitation to teach them about the types inferred from patterns

  4. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on May 3, 2022
  5. added a commit that references this issue on May 7, 2022
  6. nikomatsakis commented on May 12, 2022

    @nikomatsakis
    Contributor

    UPDATE: the below ICE is fixed now!

    Other examples:

    #![feature(type_alias_impl_trait)]
    
    fn main() {
        type T = impl Copy;
        let foo: T = (1u32, 2u32);
        match foo {
            (a, b) => (),
        }
    }

    also gives an error (playground)

  7. nikomatsakis commented on May 12, 2022

    @nikomatsakis
    Contributor

    Also ICEs (playground):

    #![feature(type_alias_impl_trait)]
    
    fn main() {
        type T = impl Copy;
        let foo: T = Some((1u32, 2u32));
        match foo {
            None => (),
            Some((a, b)) => (),
        }
    }
  8. oli-obk commented on May 12, 2022

    @oli-obk
    Contributor

    triage:

    Implement a "opaque type downcast projection" in mir and insert appropriately

  9. JohnTitor commented on May 23, 2022

    @JohnTitor
    Member

    Triage: #96572 (comment) and #96572 (comment) are fixed by #96515. The last one (#96572 (comment)) is still ICE.

  10. added
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 28, 2022
  11. 6 remaining items

  12. moved this from Todo to In Progress in type alias impl trait stabilizationon Sep 9, 2022
  13. Repository owner moved this from In Progress to Done in type alias impl trait stabilizationon Sep 20, 2022
  14. added a commit that references this issue on Oct 6, 2022
    0dc24ca
  15. added a commit that references this issue on Oct 23, 2022
    6eeefe2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions