Skip to content

hir typeck overwrites multiple defining uses of the same opaque #110601

Closed

Description

@lcnr
#![feature(type_alias_impl_trait)]
type Tait<T> = impl Sized;

fn foo<T, U>(x: T) {
    loop {
        break;
        let _: Tait<U> = String::new();
    }
    let _: Tait<T> = x;
}

this passes but should error. The issue is that when writing the opaque type into the TypeckResults we drop the previous entry without comparing them for equality.

self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);

normally this would get caught by borrowck which does handle them correctly, however Tait<U> is defined in unreachable code so mir borrowck does not catch this.

we do explicitly check that the opaques from unreachable code are equal to the reachable ones but this check uses the opaques from hir typeck which means we again ignore Tait<U> there.

Activity

  1. changed the title [-]hir typeck overwrites multiple definitions of the same opaque[/-] [+]hir typeck overwrites multiple defining uses of the same opaque[/+] on Apr 20, 2023
  2. lcnr commented on May 25, 2023

    @lcnr
    ContributorAuthor

    fixed by #111853 which also added tests for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions