AST validation doesn't correctly deal with impls nested within associated functions (original) (raw)
The following programs get wrongfully rejected since my PR #119505 (nightly-2024-01-04):
pub struct S;
trait Trait { fn provided() { impl S { pub fn perform() {} //~ ERROR visibility qualifiers are not permitted here } } }
pub struct S; struct Expr;
trait Trait { fn required(_: Expr<{ impl S { pub fn perform() {} //~ ERROR visibility qualifiers are not permitted here } 0 }>); }
The following program was incorrectly rejected even before my PR #119505 (nightly-2024-01-04):
#![feature(const_trait_impl, effects)]
pub struct S;
#[const_trait] trait Trait { fn required(); }
impl const Trait for () { fn required() { impl S { pub fn perform() {} //~ ERROR visibility qualifiers are not permitted here } } }
The following programs lead to an ICE even before my PR (e.g., in nightly-2023-12-31):
#![feature(const_trait_impl, effects)]
pub struct S;
#[const_trait]
trait Trait {
fn provided() {
impl S {
fn perform<T: const Trait>() {} // should've gotten rejected during AST validation
//^ ICE no host param id for call in const yet no errors reported
}
}
}
#![feature(const_trait_impl, effects)]
pub struct S; struct Expr;
#[const_trait]
trait Trait {
fn required(_: Expr<{
impl S {
fn perform<T: const Trait>() {} // should've gotten rejected during AST validation
//^ ICE no host param id for call in const yet no errors reported
}
0
}>);
}
#![feature(const_trait_impl, effects)]
struct S; #[const_trait] trait Trait {}
const fn f<T: Trait<{
struct I<U: const Trait<0>>(U); // should've gotten rejected during AST validation
//^ ICE no host param id for call in const yet no errors reported
0
}>>() {}
There are many more issues and probably many more ways to reproduce this, e.g. we don't visit attributes on associated functions under certain circumstances (I couldn't find a reproducer yet in which you can observe the bug).