Support root namespace in namespace attribute

This commit is contained in:
David Tolnay 2020-12-04 12:21:27 -08:00
parent 181ee912ac
commit a23d7fd9ef
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 26 additions and 3 deletions

View File

@ -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)
}

View File

@ -0,0 +1,13 @@
#[cxx::bridge]
mod ffi {
#[namespace = "::"]
extern "Rust" {}
#[namespace = ""]
extern "Rust" {}
#[namespace = ]
extern "Rust" {}
}
fn main() {}

View File

@ -0,0 +1,5 @@
error: unexpected token: `]`
--> $DIR/root_namespace.rs:9:19
|
9 | #[namespace = ]
| ^