Skip to content

const_evaluatable_checked can cause a stackoverflow #79615

Closed
@lcnr

Description

@lcnr

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6bdb59061285589534c53004561c978a

#![feature(const_generics, const_evaluatable_checked)]

fn q<T, const N: usize>(_: T) -> [u8; N + 1] {
    todo!()
}

fn supplier<T>() -> T {
    todo!()
}

fn catch_me<const N: usize>() where [u8; N + 1]: Default {
    let mut x = supplier();
    x = q(x);
}

causes

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
error: could not compile `playground`

(it does ICE with incremental enabled, this is a different bug and tracked separately)

We end up referencing an inference variable in the value of said inference variable, causing an infinite type.
This should ordinarily be prevented by the occurs check. We either have a bug there or there is something else I have missed

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`F-generic_const_exprs`#![feature(generic_const_exprs)]`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions