Skip to content

Commit 95fd17b

Browse files
authored
Remove traits that have a single implementation (#2363)
1 parent 73f33e5 commit 95fd17b

File tree

12 files changed

+17
-99
lines changed

12 files changed

+17
-99
lines changed

bindgen/codegen/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -2406,18 +2406,7 @@ impl CodeGenerator for CompInfo {
24062406
}
24072407
}
24082408

2409-
trait MethodCodegen {
2410-
fn codegen_method(
2411-
&self,
2412-
ctx: &BindgenContext,
2413-
methods: &mut Vec<proc_macro2::TokenStream>,
2414-
method_names: &mut HashSet<String>,
2415-
result: &mut CodegenResult<'_>,
2416-
parent: &CompInfo,
2417-
);
2418-
}
2419-
2420-
impl MethodCodegen for Method {
2409+
impl Method {
24212410
fn codegen_method(
24222411
&self,
24232412
ctx: &BindgenContext,

bindgen/ir/comp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
1212
use crate::clang;
1313
use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2};
1414
use crate::ir::derive::CanDeriveCopy;
15-
use crate::parse::{ClangItemParser, ParseError};
15+
use crate::parse::ParseError;
1616
use crate::HashMap;
1717
use crate::NonCopyUnionStyle;
1818
use peeking_take_while::PeekableExt;

bindgen/ir/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use super::template::{TemplateInstantiation, TemplateParameters};
2020
use super::traversal::{self, Edge, ItemTraversal};
2121
use super::ty::{FloatKind, Type, TypeKind};
2222
use crate::clang::{self, Cursor};
23-
use crate::parse::ClangItemParser;
2423
use crate::BindgenOptions;
2524
use crate::{Entry, HashMap, HashSet};
2625
use cexpr;

bindgen/ir/enum_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::item::Item;
66
use super::ty::{Type, TypeKind};
77
use crate::clang;
88
use crate::ir::annotations::Annotations;
9-
use crate::parse::{ClangItemParser, ParseError};
9+
use crate::parse::ParseError;
1010
use crate::regex_set::RegexSet;
1111

1212
/// An enum representing custom handling that can be given to a variant.

bindgen/ir/function.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use super::item::Item;
77
use super::traversal::{EdgeKind, Trace, Tracer};
88
use super::ty::TypeKind;
99
use crate::clang::{self, Attribute};
10-
use crate::parse::{
11-
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
12-
};
10+
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
1311
use clang_sys::{self, CXCallingConv};
1412
use proc_macro2;
1513
use quote;

bindgen/ir/item.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use super::template::{AsTemplateParam, TemplateParameters};
1818
use super::traversal::{EdgeKind, Trace, Tracer};
1919
use super::ty::{Type, TypeKind};
2020
use crate::clang;
21-
use crate::parse::{
22-
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
23-
};
21+
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
2422
use clang_sys;
2523
use lazycell::LazyCell;
2624
use regex;
@@ -1307,8 +1305,8 @@ fn visit_child(
13071305
}
13081306
}
13091307

1310-
impl ClangItemParser for Item {
1311-
fn builtin_type(
1308+
impl Item {
1309+
pub(crate) fn builtin_type(
13121310
kind: TypeKind,
13131311
is_const: bool,
13141312
ctx: &mut BindgenContext,
@@ -1333,7 +1331,7 @@ impl ClangItemParser for Item {
13331331
id.as_type_id_unchecked()
13341332
}
13351333

1336-
fn parse(
1334+
pub(crate) fn parse(
13371335
cursor: clang::Cursor,
13381336
parent_id: Option<ItemId>,
13391337
ctx: &mut BindgenContext,
@@ -1479,7 +1477,7 @@ impl ClangItemParser for Item {
14791477
}
14801478
}
14811479

1482-
fn from_ty_or_ref(
1480+
pub(crate) fn from_ty_or_ref(
14831481
ty: clang::Type,
14841482
location: clang::Cursor,
14851483
parent_id: Option<ItemId>,
@@ -1499,7 +1497,7 @@ impl ClangItemParser for Item {
14991497
///
15001498
/// Typerefs are resolved once parsing is completely done, see
15011499
/// `BindgenContext::resolve_typerefs`.
1502-
fn from_ty_or_ref_with_id(
1500+
pub(crate) fn from_ty_or_ref_with_id(
15031501
potential_id: ItemId,
15041502
ty: clang::Type,
15051503
location: clang::Cursor,
@@ -1554,7 +1552,7 @@ impl ClangItemParser for Item {
15541552
potential_id.as_type_id_unchecked()
15551553
}
15561554

1557-
fn from_ty(
1555+
pub(crate) fn from_ty(
15581556
ty: &clang::Type,
15591557
location: clang::Cursor,
15601558
parent_id: Option<ItemId>,
@@ -1572,7 +1570,7 @@ impl ClangItemParser for Item {
15721570
/// critical some times to obtain information, an optional parent item id,
15731571
/// that will, if it's `None`, become the current module id, and the
15741572
/// context.
1575-
fn from_ty_with_id(
1573+
pub(crate) fn from_ty_with_id(
15761574
id: ItemId,
15771575
ty: &clang::Type,
15781576
location: clang::Cursor,
@@ -1742,7 +1740,7 @@ impl ClangItemParser for Item {
17421740
/// A named type is a template parameter, e.g., the "T" in Foo<T>. They're
17431741
/// always local so it's the only exception when there's no declaration for
17441742
/// a type.
1745-
fn type_param(
1743+
pub(crate) fn type_param(
17461744
with_id: Option<ItemId>,
17471745
location: clang::Cursor,
17481746
ctx: &mut BindgenContext,

bindgen/ir/objc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::item::Item;
66
use super::traversal::{Trace, Tracer};
77
use super::ty::TypeKind;
88
use crate::clang;
9-
use crate::parse::ClangItemParser;
109
use clang_sys::CXChildVisit_Continue;
1110
use clang_sys::CXCursor_ObjCCategoryDecl;
1211
use clang_sys::CXCursor_ObjCClassMethodDecl;

bindgen/ir/template.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use super::context::{BindgenContext, ItemId, TypeId};
3131
use super::item::{IsOpaque, Item, ItemAncestors};
3232
use super::traversal::{EdgeKind, Trace, Tracer};
3333
use crate::clang;
34-
use crate::parse::ClangItemParser;
3534

3635
/// Template declaration (and such declaration's template parameters) related
3736
/// methods.

bindgen/ir/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::template::{
1414
};
1515
use super::traversal::{EdgeKind, Trace, Tracer};
1616
use crate::clang::{self, Cursor};
17-
use crate::parse::{ClangItemParser, ParseError, ParseResult};
17+
use crate::parse::{ParseError, ParseResult};
1818
use std::borrow::Cow;
1919
use std::io;
2020

bindgen/ir/var.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use super::ty::{FloatKind, TypeKind};
1010
use crate::callbacks::MacroParsingBehavior;
1111
use crate::clang;
1212
use crate::clang::ClangToken;
13-
use crate::parse::{
14-
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
15-
};
13+
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
1614
use cexpr;
1715
use std::io;
1816
use std::num::Wrapping;

bindgen/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub use crate::features::{
9090
use crate::ir::context::{BindgenContext, ItemId};
9191
pub use crate::ir::function::Abi;
9292
use crate::ir::item::Item;
93-
use crate::parse::{ClangItemParser, ParseError};
93+
use crate::parse::ParseError;
9494
use crate::regex_set::RegexSet;
9595

9696
use std::borrow::Cow;

bindgen/parse.rs

+1-63
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Common traits and types related to parsing our IR from Clang cursors.
22
33
use crate::clang;
4-
use crate::ir::context::{BindgenContext, ItemId, TypeId};
5-
use crate::ir::ty::TypeKind;
4+
use crate::ir::context::{BindgenContext, ItemId};
65

76
/// Not so much an error in the traditional sense, but a control flow message
87
/// when walking over Clang's AST with a cursor.
@@ -39,64 +38,3 @@ pub trait ClangSubItemParser: Sized {
3938
context: &mut BindgenContext,
4039
) -> Result<ParseResult<Self>, ParseError>;
4140
}
42-
43-
/// An intermediate representation item that can be parsed from a Clang cursor.
44-
pub trait ClangItemParser: Sized {
45-
/// Parse this item from the given Clang cursor.
46-
fn parse(
47-
cursor: clang::Cursor,
48-
parent: Option<ItemId>,
49-
context: &mut BindgenContext,
50-
) -> Result<ItemId, ParseError>;
51-
52-
/// Parse this item from the given Clang type.
53-
fn from_ty(
54-
ty: &clang::Type,
55-
location: clang::Cursor,
56-
parent: Option<ItemId>,
57-
ctx: &mut BindgenContext,
58-
) -> Result<TypeId, ParseError>;
59-
60-
/// Identical to `from_ty`, but use the given `id` as the `ItemId` for the
61-
/// newly parsed item.
62-
fn from_ty_with_id(
63-
id: ItemId,
64-
ty: &clang::Type,
65-
location: clang::Cursor,
66-
parent: Option<ItemId>,
67-
ctx: &mut BindgenContext,
68-
) -> Result<TypeId, ParseError>;
69-
70-
/// Parse this item from the given Clang type, or if we haven't resolved all
71-
/// the other items this one depends on, an unresolved reference.
72-
fn from_ty_or_ref(
73-
ty: clang::Type,
74-
location: clang::Cursor,
75-
parent_id: Option<ItemId>,
76-
context: &mut BindgenContext,
77-
) -> TypeId;
78-
79-
/// Identical to `from_ty_or_ref`, but use the given `potential_id` as the
80-
/// `ItemId` for the newly parsed item.
81-
fn from_ty_or_ref_with_id(
82-
potential_id: ItemId,
83-
ty: clang::Type,
84-
location: clang::Cursor,
85-
parent_id: Option<ItemId>,
86-
context: &mut BindgenContext,
87-
) -> TypeId;
88-
89-
/// Create a named template type.
90-
fn type_param(
91-
with_id: Option<ItemId>,
92-
location: clang::Cursor,
93-
ctx: &mut BindgenContext,
94-
) -> Option<TypeId>;
95-
96-
/// Create a builtin type.
97-
fn builtin_type(
98-
kind: TypeKind,
99-
is_const: bool,
100-
context: &mut BindgenContext,
101-
) -> TypeId;
102-
}

0 commit comments

Comments
 (0)