Skip to content

Commit 97a7ed2

Browse files
test: reproduce the issue with the cstr parsing inside the proc macro
While I am working on trying to patch rust-lang#112820 I think it is useful to have a test for this case as known-bug Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 136d74f commit 97a7ed2

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
#![crate_type = "proc-macro"]
4+
5+
extern crate proc_macro;
6+
7+
use proc_macro::{TokenStream, TokenTree};
8+
9+
#[proc_macro]
10+
pub fn repro(input: TokenStream) -> TokenStream {
11+
for token in input {
12+
if let TokenTree::Literal(literal) = token {
13+
assert!(format!("{}", literal).contains(&"c\""), "panic on: `{}`", literal);
14+
}
15+
}
16+
TokenStream::new()
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition: 2021
2+
// known-bug: #112820
3+
//
4+
// aux-build: count.rs
5+
#![feature(c_str_literals)]
6+
7+
// aux-build: wrong_parsing.rs
8+
extern crate wrong_parsing;
9+
10+
const _: () = {
11+
wrong_parsing::repro!(b"bytestr" c"cstr");
12+
};
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: proc macro panicked
2+
--> $DIR/edition-issue-112820-spans.rs:11:5
3+
|
4+
LL | wrong_parsing::repro!(b"bytestr" c"cstr");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: message: panic on: `cstr`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)