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

textDocument/semanticTokens/etc. GAT failure on latest pre-release #11989

Closed
stijnfrishert opened this issue Apr 14, 2022 · 2 comments · Fixed by #13021
Closed

textDocument/semanticTokens/etc. GAT failure on latest pre-release #11989

stijnfrishert opened this issue Apr 14, 2022 · 2 comments · Fixed by #13021
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@stijnfrishert
Copy link

  1. Create an empty binary cargo project with the nightly toolchain
  2. Put the following code in main:
#![feature(generic_associated_types)]

pub trait Processor {
    type Ctx<'a, const N: usize>;

    fn process<const N: usize>(&mut self, ctx: Self::Ctx<'_, N>);
}

#[derive(Default, Debug)]
pub struct Phasor {
    phase: f32,
}

pub struct PhasorCtx<'a, const N: usize> {
    increments: &'a [f32; N],
    output: &'a mut [f32; N],
}

impl Processor for Phasor {
    type Ctx<'a, const N: usize> = PhasorCtx<'a, N>;

    fn process<const N: usize>(&mut self, ctx: Self::Ctx<'_, N>) {
        for i in 0..N {
            ctx.output[i] = self.phase;
            self.phase += ctx.increments[i];
            if self.phase > 1.0 {
                self.phase -= self.phase as i32 as f32;
            }
        }
    }
}

fn main() {
    println!("Hello, world!");
}

I'm getting errors like textDocument/semanticTokens/full, textDocument/semanticTokens/full/delta, textDocument/inlayHints and textDocument/definition failed every time I start typing.

I know several GAT issues have already been solved, but I'm working with a pre-release version from 2 days ago. Assuming this fix already made it in 3 days ago I'm still running into issues and thought this warranted an issue report. :)

rust-analyzer version: rust-analyzer version: faaec86 2022-04-12 nightly
rustc version: rustc 1.61.0-nightly (c84f39e6c 2022-03-20)

@jonas-schievink jonas-schievink added A-ty type system / type inference / traits / method resolution S-actionable Someone could pick this issue up and work on it right now C-bug Category: bug labels Apr 14, 2022
@skyzh
Copy link
Contributor

skyzh commented Apr 14, 2022

A combination of const generics and GAT might be the cause of this issue. My fix only bypasses the case for GAT without const generics 🤣

@Nugine
Copy link

Nugine commented Jul 17, 2022

pub trait Select {
    type Output<'a, T>
    where
        T: 'a,
        Self: 'a;
    fn select<'a, T>(self, slice: &'a [T]) -> Self::Output<'a, T>
    where
        Self: 'a;
}

impl<const N: usize> Select for [usize; N] {
    type Output<'a, T> = impl Iterator<Item=&'a T> + 'a where T:'a;

    fn select<'a, T>(self, slice: &'a [T]) -> Self::Output<'a, T>
    where
        Self: 'a,
    {
        self.into_iter().map(move |i| &slice[i])
    }
}

rust-analyzer 0.0.0 (766c5f0 2022-07-16)
rustc 1.62.0 (a8314ef7d 2022-06-27)

N3xed added a commit to N3xed/rust-analyzer that referenced this issue Aug 14, 2022
This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics.
Additionally, I've added the `is_gat` field to `utils::Generics` that determines whether missing
generics params crashes rust analyzer. Another solution would have been to remove all panics
from the relevant code path regardless of whether the generics is on a GAT, but this could
change behavior outside of GATs.

Fixes rust-lang#11989, fixes rust-lang#12193
bors added a commit that referenced this issue Aug 21, 2022
fix: Fix panics on GATs involving const generics

This workaround avoids constant crashing of rust analyzer when using GATs with const generics,
even when the const generics are only on the `impl` block.

The workaround treats GATs as non-existing if either itself or the parent has const generics and
removes relevant panicking code-paths.
~~Additionally, I've added the `is_gat` field to `utils::Generics` that determines whether missing
generics params crashes rust analyzer. Another solution would have been to remove all panics
from the relevant code path regardless of whether the generics are on a GAT, but this could
change behavior outside of GATs.~~

Fixes #11989, fixes #12193
@bors bors closed this as completed in fdc28b4 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants