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

gce: try_unify doesn't always ignore lifetimes #98452

Closed
lcnr opened this issue Jun 24, 2022 · 1 comment · Fixed by #98499
Closed

gce: try_unify doesn't always ignore lifetimes #98452

lcnr opened this issue Jun 24, 2022 · 1 comment · Fixed by #98499
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]`

Comments

@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

struct Num<const N: usize>;

trait NumT {
    const VALUE: usize;
}

impl<const N: usize> NumT for Num<N> {
    const VALUE: usize = N;
}

struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;

trait Bar {
    type Size: NumT;

    fn bar<'a>(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
        todo!();
    }
}

trait Baz<'a> {
    type Size: NumT;

    fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
        todo!();
    }
}

results in

error: unconstrained generic constant
  --> src/lib.rs:27:17
   |
27 |     fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
   |                 ^^^^^^^^^^^^^^^^^^^^
   |
   = help: try adding a `where` bound using this expression: `where [(); N::VALUE]:`
note: required by a bound in `Foo`
  --> src/lib.rs:14:57
   |
14 | struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;
   |                                                         ^^^^^^^^ required by this bound in `Foo`

but should compile.

I assume that the error is caused by this structural comparison here

(ty::ConstKind::Unevaluated(a_uv), ty::ConstKind::Unevaluated(b_uv)) => {
a_uv == b_uv
}

We probably want to erase lifetimes at some earlier point, probably during the construction of the AbstractConsts.

@lcnr lcnr added C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Jun 24, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 29, 2022
Erase regions in New Abstract Consts

When an abstract const is constructed, we previously included lifetimes in the set of substitutes, so it was not able to unify two abstract consts if their lifetimes did not match but the values did, despite the values not depending on the lifetimes. This caused code that should have compiled to not compile.

Fixes rust-lang#98452

r? `@lcnr`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 29, 2022
Erase regions in New Abstract Consts

When an abstract const is constructed, we previously included lifetimes in the set of substitutes, so it was not able to unify two abstract consts if their lifetimes did not match but the values did, despite the values not depending on the lifetimes. This caused code that should have compiled to not compile.

Fixes rust-lang#98452

r? ``@lcnr``
@bors bors closed this as completed in 7b9a7ef Jun 29, 2022
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-generic_const_exprs `#![feature(generic_const_exprs)]`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant