Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcnr opened this issue Apr 20, 2023 · 1 comment
Closed

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

lcnr opened this issue Apr 20, 2023 · 1 comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`

Comments

@lcnr
Copy link
Contributor

lcnr commented Apr 20, 2023

#![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.

@lcnr lcnr added C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Apr 20, 2023
@lcnr lcnr changed the title hir typeck overwrites multiple definitions of the same opaque hir typeck overwrites multiple defining uses of the same opaque Apr 20, 2023
@lcnr
Copy link
Contributor Author

lcnr commented May 25, 2023

fixed by #111853 which also added tests for this

@lcnr lcnr closed this as completed May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`
Projects
None yet
Development

No branches or pull requests

1 participant