Skip to content

Assoc const equality bounds aren't taken into consideration when normalizing const projections #120905

New issue

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

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

Already on GitHub? # to your account

Open
fmease opened this issue Feb 11, 2024 · 2 comments
Assignees
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Feb 11, 2024

For example, I expected the following code to succeed compilation:

#![feature(generic_const_exprs)]
#![feature(associated_const_equality)]

trait Trait {
    const C: usize;
}

fn f<T: Trait<C = 1>>()
where
    [(); T::C]:
{
    let _: [(); T::C] = [()];
}

Since (I'm pretty sure that) the ParamEnv contains the projection predicate <T as Trait>::C == 1, the const projection <T as Trait>::C inside the function body should be able to get normalized to 1. That however doesn't seem to happen:

error[E0308]: mismatched types
  --> src/lib.rs:12:25
   |
12 |     let _: [(); T::C] = [()];
   |                         ^^^^ expected `T::C`, found `1`
   |
   = note: expected constant `T::C`
              found constant `1`
@fmease fmease added A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue. F-associated_const_equality `#![feature(associated_const_equality)]` labels Feb 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@fmease fmease changed the title Assoc const equality bounds inside the ParamEnv aren't taken into consideration during the normalization of const projections Assoc const equality bounds aren't taken into consideration for the normalization of const projections Feb 11, 2024
@fmease fmease changed the title Assoc const equality bounds aren't taken into consideration for the normalization of const projections Assoc const equality bounds aren't taken into consideration when normalizing const projections Feb 11, 2024
@fmease fmease added the F-generic_const_exprs `#![feature(generic_const_exprs)]` label Feb 11, 2024
@fmease
Copy link
Member Author

fmease commented Nov 20, 2024

TODO: Find a reproducer that isn't reliant on GCE. Reliance on mGCE/mGCA (min_generic_const_args) is fine on the other hand (once that's implemented).

@fmease
Copy link
Member Author

fmease commented Jan 29, 2025

After poking around some more, I've come to the same conclusion that this requires extending the normalization rules of UnevaluatedConst (const projections).

Like, rustc_trait_selection::traits::try_evaluate_const which is the entry point we're interested in I think doesn't do much except deferring "overly generic" const projects (where are those ultimately solved though? I couldn't find that out (try_evaluated_const again?)) or delegating normalization to the const evaluation machinery.

I presume what we would want to assemble some other candidates in try_evaluate_const (?) like we do for type projections. Most importantly ParamEnv candidates (cf. rustc_trait_selection::traits::project::assemble_candidates_from_param_env) and perform some sort of selection. Nothing feels like the right place though but that's likely because I don't know enough yet. Esp. due to the const projection deferral. I don't want to touch anything rn because this is GCE→(m)GCA territory and maybe also next-solver territory (in the sense that we likely want to implement that in the next solver only because doing so in the old solver (too) would be wasted effort and overly complex and fragile).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
Development

No branches or pull requests

2 participants