Skip to content

AST validation doesn't correctly deal with impls nested within associated functions #119924

Open

Description

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<const N: u32>;

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 N: u32>;

#[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 N: u32> {}

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions