Remove traits that have a single implementation (#2363)

This commit is contained in:
Christian Poveda Ruiz 2022-11-24 11:17:08 -05:00 committed by GitHub
parent 73f33e5a02
commit 95fd17b874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 17 additions and 99 deletions

View File

@ -2406,18 +2406,7 @@ impl CodeGenerator for CompInfo {
}
}
trait MethodCodegen {
fn codegen_method(
&self,
ctx: &BindgenContext,
methods: &mut Vec<proc_macro2::TokenStream>,
method_names: &mut HashSet<String>,
result: &mut CodegenResult<'_>,
parent: &CompInfo,
);
}
impl MethodCodegen for Method {
impl Method {
fn codegen_method(
&self,
ctx: &BindgenContext,

View File

@ -12,7 +12,7 @@ use super::ty::RUST_DERIVE_IN_ARRAY_LIMIT;
use crate::clang;
use crate::codegen::struct_layout::{align_to, bytes_from_bits_pow2};
use crate::ir::derive::CanDeriveCopy;
use crate::parse::{ClangItemParser, ParseError};
use crate::parse::ParseError;
use crate::HashMap;
use crate::NonCopyUnionStyle;
use peeking_take_while::PeekableExt;

View File

@ -20,7 +20,6 @@ use super::template::{TemplateInstantiation, TemplateParameters};
use super::traversal::{self, Edge, ItemTraversal};
use super::ty::{FloatKind, Type, TypeKind};
use crate::clang::{self, Cursor};
use crate::parse::ClangItemParser;
use crate::BindgenOptions;
use crate::{Entry, HashMap, HashSet};
use cexpr;

View File

@ -6,7 +6,7 @@ use super::item::Item;
use super::ty::{Type, TypeKind};
use crate::clang;
use crate::ir::annotations::Annotations;
use crate::parse::{ClangItemParser, ParseError};
use crate::parse::ParseError;
use crate::regex_set::RegexSet;
/// An enum representing custom handling that can be given to a variant.

View File

@ -7,9 +7,7 @@ use super::item::Item;
use super::traversal::{EdgeKind, Trace, Tracer};
use super::ty::TypeKind;
use crate::clang::{self, Attribute};
use crate::parse::{
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
};
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
use clang_sys::{self, CXCallingConv};
use proc_macro2;
use quote;

View File

@ -18,9 +18,7 @@ use super::template::{AsTemplateParam, TemplateParameters};
use super::traversal::{EdgeKind, Trace, Tracer};
use super::ty::{Type, TypeKind};
use crate::clang;
use crate::parse::{
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
};
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
use clang_sys;
use lazycell::LazyCell;
use regex;
@ -1307,8 +1305,8 @@ fn visit_child(
}
}
impl ClangItemParser for Item {
fn builtin_type(
impl Item {
pub(crate) fn builtin_type(
kind: TypeKind,
is_const: bool,
ctx: &mut BindgenContext,
@ -1333,7 +1331,7 @@ impl ClangItemParser for Item {
id.as_type_id_unchecked()
}
fn parse(
pub(crate) fn parse(
cursor: clang::Cursor,
parent_id: Option<ItemId>,
ctx: &mut BindgenContext,
@ -1479,7 +1477,7 @@ impl ClangItemParser for Item {
}
}
fn from_ty_or_ref(
pub(crate) fn from_ty_or_ref(
ty: clang::Type,
location: clang::Cursor,
parent_id: Option<ItemId>,
@ -1499,7 +1497,7 @@ impl ClangItemParser for Item {
///
/// Typerefs are resolved once parsing is completely done, see
/// `BindgenContext::resolve_typerefs`.
fn from_ty_or_ref_with_id(
pub(crate) fn from_ty_or_ref_with_id(
potential_id: ItemId,
ty: clang::Type,
location: clang::Cursor,
@ -1554,7 +1552,7 @@ impl ClangItemParser for Item {
potential_id.as_type_id_unchecked()
}
fn from_ty(
pub(crate) fn from_ty(
ty: &clang::Type,
location: clang::Cursor,
parent_id: Option<ItemId>,
@ -1572,7 +1570,7 @@ impl ClangItemParser for Item {
/// critical some times to obtain information, an optional parent item id,
/// that will, if it's `None`, become the current module id, and the
/// context.
fn from_ty_with_id(
pub(crate) fn from_ty_with_id(
id: ItemId,
ty: &clang::Type,
location: clang::Cursor,
@ -1742,7 +1740,7 @@ impl ClangItemParser for Item {
/// A named type is a template parameter, e.g., the "T" in Foo<T>. They're
/// always local so it's the only exception when there's no declaration for
/// a type.
fn type_param(
pub(crate) fn type_param(
with_id: Option<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,

View File

@ -6,7 +6,6 @@ use super::item::Item;
use super::traversal::{Trace, Tracer};
use super::ty::TypeKind;
use crate::clang;
use crate::parse::ClangItemParser;
use clang_sys::CXChildVisit_Continue;
use clang_sys::CXCursor_ObjCCategoryDecl;
use clang_sys::CXCursor_ObjCClassMethodDecl;

View File

@ -31,7 +31,6 @@ use super::context::{BindgenContext, ItemId, TypeId};
use super::item::{IsOpaque, Item, ItemAncestors};
use super::traversal::{EdgeKind, Trace, Tracer};
use crate::clang;
use crate::parse::ClangItemParser;
/// Template declaration (and such declaration's template parameters) related
/// methods.

View File

@ -14,7 +14,7 @@ use super::template::{
};
use super::traversal::{EdgeKind, Trace, Tracer};
use crate::clang::{self, Cursor};
use crate::parse::{ClangItemParser, ParseError, ParseResult};
use crate::parse::{ParseError, ParseResult};
use std::borrow::Cow;
use std::io;

View File

@ -10,9 +10,7 @@ use super::ty::{FloatKind, TypeKind};
use crate::callbacks::MacroParsingBehavior;
use crate::clang;
use crate::clang::ClangToken;
use crate::parse::{
ClangItemParser, ClangSubItemParser, ParseError, ParseResult,
};
use crate::parse::{ClangSubItemParser, ParseError, ParseResult};
use cexpr;
use std::io;
use std::num::Wrapping;

View File

@ -90,7 +90,7 @@ pub use crate::features::{
use crate::ir::context::{BindgenContext, ItemId};
pub use crate::ir::function::Abi;
use crate::ir::item::Item;
use crate::parse::{ClangItemParser, ParseError};
use crate::parse::ParseError;
use crate::regex_set::RegexSet;
use std::borrow::Cow;

View File

@ -1,8 +1,7 @@
//! Common traits and types related to parsing our IR from Clang cursors.
use crate::clang;
use crate::ir::context::{BindgenContext, ItemId, TypeId};
use crate::ir::ty::TypeKind;
use crate::ir::context::{BindgenContext, ItemId};
/// Not so much an error in the traditional sense, but a control flow message
/// when walking over Clang's AST with a cursor.
@ -39,64 +38,3 @@ pub trait ClangSubItemParser: Sized {
context: &mut BindgenContext,
) -> Result<ParseResult<Self>, ParseError>;
}
/// An intermediate representation item that can be parsed from a Clang cursor.
pub trait ClangItemParser: Sized {
/// Parse this item from the given Clang cursor.
fn parse(
cursor: clang::Cursor,
parent: Option<ItemId>,
context: &mut BindgenContext,
) -> Result<ItemId, ParseError>;
/// Parse this item from the given Clang type.
fn from_ty(
ty: &clang::Type,
location: clang::Cursor,
parent: Option<ItemId>,
ctx: &mut BindgenContext,
) -> Result<TypeId, ParseError>;
/// Identical to `from_ty`, but use the given `id` as the `ItemId` for the
/// newly parsed item.
fn from_ty_with_id(
id: ItemId,
ty: &clang::Type,
location: clang::Cursor,
parent: Option<ItemId>,
ctx: &mut BindgenContext,
) -> Result<TypeId, ParseError>;
/// Parse this item from the given Clang type, or if we haven't resolved all
/// the other items this one depends on, an unresolved reference.
fn from_ty_or_ref(
ty: clang::Type,
location: clang::Cursor,
parent_id: Option<ItemId>,
context: &mut BindgenContext,
) -> TypeId;
/// Identical to `from_ty_or_ref`, but use the given `potential_id` as the
/// `ItemId` for the newly parsed item.
fn from_ty_or_ref_with_id(
potential_id: ItemId,
ty: clang::Type,
location: clang::Cursor,
parent_id: Option<ItemId>,
context: &mut BindgenContext,
) -> TypeId;
/// Create a named template type.
fn type_param(
with_id: Option<ItemId>,
location: clang::Cursor,
ctx: &mut BindgenContext,
) -> Option<TypeId>;
/// Create a builtin type.
fn builtin_type(
kind: TypeKind,
is_const: bool,
context: &mut BindgenContext,
) -> TypeId;
}