Skip to content

Commit 171a694

Browse files
committed
Fix panicking parsing of doc comments in clang-rs
1 parent 10c717a commit 171a694

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/header-translator/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ license = "Zlib OR Apache-2.0 OR MIT"
88

99
[dependencies]
1010
# https://github.com/KyleMayes/clang-rs/pull/58
11-
clang = { git = "https://github.com/madsmtm/clang-rs.git", branch = "fix-ub-tokenize", features = ["runtime", "clang_10_0"] }
11+
# https://github.com/KyleMayes/clang-rs/pull/60
12+
# https://github.com/KyleMayes/clang-rs/pull/62
13+
clang = { git = "https://github.com/madsmtm/clang-rs.git", branch = "objc2", features = ["runtime", "clang_10_0"] }
1214
clang-sys = { version = "1.4.0" }
1315
toml_edit = "0.22.9"
1416
basic-toml = "0.1.2"

crates/header-translator/src/documentation.rs

+9-24
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,21 @@ pub struct Documentation {
1616

1717
impl Documentation {
1818
pub fn from_entity(entity: &Entity<'_>) -> Self {
19-
// This can fail when the comment is non-UTF-8, so we have to
20-
// potentially handle that case.
21-
//
22-
// TODO: Fix this in the `clang` crate.
23-
let comment = std::panic::catch_unwind(|| {
24-
if let Some(comment) = entity.get_comment() {
25-
if let Some(parsed) = entity.get_parsed_comment() {
26-
Some(parsed)
27-
} else {
28-
error!(?entity, comment, "had comment, but not parsed comment");
29-
None
19+
if let Some(comment) = entity.get_comment() {
20+
if let Some(parsed) = entity.get_parsed_comment() {
21+
Self {
22+
children: parsed.get_children(),
3023
}
3124
} else {
32-
None
33-
}
34-
});
35-
36-
match comment {
37-
Ok(Some(parsed)) => Self {
38-
children: parsed.get_children(),
39-
},
40-
Ok(None) => Self {
41-
children: Vec::new(),
42-
},
43-
Err(_err) => {
44-
warn!(?entity, "failed fetching comment");
25+
error!(?entity, comment, "had comment, but not parsed comment");
4526
Self {
4627
children: Vec::new(),
4728
}
4829
}
30+
} else {
31+
Self {
32+
children: Vec::new(),
33+
}
4934
}
5035
}
5136

generated

0 commit comments

Comments
 (0)