Skip to content

Commit 6d46b3f

Browse files
authored
Fix is_name_used_as_error returning false for unused external errors (#2641)
1 parent 1b9df3e commit 6d46b3f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

fixtures/ext-types/lib/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use uniffi_one::{
88
UniffiOneEnum, UniffiOneError, UniffiOneErrorInterface, UniffiOneInterface,
99
UniffiOneProcMacroType, UniffiOneTLA, UniffiOneTrait, UniffiOneType, UniffiOneUDLTrait,
1010
};
11-
use uniffi_sublib::SubLibType;
11+
use uniffi_sublib::{NotToThrowError, SubLibType};
1212
use url::Url;
1313

1414
// Remote types require a macro call in the Rust source
@@ -228,4 +228,17 @@ fn get_uniffi_one_udl_trait(
228228
t
229229
}
230230

231+
#[derive(uniffi::Error)]
232+
pub enum ContainsExternalError {
233+
ExternalError(NotToThrowError),
234+
}
235+
236+
#[derive(uniffi::Record)]
237+
pub struct ContainsExternalError2 {
238+
error: NotToThrowError,
239+
}
240+
241+
#[uniffi::export]
242+
fn takes_external_error(_error: NotToThrowError) {}
243+
231244
uniffi::include_scaffolding!("ext-types-lib");

fixtures/ext-types/sub-lib/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,19 @@ fn get_trait_impl() -> Arc<dyn UniffiOneTrait> {
2626
Arc::new(OneImpl {})
2727
}
2828

29+
#[derive(uniffi::Error, Debug)]
30+
pub enum NotToThrowError {
31+
Variant(u64),
32+
}
33+
34+
impl std::fmt::Display for NotToThrowError {
35+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36+
match self {
37+
NotToThrowError::Variant(code) => {
38+
write!(f, "NotToThrowError with code {code}")
39+
}
40+
}
41+
}
42+
}
43+
2944
uniffi::setup_scaffolding!("imported_types_sublib");

uniffi_bindgen/src/interface/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,10 @@ impl ComponentInterface {
10211021

10221022
pub fn is_name_used_as_error(&self, name: &str) -> bool {
10231023
self.errors.contains(name)
1024+
|| self
1025+
.all_component_interfaces
1026+
.iter()
1027+
.any(|ci| ci.errors.contains(name))
10241028
}
10251029

10261030
/// Called by `APIBuilder` impls to add a newly-parsed callback interface definition to the `ComponentInterface`.

0 commit comments

Comments
 (0)