From 1ed27431b4f46372834d51e5e3bcb4d7653dc4a1 Mon Sep 17 00:00:00 2001 From: Vincenzo Palazzo Date: Sat, 23 Sep 2023 16:16:10 +0200 Subject: [PATCH] test: reproduce the issue with the cstr parsing inside the proc macro 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 --- .../auxiliary/wrong_parsing.rs | 17 +++++++++++++++++ .../edition-issue-112820-spans.rs | 14 ++++++++++++++ .../edition-issue-112820-spans.stderr | 10 ++++++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/wrong_parsing.rs create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.rs create mode 100644 tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.stderr diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/wrong_parsing.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/wrong_parsing.rs new file mode 100644 index 0000000000000..c5aaa16af0cb1 --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/auxiliary/wrong_parsing.rs @@ -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() +} diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.rs new file mode 100644 index 0000000000000..2a4af32f46f2f --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.rs @@ -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() {} diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.stderr new file mode 100644 index 0000000000000..1bf0aee144288 --- /dev/null +++ b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-issue-112820-spans.stderr @@ -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 +