Skip to content

Commit 3a7cd8f

Browse files
bors[bot]xFrednet
andauthored
Merge #54
54: Add items and adjust existing ones to the evolving standard r=xFrednet a=xFrednet This was quite fun to write. It's remarkable how a good framework and setup can come together for fast and effective development :3 This closes #49, the driver implementation will be done in as part of #53. This issue also removes almost all traits from our API 🎉. The last trait will be removed with #51 this therefore also closes #6. Also, as usual, some progress on #38. The normal disclaimer: I'm happy about reviews, but will merge this, if there has been no activity by the time I want to create the next PR. Let's hope this progress keeps up. --- Closes #49 Closes #6 (The last will be removed as part of #51 ) CC: #53 Co-authored-by: xFrednet <[email protected]>
2 parents 9cc40b1 + 627295d commit 3a7cd8f

29 files changed

+793
-351
lines changed

linter_adapter/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod context;
88
mod loader;
99

1010
use linter_api::{
11-
ast::{item::ItemType, Crate},
11+
ast::{item::ItemKind, Crate},
1212
context::AstContext,
1313
lint::Lint,
1414
LintPass,
@@ -37,10 +37,10 @@ impl<'ast> Adapter<'ast> {
3737

3838
for item in krate.items() {
3939
match item {
40-
ItemType::Mod(data) => self.external_lint_crates.check_mod(cx, data),
41-
ItemType::ExternCrate(data) => self.external_lint_crates.check_extern_crate(cx, data),
42-
ItemType::UseDecl(data) => self.external_lint_crates.check_use_decl(cx, data),
43-
ItemType::Static(data) => self.external_lint_crates.check_static_item(cx, data),
40+
ItemKind::Mod(data) => self.external_lint_crates.check_mod(cx, data),
41+
ItemKind::ExternCrate(data) => self.external_lint_crates.check_extern_crate(cx, data),
42+
ItemKind::UseDecl(data) => self.external_lint_crates.check_use_decl(cx, data),
43+
ItemKind::Static(data) => self.external_lint_crates.check_static_item(cx, data),
4444
_ => {},
4545
}
4646
}

linter_api/src/ast/common.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ pub trait Attribute<'ast>: Debug {
119119
// FIXME: Add attribute functions
120120
}
121121

122-
pub trait Pattern<'ast> {}
123-
124122
#[repr(C)]
125123
#[derive(Debug, PartialEq, Eq, Hash)]
126124
pub struct TraitRef<'ast> {

linter_api/src/ast/common/callable.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::{
66

77
use super::{Abi, Span, SpanId, SymbolId};
88

9-
/// This trait provides informations about callable items and types. Some
9+
/// This trait provides information about callable items and types. Some
1010
/// properties might not be available for every callable object. In those
1111
/// cases the default value will be returned.
12-
pub trait Callable<'ast> {
12+
pub trait CallableData<'ast> {
1313
/// Returns `true`, if this callable is `const`.
1414
///
1515
/// Defaults to `false` if unspecified.
@@ -40,12 +40,12 @@ pub trait Callable<'ast> {
4040

4141
/// Returns `true`, if this callable has a specified `self` argument. The
4242
/// type of `self` can be retrieved from the first element of
43-
/// [`Callable::params()`].
43+
/// [`CallableData::params()`].
4444
fn has_self(&self) -> bool;
4545

4646
/// Returns the parameters, that this callable accepts. The `self` argument
4747
/// of methods, will be the first element of this slice. Use
48-
/// [`Callable::has_self`] to determine if the first argument is `self`.
48+
/// [`CallableData::has_self`] to determine if the first argument is `self`.
4949
fn params(&self) -> &[Parameter<'ast>];
5050

5151
/// Returns the return type, if specified.
@@ -55,6 +55,7 @@ pub trait Callable<'ast> {
5555
#[repr(C)]
5656
#[derive(Debug, PartialEq, Eq, Hash)]
5757
pub struct Parameter<'ast> {
58+
// FIXME: This shouldn't be a name but a pattern...
5859
name: FfiOption<SymbolId>,
5960
ty: FfiOption<TyKind<'ast>>,
6061
span: FfiOption<SpanId>,
@@ -93,7 +94,7 @@ impl<'ast> Parameter<'ast> {
9394
#[repr(C)]
9495
#[derive(Debug, PartialEq, Eq, Hash)]
9596
#[cfg_attr(feature = "driver-api", visibility::make(pub))]
96-
pub(crate) struct CallableData<'ast> {
97+
pub(crate) struct CommonCallableData<'ast> {
9798
pub(crate) is_const: bool,
9899
pub(crate) is_async: bool,
99100
pub(crate) is_unsafe: bool,
@@ -106,7 +107,7 @@ pub(crate) struct CallableData<'ast> {
106107

107108
#[cfg(feature = "driver-api")]
108109
#[allow(clippy::fn_params_excessive_bools, clippy::too_many_arguments)]
109-
impl<'ast> CallableData<'ast> {
110+
impl<'ast> CommonCallableData<'ast> {
110111
pub fn new(
111112
is_const: bool,
112113
is_async: bool,
@@ -130,9 +131,11 @@ impl<'ast> CallableData<'ast> {
130131
}
131132
}
132133

133-
macro_rules! impl_callable_trait {
134+
/// This macro automatically implements the [`Callable`] trait for structs that
135+
/// have a [`CallableData`] field called `callable_data`.
136+
macro_rules! impl_callable_data_trait {
134137
($self_ty:ty) => {
135-
impl<'ast> $crate::ast::common::Callable<'ast> for $self_ty {
138+
impl<'ast> $crate::ast::common::CallableData<'ast> for $self_ty {
136139
fn is_const(&self) -> bool {
137140
self.callable_data.is_const
138141
}
@@ -160,4 +163,4 @@ macro_rules! impl_callable_trait {
160163
}
161164
};
162165
}
163-
pub(crate) use impl_callable_trait;
166+
pub(crate) use impl_callable_data_trait;

linter_api/src/ast/generic/bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::Lifetime;
66
#[repr(C)]
77
#[derive(Debug, PartialEq, Eq, Hash)]
88
#[non_exhaustive]
9-
pub enum TypeParamBound<'ast> {
9+
pub enum TyParamBound<'ast> {
1010
Lifetime(&'ast Lifetime<'ast>),
1111
TraitBound(&'ast TraitBound<'ast>),
1212
}

linter_api/src/ast/generic/clause.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
ffi::{FfiOption, FfiSlice},
44
};
55

6-
use super::{GenericParams, Lifetime, TypeParamBound};
6+
use super::{GenericParams, Lifetime, TyParamBound};
77

88
/// This represents a single clause in a where statement
99
///
@@ -58,13 +58,13 @@ impl<'ast> LifetimeClause<'ast> {
5858
pub struct TyClause<'ast> {
5959
params: FfiOption<GenericParams<'ast>>,
6060
ty: TyKind<'ast>,
61-
bounds: FfiSlice<'ast, TypeParamBound<'ast>>,
61+
bounds: FfiSlice<'ast, TyParamBound<'ast>>,
6262
}
6363

6464
impl<'ast> TyClause<'ast> {
6565
/// Additional parameters introduced as part of this where clause with a `for`.
66-
pub fn params(&self) -> &FfiOption<GenericParams<'ast>> {
67-
&self.params
66+
pub fn params(&self) -> Option<&GenericParams<'ast>> {
67+
self.params.get()
6868
}
6969

7070
/// The type that is bound
@@ -73,14 +73,14 @@ impl<'ast> TyClause<'ast> {
7373
}
7474

7575
/// The bounds applied to the specified type.
76-
pub fn bounds(&self) -> &FfiSlice<'ast, TypeParamBound<'ast>> {
77-
&self.bounds
76+
pub fn bounds(&self) -> &'ast [TyParamBound<'ast>] {
77+
self.bounds.get()
7878
}
7979
}
8080

8181
#[cfg(feature = "driver-api")]
8282
impl<'ast> TyClause<'ast> {
83-
pub fn new(params: Option<GenericParams<'ast>>, ty: TyKind<'ast>, bounds: &'ast [TypeParamBound<'ast>]) -> Self {
83+
pub fn new(params: Option<GenericParams<'ast>>, ty: TyKind<'ast>, bounds: &'ast [TyParamBound<'ast>]) -> Self {
8484
Self {
8585
params: params.into(),
8686
ty,

linter_api/src/ast/generic/param.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ast::{GenericId, Span, SpanId, SymbolId};
22
use crate::context::with_cx;
33
use crate::ffi::{FfiOption, FfiSlice};
44

5-
use super::{Lifetime, TypeParamBound};
5+
use super::{Lifetime, TyParamBound};
66

77
/// A singular generic parameter, like `'a` and `T` in this example:
88
///
@@ -65,13 +65,13 @@ pub trait GenericParamData<'ast> {
6565
pub struct TyParam<'ast> {
6666
id: GenericId,
6767
name: SymbolId,
68-
bounds: FfiSlice<'ast, TypeParamBound<'ast>>,
68+
bounds: FfiSlice<'ast, TyParamBound<'ast>>,
6969
span: FfiOption<SpanId>,
7070
}
7171

7272
#[cfg(feature = "driver-api")]
7373
impl<'ast> TyParam<'ast> {
74-
pub fn new(span: Option<SpanId>, name: SymbolId, id: GenericId, bounds: &'ast [TypeParamBound<'ast>]) -> Self {
74+
pub fn new(span: Option<SpanId>, name: SymbolId, id: GenericId, bounds: &'ast [TyParamBound<'ast>]) -> Self {
7575
Self {
7676
id,
7777
name,

0 commit comments

Comments
 (0)