-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand compile_error! #2362
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
Expand compile_error! #2362
Conversation
|
||
let macro_content = { | ||
// FIXME: verify that this is an ast::Literatal with kind() == LiteralKind.String, else error. | ||
let arg = macro_call.token_tree().ok_or_else(|| mbe::ExpandError::UnexpectedToken)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could get it by using tt
, if it is valid , it should be a single subtree with one literal token-tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Once I have the literal is there an existing funtion to validate it's type or do I need to manually parse the ends and look for quotes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I know there is no existing function to validate it, so you may need to check whether it contains double quote. And if I remember correctly, the quote!
macro support TokenTree
too.
I think we could add a builtin error in |
Could you actually give an error when |
Maybe?I'm not too familiar with our diagnostics infra @matklad?
…On Fri, Nov 22, 2019 at 3:31 PM bjorn3 ***@***.***> wrote:
Could you actually give an error when compile_error is expanded?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2362>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBACRHCNY5UZWUAKCWV2CTQVA6SJANCNFSM4JQU66ZQ>
.
|
match &tt.token_trees[0] { | ||
tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { | ||
let s = it.text.as_str(); | ||
if s.starts_with(r#"""#) && s.ends_with(r#"""#) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be a raw string, which start with r#
, just checking whether it contains a double quote will be enough.
Nope, there's no infra for macro diagnostics yet |
1f1963c
to
67d3600
Compare
bors r+ , Thanks |
2362: Expand compile_error! r=edwin0cheng a=kjeremy Does not validate that the input is a string literal. I thought that I could `match_ast!` against the `macro_args` but that did not work. Even if it had I am not sure which error would be appropriate. Co-authored-by: Jeremy Kolb <[email protected]>
Build succeeded
|
Does not validate that the input is a string literal. I thought that I could
match_ast!
against themacro_args
but that did not work. Even if it had I am not sure which error would be appropriate.