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

Fix and slightly improve AstValidator #120698

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
389 changes: 212 additions & 177 deletions compiler/rustc_ast_passes/src/ast_validation.rs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions tests/ui/parser/semantic/impls-nested-within-fns-semantic-0.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for issue #119924.
// check-pass

pub struct Type;

trait Trait {
fn provided() {
impl Type {
// This visibility qualifier used to get rejected.
pub fn perform() {}
}
}
}

fn main() {}
21 changes: 21 additions & 0 deletions tests/ui/parser/semantic/impls-nested-within-fns-semantic-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Regression test for issue #119924.
// check-pass
#![feature(const_trait_impl, effects)]

pub struct Type;

#[const_trait]
trait Trait {
fn required();
}

impl const Trait for () {
fn required() {
impl Type {
// This visibility qualifier used to get rejected.
pub fn perform() {}
}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Regression test for issues #119924 and #89342.
// check-pass

struct Type;
struct Expr<const N: u32>;

trait Trait0 {
fn required(_: Expr<{
impl Type {
// This visibility qualifier used to get rejected.
pub fn perform() {}
}
0
}>);
}

trait Trait1 {}

impl Trait1 for ()
where
[(); {
impl Type {
// This visibility qualifier used to get rejected.
pub const STORE: Self = Self;
}
0
}]:
{}

trait Trait2<const B: bool> {}

fn f(_: impl Trait2<{
// This impl-Trait used to get rejected as "nested" impl-Trait.
fn g(_: impl Sized) {}
false
}>) {}

fn scope() {
let _: <Parametrized<{
// This impl-Trait used get rejected with "not allowed in path parameters".
fn run(_: impl Sized) {}
0
}> as Trait3>::Projected;
}

trait Trait3 { type Projected; }
struct Parametrized<const N: usize>;

impl<const N: usize> Trait3 for Parametrized<N> { type Projected = (); }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Regression test for issue #119924.
#![feature(const_trait_impl, effects)]
#![allow(incomplete_features)]

pub struct Type;

#[const_trait]
trait Trait0 {
fn provided() {
impl Type {
fn perform<T: ~const Trait0>() {}
//~^ ERROR `~const` is not allowed here
}
}
}

struct Expr<const N: u32>;

#[const_trait]
trait Trait1 {
fn required(_: Expr<{
impl Type {
fn compute<T: ~const Trait1>() {}
//~^ ERROR `~const` is not allowed here
}
0
}>);
}

#[const_trait]
trait Trait2<const N: u32> {}

const fn operate<T: Trait2<{
struct I<U: ~const Trait2<0>>(U);
//~^ ERROR `~const` is not allowed here
0
}>>() {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places-nested.rs:11:27
|
LL | fn perform<T: ~const Trait0>() {}
| ^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/tilde-const-invalid-places-nested.rs:11:16
|
LL | fn perform<T: ~const Trait0>() {}
| ^^^^^^^

error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places-nested.rs:23:27
|
LL | fn compute<T: ~const Trait1>() {}
| ^^^^^^
|
note: this function is not `const`, so it cannot have `~const` trait bounds
--> $DIR/tilde-const-invalid-places-nested.rs:23:16
|
LL | fn compute<T: ~const Trait1>() {}
| ^^^^^^^

error: `~const` is not allowed here
--> $DIR/tilde-const-invalid-places-nested.rs:34:17
|
LL | struct I<U: ~const Trait2<0>>(U);
| ^^^^^^
|
= note: this item cannot have `~const` trait bounds

error: aborting due to 3 previous errors