Skip to content

cortex-m-semihosting: make semihosting macros compatible with 1-arg format strings #591

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

Conversation

suaviloquence
Copy link
Contributor

Fixes #581

};
($s:expr, $($tt:tt)*) => {
$crate::export::hstderr_fmt(format_args!(concat!($s, "\n"), $($tt)*))
$crate::export::hstderr_fmt(format_args!("{}\n", format_args!($s, $($tt)*)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double nested format_args! required here? Was there some use case that didn't work with the previous method of using concat!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry I meant to take a note of it - format_args! doesn't expand captures in the format string literal if it is generated by a macro:

Playground link

From rust-lang/rust#106824, it should get flattened into a single format_args!/Arguments call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes - thanks for the clarification.

@jonathanpallant
Copy link
Contributor

As a point of reference, the semihosting crate does it like this: https://docs.rs/semihosting/0.1.18/src/semihosting/macros.rs.html.

You could make the argument we should deprecate this crate and recommend people use that one.

@suaviloquence
Copy link
Contributor Author

Anything else I need to do on this PR?

@jonathanpallant
Copy link
Contributor

No, it's all good. I was just letting others have a chance to weigh in.

@jonathanpallant jonathanpallant added this pull request to the merge queue Apr 24, 2025
Merged via the queue into rust-embedded:master with commit c3d664b Apr 24, 2025
11 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cortex-m-semihosting: hprint! family of macros do not format strings without arguments
2 participants