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

Consider redefining the places ~const bounds are allowed #102497

Open
fee1-dead opened this issue Sep 30, 2022 · 7 comments
Open

Consider redefining the places ~const bounds are allowed #102497

fee1-dead opened this issue Sep 30, 2022 · 7 comments
Labels
F-const_trait_impl `#![feature(const_trait_impl)]`

Comments

@fee1-dead
Copy link
Member

At #102409 (comment), it was pointed out that associated functions can have ~const bounds even though they may be non-const. We need to figure out and define what places ~const should be allowed. Note that since ~const only applies more restrictions on callers that are const, putting them on non-const fns has no effect.

@fee1-dead fee1-dead added the F-const_trait_impl `#![feature(const_trait_impl)]` label Sep 30, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Sep 30, 2022

Why can't we just forbid it on non const assoc fns?

@fee1-dead
Copy link
Member Author

fee1-dead commented Sep 30, 2022

Yes we can. I was also thinking about impl<T: ~const Tr> SomeType {} so that all const fns inherit this bound.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 30, 2022

Ah yea, seems ok as long as we have an unused ~const lint for the case where nothing uses it

@onestacked
Copy link
Contributor

Yes we can. I was also thinking about impl<T: ~const Tr> SomeType {} so that all const fns inherit this bound.

I think that would make a lot of const code a bit cleaner.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 11, 2023

I tried implementing this with effects, but it's a bit messy. Right now, we desugar

impl SomeType {
    const fn foo<T: ~const Trait>() {}
}

to

impl SomeType {
    fn foo<effect C: constness, T: Trait<C>>() {}
}

but in order to allow

impl<T: ~const Tr> SomeType {
    const fn foo() {}
}

to use the <T as ~const Tr> information, we'd need an effect available on the impl level, so

impl<effect C: constness, T: Tr<C>> SomeType {
    const fn foo() {}
    fn bar() {}
}

but then non-const fns like bar now suddenly have const effects in their generics. This all seems resolvable, but I'm going to mark the existing test as // known-bug pointing to this issue and look into this again once the rest works reliably

@fee1-dead
Copy link
Member Author

Can we ignore the constness effect in non-const contexts?

@oli-obk
Copy link
Contributor

oli-obk commented Jan 11, 2023

Can we ignore the constness effect in non-const contexts?

The current design treats the presence of a constness effect as the source of truth for whether a function is const fn. I tried going back to the existing constness/is_const_fn_raw checks, but that turned out to cause lots of problems in other situations so I stopped pursuing this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]`
Projects
None yet
Development

No branches or pull requests

3 participants