Skip to content

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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

suaviloquence
Copy link

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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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