From dc5a920deb7aa9f778cde3f0aad485a2592f738f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 8 Nov 2022 00:47:31 -0800 Subject: [PATCH] Add raw identifier ui test --- tests/ui/raw_ident_namespace.rs | 53 +++++++++++++++++++++++++++++ tests/ui/raw_ident_namespace.stderr | 11 ++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/ui/raw_ident_namespace.rs create mode 100644 tests/ui/raw_ident_namespace.stderr diff --git a/tests/ui/raw_ident_namespace.rs b/tests/ui/raw_ident_namespace.rs new file mode 100644 index 000000000..2c8286c70 --- /dev/null +++ b/tests/ui/raw_ident_namespace.rs @@ -0,0 +1,53 @@ +use cxx::{type_id, ExternType}; + +#[repr(transparent)] +pub struct QuotedRaw(usize); + +unsafe impl ExternType for QuotedRaw { + type Id = type_id!("org::r#box::implementation::QuotedRaw"); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct QuotedKeyword(usize); + +unsafe impl ExternType for QuotedKeyword { + type Id = type_id!("org::box::implementation::QuotedKeyword"); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct UnquotedRaw(usize); + +unsafe impl ExternType for UnquotedRaw { + type Id = type_id!(org::r#box::implementation::UnquotedRaw); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct UnquotedKeyword(usize); + +unsafe impl ExternType for UnquotedKeyword { + type Id = type_id!(org::box::implementation::UnquotedKeyword); + type Kind = cxx::kind::Trivial; +} + +#[cxx::bridge] +pub mod ffi { + extern "C++" { + #[namespace = "org::r#box::implementation"] + type QuotedRaw = crate::QuotedRaw; + + #[namespace = "org::box::implementation"] + type QuotedKeyword = crate::QuotedKeyword; + + #[namespace = org::r#box::implementation] + type UnquotedRaw = crate::UnquotedRaw; + + // Not allowed by rustc (independent of cxx): + // #[namespace = org::box::implementation] + // type UnquotedKeyword = crate::UnquotedKeyword; + } +} + +fn main() {} diff --git a/tests/ui/raw_ident_namespace.stderr b/tests/ui/raw_ident_namespace.stderr new file mode 100644 index 000000000..e46845942 --- /dev/null +++ b/tests/ui/raw_ident_namespace.stderr @@ -0,0 +1,11 @@ +error: raw identifier `r#box` is not allowed in a quoted namespace + --> tests/ui/raw_ident_namespace.rs:7:24 + | +7 | type Id = type_id!("org::r#box::implementation::QuotedRaw"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: raw identifier `r#box` is not allowed in a quoted namespace + --> tests/ui/raw_ident_namespace.rs:38:23 + | +38 | #[namespace = "org::r#box::implementation"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^