Skip to content

Commit a8f2634

Browse files
authored
Merge branch 'rust-lang:master' into generated_name_override
2 parents 3c8d6e9 + 9677e41 commit a8f2634

File tree

273 files changed

+13304
-19741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+13304
-19741
lines changed

.github/workflows/bindgen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ jobs:
4848
profile: minimal
4949
# MSRV below is documented in Cargo.toml and README.md, please update those if you
5050
# change this.
51-
toolchain: 1.56.1
51+
toolchain: 1.57.0
5252
override: true
5353

5454
- name: Build with msrv
55-
run: rm Cargo.lock && cargo +1.56.1 build --lib
55+
run: rm Cargo.lock && cargo +1.57.0 build --lib
5656

5757
quickchecking:
5858
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,20 @@
143143

144144
## Added
145145

146+
* new feature: `--sort-semantically` flag to sort the output in a predefined manner [(#1743)]
147+
146148
## Changed
147149

150+
* clap has been updated, new msrv is 1.57.
151+
148152
## Removed
149153

150154
## Fixed
151155

152156
## Security
153157

158+
[(#1743)]: https://github.com/rust-lang/rust-bindgen/issues/1743
159+
154160
# 0.60.1
155161

156162
Released 2022/06/06

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ $ cargo test
152152

153153
### Testing a Single Header's Bindings Generation and Compiling its Bindings
154154

155+
Note: You will to need to install [Graphviz](https://graphviz.org/) since that
156+
is a dependency for running `test-one.sh`.
157+
155158
Sometimes its useful to work with one test header from start (generating
156159
bindings for it) to finish (compiling the bindings and running their layout
157160
tests). This can be done with the `tests/test-one.sh` script. It supports fuzzy

Cargo.lock

Lines changed: 48 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ version = "0.60.1"
1818
edition = "2018"
1919
build = "build.rs"
2020
# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml
21-
rust-version = "1.56.1"
21+
rust-version = "1.57.0"
2222

2323
include = [
2424
"LICENSE",
@@ -57,7 +57,8 @@ lazycell = "1"
5757
lazy_static = "1"
5858
peeking_take_while = "0.1.2"
5959
quote = { version = "1", default-features = false }
60-
regex = { version = "1.5", default-features = false , features = [ "std", "unicode"]}
60+
syn = { version = "1.0.99", features = ["full", "extra-traits"]}
61+
regex = { version = "1.5", default-features = false , features = ["std", "unicode"] }
6162
which = { version = "4.2.1", optional = true, default-features = false }
6263
shlex = "1"
6364
rustc-hash = "1.0.1"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern "C" {
3939

4040
## MSRV
4141

42-
The minimum supported Rust version is **1.56.1**.
42+
The minimum supported Rust version is **1.57.0**.
4343

4444
No MSRV bump policy has been established yet, so MSRV may increase in any release.
4545

src/clang.rs

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,56 @@ impl Cursor {
276276
true
277277
}
278278

279+
/// Is the referent any kind of template parameter?
280+
pub fn is_template_parameter(&self) -> bool {
281+
matches!(
282+
self.kind(),
283+
CXCursor_TemplateTemplateParameter |
284+
CXCursor_TemplateTypeParameter |
285+
CXCursor_NonTypeTemplateParameter
286+
)
287+
}
288+
289+
/// Does the referent's type or value depend on a template parameter?
290+
pub fn is_dependent_on_template_parameter(&self) -> bool {
291+
fn visitor(
292+
found_template_parameter: &mut bool,
293+
cur: Cursor,
294+
) -> CXChildVisitResult {
295+
// If we found a template parameter, it is dependent.
296+
if cur.is_template_parameter() {
297+
*found_template_parameter = true;
298+
return CXChildVisit_Break;
299+
}
300+
301+
// Get the referent and traverse it as well.
302+
if let Some(referenced) = cur.referenced() {
303+
if referenced.is_template_parameter() {
304+
*found_template_parameter = true;
305+
return CXChildVisit_Break;
306+
}
307+
308+
referenced
309+
.visit(|next| visitor(found_template_parameter, next));
310+
if *found_template_parameter {
311+
return CXChildVisit_Break;
312+
}
313+
}
314+
315+
// Continue traversing the AST at the original cursor.
316+
CXChildVisit_Recurse
317+
}
318+
319+
if self.is_template_parameter() {
320+
return true;
321+
}
322+
323+
let mut found_template_parameter = false;
324+
self.visit(|next| visitor(&mut found_template_parameter, next));
325+
326+
found_template_parameter
327+
}
328+
279329
/// Is this cursor pointing a valid referent?
280330
pub fn is_valid(&self) -> bool {
281331
unsafe { clang_isInvalid(self.kind()) == 0 }
@@ -485,9 +535,45 @@ impl Cursor {
485535
!self.is_defaulted_function()
486536
}
487537

538+
/// Is the referent a bit field declaration?
539+
pub fn is_bit_field(&self) -> bool {
540+
unsafe { clang_Cursor_isBitField(self.x) != 0 }
541+
}
542+
543+
/// Get a cursor to the bit field's width expression, or `None` if it's not
544+
/// a bit field.
545+
pub fn bit_width_expr(&self) -> Option<Cursor> {
546+
if !self.is_bit_field() {
547+
return None;
548+
}
549+
550+
let mut result = None;
551+
self.visit(|cur| {
552+
// The first child may or may not be a TypeRef, depending on whether
553+
// the field's type is builtin. Skip it.
554+
if cur.kind() == CXCursor_TypeRef {
555+
return CXChildVisit_Continue;
556+
}
557+
558+
// The next expression or literal is the bit width.
559+
result = Some(cur);
560+
561+
CXChildVisit_Break
562+
});
563+
564+
result
565+
}
566+
488567
/// Get the width of this cursor's referent bit field, or `None` if the
489-
/// referent is not a bit field.
568+
/// referent is not a bit field or if the width could not be evaluated.
490569
pub fn bit_width(&self) -> Option<u32> {
570+
// It is not safe to check the bit width without ensuring it doesn't
571+
// depend on a template parameter. See
572+
// https://github.com/rust-lang/rust-bindgen/issues/2239
573+
if self.bit_width_expr()?.is_dependent_on_template_parameter() {
574+
return None;
575+
}
576+
491577
unsafe {
492578
let w = clang_getFieldDeclBitWidth(self.x);
493579
if w == -1 {
@@ -1789,9 +1875,15 @@ pub fn ast_dump(c: &Cursor, depth: isize) -> CXChildVisitResult {
17891875
format!(" {}number-of-template-args = {}", prefix, num),
17901876
);
17911877
}
1792-
if let Some(width) = c.bit_width() {
1878+
1879+
if c.is_bit_field() {
1880+
let width = match c.bit_width() {
1881+
Some(w) => w.to_string(),
1882+
None => "<unevaluable>".to_string(),
1883+
};
17931884
print_indent(depth, format!(" {}bit-width = {}", prefix, width));
17941885
}
1886+
17951887
if let Some(ty) = c.enum_type() {
17961888
print_indent(
17971889
depth,

0 commit comments

Comments
 (0)