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

Syntax Error: expected comma when RA + HRTB + const trait #19478

Open
loynoir opened this issue Mar 30, 2025 · 3 comments
Open

Syntax Error: expected comma when RA + HRTB + const trait #19478

loynoir opened this issue Mar 30, 2025 · 3 comments
Labels
A-parser parser issues C-bug Category: bug

Comments

@loynoir
Copy link

loynoir commented Mar 30, 2025

BUG

Syntax Error: expected comma when RA + HRTB + const trait

Detail

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer version: 1.87.0-nightly (3f55023 2025-03-27) [/home/vscode/.rustup/toolchains/nightly-2025-03-28-x86_64-unknown-linux-gnu/bin/rust-analyzer]

rustc version: (eg. output of rustc -V)

rustc 1.87.0-nightly (3f5502370 2025-03-27)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)

vscode

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

#![feature(const_destruct)]
#![feature(const_trait_impl)]
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>
            + ~const std::marker::Destruct,
    {
        let delta = T::const_from(42u8);

        x.const_add_assign(&delta)
    }
}

Related

Prev

rust-lang/rust#139134 (comment)

@loynoir loynoir added the C-bug Category: bug label Mar 30, 2025
@ChayimFriedman2
Copy link
Contributor

I believe the const trait syntax is being reworked, so there is no point in supporting it now.

@ChayimFriedman2 ChayimFriedman2 added the A-parser parser issues label Mar 30, 2025
@loynoir
Copy link
Author

loynoir commented Mar 30, 2025

@ChayimFriedman2

But parser Syntax Error is very very critial, which makes editor red and unusable, and cannot workaround with feature guard.

    #[cfg(not(feature = "RA"))]
    pub const fn const_incr42<T>(mut x: T)
    where
        T: ~const ConstFrom<u8>
            + for<'a> ~const ConstAddAssign<&'a T>
            + ~const core::marker::Destruct,
    {
        let delta = T::const_from(42u8);

        x.const_add_assign(&delta)
    }

Quote @ChayimFriedman2

I believe the const trait syntax is being reworked, so there is no point in supporting it now.

@fmease

What do you think?

Thank you.

@fmease
Copy link
Member

fmease commented Mar 31, 2025

I believe the const trait syntax is being reworked, so there is no point in supporting it now.

I don't completely disagree with this statement since the const_trait_impl feature is considered quite experimental as its implementation has completely changed several times over the last years and still doesn't have an approved RFC backing it, so I think I can safely say as an outsider that it likely represents a certain 'risk' for the rust-analyzer team to support it (in whatever capacity) ('risk' as in potentially wasted people hours).

Moreover, const_trait_impl isn't even that convenient to use right now since most core and std trait impls are no longer unstably const due to the aforementioned rewrites and since we, the project group const traits, have decided to block further trait impl constifications on the new RFC 3762. So the user base is not that huge currently.

And lastly, yeah, the syntax is being reworked (see the RFC) to the point that it's absolutely not clear yet how it'll end up looking.


However, I do have to note that rust-analyzer does seem to be able to parse impl const … { … }, const Trait bounds and ~const Trait bounds. It's just that it fails to parse for<…> ~const Trait bounds (which might look like for<…> (const) Trait in the future). If T-rust-analyzer{,-contributors} decide they don't want fix that problem for now, I will respect that personally speaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser parser issues C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants