mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-23 20:09:55 +00:00
Support root namespace in namespace attribute
This commit is contained in:
parent
181ee912ac
commit
a23d7fd9ef
@ -10,14 +10,14 @@ impl QualifiedName {
|
||||
pub fn parse_unquoted(input: ParseStream) -> Result<Self> {
|
||||
let mut segments = Vec::new();
|
||||
let mut trailing_punct = true;
|
||||
input.parse::<Option<Token![::]>>()?;
|
||||
let leading_colons: Option<Token![::]> = input.parse()?;
|
||||
while trailing_punct && input.peek(Ident::peek_any) {
|
||||
let ident = Ident::parse_any(input)?;
|
||||
segments.push(ident);
|
||||
let colons: Option<Token![::]> = input.parse()?;
|
||||
trailing_punct = colons.is_some();
|
||||
}
|
||||
if segments.is_empty() {
|
||||
if segments.is_empty() && leading_colons.is_none() {
|
||||
return Err(input.error("expected path"));
|
||||
} else if trailing_punct {
|
||||
return Err(input.error("expected path segment"));
|
||||
@ -28,7 +28,12 @@ impl QualifiedName {
|
||||
pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> {
|
||||
if input.peek(LitStr) {
|
||||
let lit: LitStr = input.parse()?;
|
||||
lit.parse_with(Self::parse_unquoted)
|
||||
if lit.value().is_empty() {
|
||||
let segments = Vec::new();
|
||||
Ok(QualifiedName { segments })
|
||||
} else {
|
||||
lit.parse_with(Self::parse_unquoted)
|
||||
}
|
||||
} else {
|
||||
Self::parse_unquoted(input)
|
||||
}
|
||||
|
13
tests/ui/root_namespace.rs
Normal file
13
tests/ui/root_namespace.rs
Normal file
@ -0,0 +1,13 @@
|
||||
#[cxx::bridge]
|
||||
mod ffi {
|
||||
#[namespace = "::"]
|
||||
extern "Rust" {}
|
||||
|
||||
#[namespace = ""]
|
||||
extern "Rust" {}
|
||||
|
||||
#[namespace = ]
|
||||
extern "Rust" {}
|
||||
}
|
||||
|
||||
fn main() {}
|
5
tests/ui/root_namespace.stderr
Normal file
5
tests/ui/root_namespace.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: unexpected token: `]`
|
||||
--> $DIR/root_namespace.rs:9:19
|
||||
|
|
||||
9 | #[namespace = ]
|
||||
| ^
|
Loading…
Reference in New Issue
Block a user