-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Deprecated tracking issue for closed RFC 2632, impl const Trait for Ty
and ~const
(tilde const) syntax (const_trait_impl
)
#67792
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
Comments
impl const Trait for Ty
syntaximpl const Trait for Ty
impl const Trait for Ty
impl const Trait for Ty
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
Parse the syntax described in RFC 2632 This adds support for both `impl const Trait for Ty` and `?const Trait` bound syntax from rust-lang/rfcs#2632 to the parser. For now, both modifiers end up in a newly-added `constness` field on `ast::TraitRef`, although this may change once the implementation is fleshed out. I was planning on using `delay_span_bug` when this syntax is encountered during lowering, but I can't write `should-ice` UI tests. I emit a normal error instead, which causes duplicates when the feature gate is not enabled (see the `.stderr` files for the feature gate tests). Not sure what the desired approach is; Maybe just do nothing when the syntax is encountered with the feature gate is enabled? @oli-obk I went with `const_trait_impl` and `const_trait_bound_opt_out` for the names of these features. Are these to your liking? cc rust-lang#67792 rust-lang#67794 r? @Centril
Allow trait methods to be called on concrete types in a const context This partially implements [RFC 2632](rust-lang/rfcs#2632) by const-checking methods inside an `impl const` block and allowing those methods to be called on concrete types. Calling trait methods on type parameters in a const context is not yet allowed. Implementing this will require much more work. Since we are only concerned with methods on concrete types, we are able to take advantage of the machinery in `Instance::resolve`, which is doing most of the work. This also propagates `#[rustc_const_unstable]` from parent items to child items, making that attribute behave like `#[stable]` and `#[unstable]` do. This allows trait methods to be marked as unstably const. cc #67792 #57563 cc @rust-lang/wg-const-eval r? @oli-obk
=== stdout === === stderr === warning: the feature `const_trait_impl` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/69487.rs:1:12 | 1 | #![feature(const_trait_impl)] | ^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #67792 <rust-lang/rust#67792> for more information error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple --> /home/runner/work/glacier/glacier/ices/69487.rs:10:5 | 10 | extern "rust-call" fn call_once(self, arg: &usize) -> Self::Output { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error; 1 warning emitted ==============
impl const Trait for Ty
and ~const
(tilde const) syntaximpl const Trait for Ty
and ~const
(tilde const) syntax (const_trait_impl
)
This comment has been minimized.
This comment has been minimized.
I think the new RFC should get a new tracking issue (once it gets accepted). There's too much no-longer-relevant history in this one.
|
What about HRTB? Fail to compile when HRTB + const trait pub mod reproduce {
#[const_trait]
pub trait ConstFrom<T>: Sized {
#[must_use]
fn const_from(value: T) -> Self;
}
#[const_trait]
pub trait ConstAddAssign<Rhs = Self> {
fn const_add_assign(&mut self, rhs: Rhs);
}
pub fn incr42<T>(mut x: T)
where
T: const ConstFrom<u8> + for<'a> ConstAddAssign<&'a T>,
{
let delta = T::const_from(42u8);
x.const_add_assign(&delta)
}
pub const fn const_incr42<T>(mut x: T)
where
T: const ConstFrom<u8> + for<'a> const ConstAddAssign<&'a T>,
{
let delta = T::const_from(42u8);
x.const_add_assign(&delta)
}
} |
The Bound must be |
Still not able to compile. pub const fn const_incr42<T>(mut x: T)
where
T: ~const ConstFrom<u8> + for<'a> ~const ConstAddAssign<&'a T>,
{
let delta = T::const_from(42u8);
x.const_add_assign(&delta)
} |
Hmm, I can't find a quick solution. I spent some time looking into the |
@quratoop You need to also add the bound This is a tracking issue, for the record. If you have a bug with a specific feature, please open a new issue! If you want to discuss the implementation, please also open a new issue and it can be tagged C-discussion. Tracking issues have a linear history so they are not conducive to any kind of discussion. CC'ing the new RFC, RFC 3762, again, for which we would open a new tracking issue on approval as Ralf wrote. |
impl const Trait for Ty
and ~const
(tilde const) syntax (const_trait_impl
)impl const Trait for Ty
and ~const
(tilde const) syntax (const_trait_impl
)
NOTE: See #110395, which tracks a planned rewrite of this feature's implementation
This is the primary tracking issue for rust-lang/rfcs#2632.
The current RFC text can be found at https://internals.rust-lang.org/t/pre-rfc-revamped-const-trait-impl-aka-rfc-2632/15192
This RFC has not yet been accepted. It is being implemented on a provisional basis to evaluate the potential fallout.
cc #57563
The feature gate is
const_trait_impl
.Components
#[const_trait]
attributeimpl const Trait
T: ~const Trait
append_const_msg
onrustc_on_unimplemented
#[derive_const]
trait Destruct
Open issues
const fn
with aTrait
bound even if the concrete type does not implementconst Trait
, but justTrait
. This will fail later during evaluation. Some related discussion can be found in Allow using generic trait methods inconst fn
#79287 (comment)const impl
without defining one without the feature gate enabled. This should be added before anyimpl const
is added to the standard library.#[rustc_const_stable]
and#[rustc_const_unstable]
so we can properly stabilize (or not) the constness of impls in the standard libraryimpl const
wrongly accepts impl with non-const provided methods #79450 shows that with default function bodies in the trait declaration, we can cause non-const functions to exist inimpl const Trait
impls by leaving out these default functions~const
. (In the interim, we may want to switch this to use ak#provisional_keyword
or similar.)#[default_method_body_is_const]
, determine the syntax for it instead of existing as an attribute#[derive_const]
for custom derives (proc macros) Provide a way for derives to know if they were invoked with#[derive_const]
#118304110395
and figure out what to do everywhere that issue is mentioned (this is old stuff left over from when the previous const trait impl was removed)When stabilizing: compiler changes are required:
rustc_const_unstable
attribute onconst
impl
s as they are now insta-stable.default_method_body_is_const
bodies andconst
impl
bodies asstable
const fn
bodies. We need to prevent accidentally stabilizing an implementation that uses unstable lang/libconst fn
features.~const
bounds or what syntax we decided it to be.The text was updated successfully, but these errors were encountered: