Skip to content

Commit 0076a17

Browse files
Hywanemilio
authored andcommitted
feat(ir) Simplify ManuallyDrop and MaybeUninit only for C.
1 parent af6d2e3 commit 0076a17

File tree

7 files changed

+25
-22
lines changed

7 files changed

+25
-22
lines changed

src/bindgen/ir/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ impl Function {
120120
&self.path
121121
}
122122

123-
pub fn simplify_standard_types(&mut self) {
124-
self.ret.simplify_standard_types();
123+
pub fn simplify_standard_types(&mut self, config: &Config) {
124+
self.ret.simplify_standard_types(config);
125125
for arg in &mut self.args {
126-
arg.ty.simplify_standard_types();
126+
arg.ty.simplify_standard_types(config);
127127
}
128128
}
129129

src/bindgen/ir/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl Static {
6161
}
6262
}
6363

64-
pub fn simplify_standard_types(&mut self) {
65-
self.ty.simplify_standard_types();
64+
pub fn simplify_standard_types(&mut self, config: &Config) {
65+
self.ty.simplify_standard_types(config);
6666
}
6767
}
6868

src/bindgen/ir/structure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ impl Struct {
143143
}
144144
}
145145

146-
pub fn simplify_standard_types(&mut self) {
146+
pub fn simplify_standard_types(&mut self, config: &Config) {
147147
for &mut (_, ref mut ty, _) in &mut self.fields {
148-
ty.simplify_standard_types();
148+
ty.simplify_standard_types(config);
149149
}
150150
}
151151

src/bindgen/ir/ty.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt;
66
use std::io::Write;
77

88
use crate::bindgen::cdecl;
9-
use crate::bindgen::config::Config;
9+
use crate::bindgen::config::{Config, Language};
1010
use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver;
1111
use crate::bindgen::dependencies::Dependencies;
1212
use crate::bindgen::ir::{Documentation, GenericParams, GenericPath, Path};
@@ -411,7 +411,7 @@ impl Type {
411411
}
412412
}
413413

414-
fn simplified_type(&self) -> Option<Self> {
414+
fn simplified_type(&self, config: &Config) -> Option<Self> {
415415
let path = match *self {
416416
Type::Path(ref p) => p,
417417
_ => return None,
@@ -422,7 +422,7 @@ impl Type {
422422
}
423423

424424
let mut generic = path.generics()[0].clone();
425-
generic.simplify_standard_types();
425+
generic.simplify_standard_types(config);
426426

427427
match path.name() {
428428
// FIXME(#223): This is not quite correct.
@@ -433,13 +433,14 @@ impl Type {
433433
is_nullable: false,
434434
is_ref: false,
435435
}),
436-
"Cell" | "ManuallyDrop" | "MaybeUninit" => Some(generic),
436+
"Cell" => Some(generic),
437+
"ManuallyDrop" | "MaybeUninit" if config.language == Language::C => Some(generic),
437438
_ => None,
438439
}
439440
}
440441

441-
pub fn simplify_standard_types(&mut self) {
442-
if let Some(ty) = self.simplified_type() {
442+
pub fn simplify_standard_types(&mut self, config: &Config) {
443+
if let Some(ty) = self.simplified_type(config) {
443444
*self = ty;
444445
}
445446
}

src/bindgen/ir/typedef.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl Typedef {
6666
}
6767
}
6868

69-
pub fn simplify_standard_types(&mut self) {
70-
self.aliased.simplify_standard_types();
69+
pub fn simplify_standard_types(&mut self, config: &Config) {
70+
self.aliased.simplify_standard_types(config);
7171
}
7272

7373
pub fn transfer_annotations(&mut self, out: &mut HashMap<Path, AnnotationSet>) {

src/bindgen/ir/union.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ impl Union {
9696
}
9797
}
9898

99-
pub fn simplify_standard_types(&mut self) {
99+
pub fn simplify_standard_types(&mut self, config: &Config) {
100100
for &mut (_, ref mut ty, _) in &mut self.fields {
101-
ty.simplify_standard_types();
101+
ty.simplify_standard_types(config);
102102
}
103103
}
104104

src/bindgen/library.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,22 @@ impl Library {
344344
}
345345

346346
fn simplify_standard_types(&mut self) {
347+
let config = &self.config;
348+
347349
self.structs.for_all_items_mut(|x| {
348-
x.simplify_standard_types();
350+
x.simplify_standard_types(config);
349351
});
350352
self.unions.for_all_items_mut(|x| {
351-
x.simplify_standard_types();
353+
x.simplify_standard_types(config);
352354
});
353355
self.globals.for_all_items_mut(|x| {
354-
x.simplify_standard_types();
356+
x.simplify_standard_types(config);
355357
});
356358
self.typedefs.for_all_items_mut(|x| {
357-
x.simplify_standard_types();
359+
x.simplify_standard_types(config);
358360
});
359361
for x in &mut self.functions {
360-
x.simplify_standard_types();
362+
x.simplify_standard_types(config);
361363
}
362364
}
363365

0 commit comments

Comments
 (0)