Skip to content

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

Closed
@lcnr

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.

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