Skip to content

Commit

Permalink
Friendlier message when cxx::CxxString is used in a #[cxx::bridge].
Browse files Browse the repository at this point in the history
  • Loading branch information
anforowicz committed Dec 16, 2024
1 parent 3190072 commit 4f0d547
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions syntax/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,13 @@ fn parse_type_path(ty: &TypePath) -> Result<Type> {
}
}

if ty.qself.is_none() && path.segments.len() == 2 && path.segments[0].ident == "cxx" {
return Err(Error::new_spanned(
ty,
"unexpected `cxx::` qualifier found in a `#[cxx::bridge]`",
));
}

Err(Error::new_spanned(ty, "unsupported type"))
}

Expand Down
17 changes: 17 additions & 0 deletions tests/ui/cxx_crate_name_qualified_cxx_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[cxx::bridge]
mod ffi {
extern "Rust" {
fn foo(x: CxxString);
fn bar(x: &cxx::CxxString);
}
}

fn foo(_: &cxx::CxxString) {
todo!()
}

fn bar(_: &cxx::CxxString) {
todo!()
}

fn main() {}
5 changes: 5 additions & 0 deletions tests/ui/cxx_crate_name_qualified_cxx_string.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: unexpected `cxx::` qualifier found in a `#[cxx::bridge]`
--> tests/ui/cxx_crate_name_qualified_cxx_string.rs:5:20
|
5 | fn bar(x: &cxx::CxxString);
| ^^^^^^^^^^^^^^

0 comments on commit 4f0d547

Please sign in to comment.