Skip to content

Commit 1ad018a

Browse files
committed
Fix renamed protocols
1 parent b4326d0 commit 1ad018a

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

crates/header-translator/src/stmt.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ pub enum Stmt {
369369
/// extern_protocol!
370370
ProtocolDecl {
371371
id: ItemIdentifier,
372+
actual_name: Option<String>,
372373
availability: Availability,
373374
protocols: BTreeSet<ItemIdentifier>,
374375
methods: Vec<Method>,
@@ -797,9 +798,14 @@ impl Stmt {
797798
.collect()
798799
}
799800
EntityKind::ObjCProtocolDecl => {
800-
let id = ItemIdentifier::new(entity, context)
801-
.map_name(|name| context.replace_protocol_name(name));
802-
let data = context.protocol_data.get(&id.name);
801+
let actual_id = ItemIdentifier::new(entity, context);
802+
let data = context.protocol_data.get(&actual_id.name);
803+
let actual_name = data
804+
.map(|data| data.renamed.is_some())
805+
.unwrap_or_default()
806+
.then(|| actual_id.name.clone());
807+
808+
let id = actual_id.map_name(|name| context.replace_protocol_name(name));
803809

804810
if data.map(|data| data.skipped).unwrap_or_default() {
805811
return vec![];
@@ -830,6 +836,7 @@ impl Stmt {
830836

831837
vec![Self::ProtocolDecl {
832838
id,
839+
actual_name,
833840
availability,
834841
protocols,
835842
methods,
@@ -1616,6 +1623,7 @@ impl fmt::Display for Stmt {
16161623
}
16171624
Self::ProtocolDecl {
16181625
id,
1626+
actual_name,
16191627
availability,
16201628
protocols,
16211629
methods,
@@ -1683,7 +1691,13 @@ impl fmt::Display for Stmt {
16831691
}
16841692
writeln!(f, " }}")?;
16851693
writeln!(f)?;
1686-
writeln!(f, " unsafe impl ProtocolType for dyn {} {{}}", id.name)?;
1694+
writeln!(f, " unsafe impl ProtocolType for dyn {} {{", id.name)?;
1695+
if let Some(actual_name) = actual_name {
1696+
writeln!(f)?;
1697+
writeln!(f, " const NAME: &'static str = {actual_name:?};")?;
1698+
write!(f, " ")?;
1699+
}
1700+
writeln!(f, "}}")?;
16871701
writeln!(f, ");")?;
16881702
}
16891703
Self::StructDecl {

crates/icrate/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6565
to use in such hashing collections.
6666
* **BREAKING**: Added `HasStableHash` requirement on `NSDictionary` and
6767
`NSSet` creation methods, fixing a long-standing soundess issue.
68+
* Fixed the protocol names of `NSAccessibilityElementProtocol`,
69+
`NSTextAttachmentCellProtocol` and `NSFileProviderItemProtocol`.
6870

6971

7072
## icrate 0.0.4 - 2023-07-31

crates/icrate/src/fixes/Foundation/copying.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ extern_protocol!(
4141
Self: CounterpartOrSelf;
4242
}
4343

44-
unsafe impl ProtocolType for dyn NSCopying {
45-
const NAME: &'static str = "NSCopying";
46-
}
44+
unsafe impl ProtocolType for dyn NSCopying {}
4745
);
4846

4947
// FIXME: Remove this hack which makes NSMutableDictionary tests work
@@ -86,7 +84,5 @@ extern_protocol!(
8684
Self: CounterpartOrSelf;
8785
}
8886

89-
unsafe impl ProtocolType for dyn NSMutableCopying {
90-
const NAME: &'static str = "NSMutableCopying";
91-
}
87+
unsafe impl ProtocolType for dyn NSMutableCopying {}
9288
);

crates/icrate/src/generated

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![cfg(feature = "AppKit")]
2+
use icrate::AppKit::NSAccessibilityElementProtocol;
3+
use objc2::ProtocolType;
4+
5+
#[test]
6+
fn accessibility_element_protocol() {
7+
let actual: &str = <dyn NSAccessibilityElementProtocol>::NAME;
8+
assert_eq!(actual, "NSAccessibilityElement");
9+
}

0 commit comments

Comments
 (0)