-
Notifications
You must be signed in to change notification settings - Fork 13.3k
macros: it is possible to downcast a tt
to most anything using nested macros
#16036
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
Comments
tt
tt
to most anything using nested macros
I'm not sure I understand
Could you clarify? (The doc comment is an attribute that ends up attached to the |
Triaging: I was not able to compile on nightly. The code needed some
#![feature(macro_rules)]
macro_rules! print_doccomment(
(
$doc:tt
fn $name:ident()
) => (
macro_rules! dummy( () => (
$doc
fn $name() {
println!("The doc for this function is `{}`", stringify!($doc));
}
))
dummy!()
)
);
print_doccomment!(
/// This is a doc comment
fn function_to_doc()
);
fn main() {
function_to_doc();
} |
The original and updated code no longer compile, and I suspect it should be closed, since the original issue is, and I cannot reproduce. @jseyfried Can you confirm? |
Closing. Please reopen if that's not the correct decision here. |
Yeah, this should be closed -- we can now downcast |
…mode, r=lnicola make ParamLoweringMode accessible In `hir-ty`, the `TyLoweringContext` has functions `pub fn with_impl_trait_mode` and `pub fn with_type_param_mode`, which can be used to fine-tune certain lowering properties. Each of these takes one enum (either `pub enum ImplTraitLoweringMode`, or `pub enum ParamLoweringMode`), which encodes the possible configuration options. To then make this usable for other crates, `TyLoweringContext` and `ImplTraitLoweringMode` are exported. Unfortuntely, `ParamLoweringMode` is not. This means that while the method can be called, there are no useful values to call it with. Presumably this is an oversight. It would be great if this was made actually public.
The following code compiles:
And prints "/// This is a doc comment". However, the token
/// This is a doc comment
is not an item, which is the only thing that should parse for the first$doc
whendummy!
is expanded (according to @chris-morgan on IRC).Note that I am using (a variation on) this in some code to transmit the doc comments on RPC-handling functions in response to the RPC "help". It would be great if there were a sanctioned way to parse or construct doccomments in macros.
The text was updated successfully, but these errors were encountered: