Skip to content

Commit

Permalink
test: reproduce the issue with the cstr parsing inside the proc macro
Browse files Browse the repository at this point in the history
While I am working on trying to patch #112820

I think it is useful to have a test for this case as known-bug

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Sep 24, 2023
1 parent 136d74f commit 1ed2743
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::{TokenStream, TokenTree};

#[proc_macro]
pub fn repro(input: TokenStream) -> TokenStream {
for token in input {
if let TokenTree::Literal(literal) = token {
assert!(format!("{}", literal).contains(&"c\""), "panic on: `{}`", literal);
}
}
TokenStream::new()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// edition: 2021
// known-bug: #112820
//
// aux-build: count.rs
#![feature(c_str_literals)]

// aux-build: wrong_parsing.rs
extern crate wrong_parsing;

const _: () = {
wrong_parsing::repro!(c"cstr");
};

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: proc macro panicked
--> $DIR/edition-issue-112820-spans.rs:11:5
|
LL | wrong_parsing::repro!(c"cstr");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: panic on: `cstr`

error: aborting due to previous error

0 comments on commit 1ed2743

Please sign in to comment.