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

Conditionally const bounds (~const) in inherent impl headers #11

Open
fmease opened this issue Oct 25, 2024 · 1 comment
Open

Conditionally const bounds (~const) in inherent impl headers #11

fmease opened this issue Oct 25, 2024 · 1 comment

Comments

@fmease
Copy link
Member

fmease commented Oct 25, 2024

Decide once and for all if we want to support ~const bounds in inherent impl headers:

//@ check-fail
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl, effects)]
#![crate_type = "lib"]

#[const_trait] trait Bound { fn f(); }
struct Ty<T>(T);     

impl<T: ~const Bound> Ty<T> {
//      ^^^^^^^^^^^^
    const fn g() { T::f() }
}

Indeed back when we had the earliest const host: bool desugaring, we decided to reject them and to this day we reject them during AST validation. See rust-lang/rust#117817 (comment) and rust-lang/rust#119059. We currently require the user to move the ~const bound from the impl header to the associated function:

//@ check-pass

// ...

impl<T> Ty<T> {
    const fn g() where T: ~const Bound { T::f() }
//                        ^^^^^^^^^^^^
}

I think the biggest reason was the fact that you couldn't represent this in the old desugaring because you couldn't really couple the host effect param for Bound with the one of <T> Ty::<T>::g. Indeed, it's a bit backwards.

It might be worthwhile to revisit this decision now that we have a different representation. I could be far off base here, though. Feel free to correct me.

@compiler-errors
Copy link
Member

I'm not sold that it's useful, though it would I guess be doable. We should at least warn if a non-conditionally-const item exists in a impl with ~const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants