-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Stop compilation early if macro expansion failed #144409
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
Merged
bors
merged 3 commits into
rust-lang:master
from
GuillaumeGomez:macro-expansion-early-abort
Jul 27, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
23 changes: 23 additions & 0 deletions
23
tests/ui/const-generics/min_const_generics/macro-fail-const.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,23 @@ | ||
trait Marker<const N: usize> {} | ||
struct Example<const N: usize>; | ||
impl<const N: usize> Marker<N> for Example<N> {} | ||
|
||
fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
//~^ ERROR: type provided when a constant was expected | ||
//~| ERROR: type provided when a constant was expected | ||
Example::<gimme_a_const!(marker)> | ||
//~^ ERROR: type provided when a constant was expected | ||
} | ||
|
||
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 _ok = Example::<{gimme_a_const!(marker)}>; | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/ui/const-generics/min_const_generics/macro-fail-const.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,51 @@ | ||
error: expected type, found `{` | ||
--> $DIR/macro-fail-const.rs:16: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 the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: expected type, found `{` | ||
--> $DIR/macro-fail-const.rs:16: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 the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0747]: type provided when a constant was expected | ||
--> $DIR/macro-fail-const.rs:5:33 | ||
| | ||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0747]: type provided when a constant was expected | ||
--> $DIR/macro-fail-const.rs:5:33 | ||
| | ||
LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0747]: type provided when a constant was expected | ||
--> $DIR/macro-fail-const.rs:8:13 | ||
| | ||
LL | Example::<gimme_a_const!(marker)> | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0747`. |
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
|
||
fn main() { | ||
println!("Hello, World!"); | ||
//~^ NOTE trace_macro | ||
//~| NOTE expanding `println! | ||
//~| NOTE to `{ | ||
} |
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,22 @@ | ||
#![feature(builtin_syntax)] | ||
|
||
use std::mem::offset_of; | ||
|
||
fn main() { | ||
offset_of!((u8, u8), _0); //~ ERROR no field `_0` | ||
offset_of!((u8, u8), 01); //~ ERROR no field `01` | ||
offset_of!((u8, u8), 1e2); //~ ERROR no field `1e2` | ||
offset_of!((u8, u8), 1_u8); //~ ERROR no field `1_` | ||
//~| ERROR suffixes on a tuple index | ||
|
||
builtin # offset_of((u8, u8), 1e2); //~ ERROR no field `1e2` | ||
builtin # offset_of((u8, u8), _0); //~ ERROR no field `_0` | ||
builtin # offset_of((u8, u8), 01); //~ ERROR no field `01` | ||
builtin # offset_of((u8, u8), 1_u8); //~ ERROR no field `1_` | ||
//~| ERROR suffixes on a tuple index | ||
|
||
offset_of!(((u8, u16), (u32, u16, u8)), 0.2); //~ ERROR no field `2` | ||
offset_of!(((u8, u16), (u32, u16, u8)), 0.1e2); //~ ERROR no field `1e2` | ||
offset_of!(((u8, u16), (u32, u16, u8)), 1.2); | ||
offset_of!(((u8, u16), (u32, u16, u8)), 1.2.0); //~ ERROR no field `0` | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.