Skip to content

Failure to parse for<'a> [const] Trait syntax #20276

@clarfonthey

Description

@clarfonthey

rust-analyzer version: rust-analyzer 1 (0ac65592a8 2025-07-06)

rustc version: 1.90.0-nightly (a00149764 2025-07-14)

editor or extension: kakoune + kak-lsp

relevant settings: none

repository link (if public, optional): rust-lang/rust

code snippet to reproduce:

#[inline]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
const fn chaining_impl<'l, 'r, A: [const] PartialOrd, B, C>(
    left: &'l [A],
    right: &'r [A],
    elem_chain: impl [const] Fn(&'l A, &'r A) -> ControlFlow<B> + [const] Destruct,
    len_chain: impl [const] Destruct + for<'a> [const] FnOnce(&'a usize, &'a usize) -> ControlFlow<B, C>,
) -> ControlFlow<B, C> {
    let l = cmp::min(left.len(), right.len());

    // Slice to the loop iteration range to enable bound check
    // elimination in the compiler
    let lhs = &left[..l];
    let rhs = &right[..l];

    for i in 0..l {
        elem_chain(&lhs[i], &rhs[i])?;
    }

    len_chain(&left.len(), &right.len())
}

Ran into this case when trying to constify PartialOrd in the main rust-lang repo. Rust correctly parses this case (and recovers when seeing [const] for<'a>, requesting you to swap the two), but R-A fails in both cases.

(Side note: I am aware this code also doesn't compile for other reasons. It's just that a syntax error showed up and I wanted to report it.)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions