Skip to content

Commit

Permalink
Add raw identifier ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 8, 2022
1 parent 9f47a62 commit dc5a920
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/ui/raw_ident_namespace.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/raw_ident_namespace.stderr
Original file line number Diff line number Diff line change
@@ -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"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 comments on commit dc5a920

Please sign in to comment.