forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#130337 - BoxyUwU:anon_const_macro_call, r=cam…
…elid Fix anon const def-creation when macros are involved take 2 Fixes rust-lang#130321 There were two cases that rust-lang#129137 did not handle correctly: - Given a const argument `Foo<{ bar!() }>` in which `bar!()` expands to `N`, we would visit the anon const and then visit the `{ bar() }` expression instead of visiting the macro call. This meant that we would build a def for the anon const as `{ bar!() }` is not a trivial const argument as `bar!()` is not a path. - Given a const argument `Foo<{ bar!() }>` is which `bar!()` expands to `{ qux!() }` in which `qux!()` expands to `N`, it should not be considered a trivial const argument as `{{ N }}` has two pairs of braces. If we only looked at `qux`'s expansion it would *look* like a trivial const argument even though it is not. We have to track whether we have "unwrapped" a brace already when recursing into the expansions of `bar`/`qux`/any macro r? `@camelid`
- Loading branch information
Showing
15 changed files
with
210 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
macro_rules! y { | ||
() => { | ||
N | ||
}; | ||
} | ||
|
||
struct A<const N: usize>; | ||
|
||
fn foo<const N: usize>() -> A<{ y!() }> { | ||
A::<1> | ||
//~^ ERROR: mismatched types | ||
} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/trivial-const-arg-macro-braced-expansion.rs:10:5 | ||
| | ||
LL | fn foo<const N: usize>() -> A<{ y!() }> { | ||
| ----------- expected `A<N>` because of return type | ||
LL | A::<1> | ||
| ^^^^^^ expected `N`, found `1` | ||
| | ||
= note: expected struct `A<N>` | ||
found struct `A<1>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
macro_rules! y { | ||
() => { | ||
N | ||
//~^ ERROR: generic parameters may not be used in const operations | ||
}; | ||
} | ||
|
||
struct A<const N: usize>; | ||
|
||
#[rustfmt::skip] | ||
fn foo<const N: usize>() -> A<{{ y!() }}> { | ||
A::<1> | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/trivial-const-arg-macro-nested-braces-2.rs:3:9 | ||
| | ||
LL | N | ||
| ^ cannot perform const operation using `N` | ||
... | ||
LL | fn foo<const N: usize>() -> A<{{ y!() }}> { | ||
| ---- in this macro invocation | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions | ||
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 1 previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[rustfmt::skip] | ||
macro_rules! y { | ||
() => { | ||
{ N } | ||
//~^ ERROR: generic parameters may not be used in const operations | ||
}; | ||
} | ||
|
||
struct A<const N: usize>; | ||
|
||
fn foo<const N: usize>() -> A<{ y!() }> { | ||
A::<1> | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/trivial-const-arg-macro-nested-braces.rs:4:11 | ||
| | ||
LL | { N } | ||
| ^ cannot perform const operation using `N` | ||
... | ||
LL | fn foo<const N: usize>() -> A<{ y!() }> { | ||
| ---- in this macro invocation | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions | ||
= note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 1 previous error | ||
|
9 changes: 9 additions & 0 deletions
9
tests/ui/const-generics/early/trivial-const-arg-nested-braces.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
struct A<const N: usize>; | ||
|
||
#[rustfmt::skip] | ||
fn foo<const N: usize>() -> A<{ { N } }> { | ||
//~^ ERROR: generic parameters may not be used in const operations | ||
A::<1> | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui/const-generics/early/trivial-const-arg-nested-braces.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/trivial-const-arg-nested-braces.rs:4:35 | ||
| | ||
LL | fn foo<const N: usize>() -> A<{ { N } }> { | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions | ||
|
||
error: aborting due to 1 previous error | ||
|