-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add macro test for min-const-generics #78912
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/ui/const-generics/min_const_generics/macro-fail.rs
This file contains hidden or 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,48 @@ | ||
#![feature(min_const_generics)] | ||
|
||
struct Example<const N: usize>; | ||
|
||
macro_rules! external_macro { | ||
() => {{ | ||
//~^ ERROR expected type | ||
const X: usize = 1337; | ||
X | ||
}} | ||
} | ||
|
||
trait Marker<const N: usize> {} | ||
impl<const N: usize> Marker<N> for Example<N> {} | ||
|
||
fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
//~^ ERROR wrong number of const | ||
//~| ERROR wrong number of type | ||
Example::<gimme_a_const!(marker)> | ||
//~^ ERROR wrong number of const | ||
//~| ERROR wrong number of type | ||
} | ||
|
||
fn from_marker(_: impl Marker<{ | ||
#[macro_export] | ||
macro_rules! inline { () => {{ 3 }} }; inline!() | ||
}>) {} | ||
|
||
fn main() { | ||
let _ok = Example::<{ | ||
#[macro_export] | ||
macro_rules! gimme_a_const { | ||
($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ||
//~^ ERROR expected type | ||
//~| ERROR expected type | ||
}; | ||
gimme_a_const!(run) | ||
}>; | ||
|
||
let _fail = Example::<external_macro!()>; | ||
//~^ ERROR wrong number of const | ||
//~| ERROR wrong number of type | ||
|
||
let _fail = Example::<gimme_a_const!()>; | ||
//~^ ERROR wrong number of const | ||
//~| ERROR wrong number of type | ||
//~| ERROR unexpected end of macro invocation | ||
} |
107 changes: 107 additions & 0 deletions
107
src/test/ui/const-generics/min_const_generics/macro-fail.stderr
This file contains hidden or 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,107 @@ | ||
error: expected type, found `{` | ||
--> $DIR/macro-fail.rs:33:27 | ||
| | ||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
| ---------------------- | ||
| | | ||
| this macro call doesn't expand to a type | ||
| in this macro invocation | ||
... | ||
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected type, found `{` | ||
--> $DIR/macro-fail.rs:33:27 | ||
| | ||
LL | Example::<gimme_a_const!(marker)> | ||
| ---------------------- | ||
| | | ||
| this macro call doesn't expand to a type | ||
| in this macro invocation | ||
... | ||
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected type, found `{` | ||
--> $DIR/macro-fail.rs:6:10 | ||
| | ||
LL | () => {{ | ||
| __________^ | ||
LL | | | ||
LL | | const X: usize = 1337; | ||
LL | | X | ||
LL | | }} | ||
| |___^ expected type | ||
... | ||
LL | let _fail = Example::<external_macro!()>; | ||
| ----------------- | ||
| | | ||
| this macro call doesn't expand to a type | ||
| in this macro invocation | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: unexpected end of macro invocation | ||
--> $DIR/macro-fail.rs:44:25 | ||
| | ||
LL | macro_rules! gimme_a_const { | ||
| -------------------------- when calling this macro | ||
... | ||
LL | let _fail = Example::<gimme_a_const!()>; | ||
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments | ||
|
||
error[E0107]: wrong number of const arguments: expected 1, found 0 | ||
--> $DIR/macro-fail.rs:16:26 | ||
| | ||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/macro-fail.rs:16:33 | ||
| | ||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument | ||
|
||
error[E0107]: wrong number of const arguments: expected 1, found 0 | ||
--> $DIR/macro-fail.rs:19:3 | ||
| | ||
LL | Example::<gimme_a_const!(marker)> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/macro-fail.rs:19:13 | ||
| | ||
LL | Example::<gimme_a_const!(marker)> | ||
| ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument | ||
|
||
error[E0107]: wrong number of const arguments: expected 1, found 0 | ||
--> $DIR/macro-fail.rs:40:15 | ||
| | ||
LL | let _fail = Example::<external_macro!()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/macro-fail.rs:40:25 | ||
| | ||
LL | let _fail = Example::<external_macro!()>; | ||
| ^^^^^^^^^^^^^^^^^ unexpected type argument | ||
|
||
error[E0107]: wrong number of const arguments: expected 1, found 0 | ||
--> $DIR/macro-fail.rs:44:15 | ||
| | ||
LL | let _fail = Example::<gimme_a_const!()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument | ||
|
||
error[E0107]: wrong number of type arguments: expected 0, found 1 | ||
--> $DIR/macro-fail.rs:44:25 | ||
| | ||
LL | let _fail = Example::<gimme_a_const!()>; | ||
| ^^^^^^^^^^^^^^^^ unexpected type argument | ||
|
||
error: aborting due to 12 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0107`. |
This file contains hidden or 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,57 @@ | ||
// run-pass | ||
#![feature(min_const_generics)] | ||
|
||
struct Example<const N: usize>; | ||
|
||
macro_rules! external_macro { | ||
() => {{ | ||
const X: usize = 1337; | ||
X | ||
}} | ||
} | ||
|
||
trait Marker<const N: usize> {} | ||
impl<const N: usize> Marker<N> for Example<N> {} | ||
|
||
fn make_marker() -> impl Marker<{ | ||
#[macro_export] | ||
macro_rules! const_macro { () => {{ 3 }} }; inline!() | ||
}> { | ||
Example::<{ const_macro!() }> | ||
} | ||
|
||
fn from_marker(_: impl Marker<{ | ||
#[macro_export] | ||
macro_rules! inline { () => {{ 3 }} }; inline!() | ||
}>) {} | ||
|
||
fn main() { | ||
let _ok = Example::<{ | ||
#[macro_export] | ||
macro_rules! gimme_a_const { | ||
($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ||
}; | ||
gimme_a_const!(run) | ||
}>; | ||
JulianKnodt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let _ok = Example::<{ external_macro!() }>; | ||
|
||
let _ok: [_; gimme_a_const!(blah)] = [0,0,0]; | ||
let _ok: [[u8; gimme_a_const!(blah)]; gimme_a_const!(blah)]; | ||
let _ok: [u8; gimme_a_const!(blah)]; | ||
|
||
let _ok: [u8; { | ||
#[macro_export] | ||
macro_rules! const_two { () => {{ 2 }} }; | ||
const_two!() | ||
}]; | ||
|
||
let _ok = [0; { | ||
#[macro_export] | ||
macro_rules! const_three { () => {{ 3 }} }; | ||
const_three!() | ||
}]; | ||
let _ok = [0; const_three!()]; | ||
|
||
from_marker(make_marker()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.