Skip to content

gce: try_unify doesn't always ignore lifetimes #98452

Closed
@lcnr

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions