Skip to content

Commit

Permalink
Merge #54
Browse files Browse the repository at this point in the history
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 <xFrednet@gmail.com>
  • Loading branch information
bors[bot] and xFrednet committed Nov 19, 2022
2 parents 9cc40b1 + 627295d commit 3a7cd8f
Show file tree
Hide file tree
Showing 29 changed files with 793 additions and 351 deletions.
10 changes: 5 additions & 5 deletions linter_adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod context;
mod loader;

use linter_api::{
ast::{item::ItemType, Crate},
ast::{item::ItemKind, Crate},
context::AstContext,
lint::Lint,
LintPass,
Expand Down Expand Up @@ -37,10 +37,10 @@ impl<'ast> Adapter<'ast> {

for item in krate.items() {
match item {
ItemType::Mod(data) => self.external_lint_crates.check_mod(cx, data),
ItemType::ExternCrate(data) => self.external_lint_crates.check_extern_crate(cx, data),
ItemType::UseDecl(data) => self.external_lint_crates.check_use_decl(cx, data),
ItemType::Static(data) => self.external_lint_crates.check_static_item(cx, data),
ItemKind::Mod(data) => self.external_lint_crates.check_mod(cx, data),
ItemKind::ExternCrate(data) => self.external_lint_crates.check_extern_crate(cx, data),
ItemKind::UseDecl(data) => self.external_lint_crates.check_use_decl(cx, data),
ItemKind::Static(data) => self.external_lint_crates.check_static_item(cx, data),
_ => {},
}
}
Expand Down
2 changes: 0 additions & 2 deletions linter_api/src/ast/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ pub trait Attribute<'ast>: Debug {
// FIXME: Add attribute functions
}

pub trait Pattern<'ast> {}

#[repr(C)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct TraitRef<'ast> {
Expand Down
21 changes: 12 additions & 9 deletions linter_api/src/ast/common/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::{

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

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

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

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

/// Returns the return type, if specified.
Expand All @@ -55,6 +55,7 @@ pub trait Callable<'ast> {
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Parameter<'ast> {
// FIXME: This shouldn't be a name but a pattern...
name: FfiOption<SymbolId>,
ty: FfiOption<TyKind<'ast>>,
span: FfiOption<SpanId>,
Expand Down Expand Up @@ -93,7 +94,7 @@ impl<'ast> Parameter<'ast> {
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "driver-api", visibility::make(pub))]
pub(crate) struct CallableData<'ast> {
pub(crate) struct CommonCallableData<'ast> {
pub(crate) is_const: bool,
pub(crate) is_async: bool,
pub(crate) is_unsafe: bool,
Expand All @@ -106,7 +107,7 @@ pub(crate) struct CallableData<'ast> {

#[cfg(feature = "driver-api")]
#[allow(clippy::fn_params_excessive_bools, clippy::too_many_arguments)]
impl<'ast> CallableData<'ast> {
impl<'ast> CommonCallableData<'ast> {
pub fn new(
is_const: bool,
is_async: bool,
Expand All @@ -130,9 +131,11 @@ impl<'ast> CallableData<'ast> {
}
}

macro_rules! impl_callable_trait {
/// This macro automatically implements the [`Callable`] trait for structs that
/// have a [`CallableData`] field called `callable_data`.
macro_rules! impl_callable_data_trait {
($self_ty:ty) => {
impl<'ast> $crate::ast::common::Callable<'ast> for $self_ty {
impl<'ast> $crate::ast::common::CallableData<'ast> for $self_ty {
fn is_const(&self) -> bool {
self.callable_data.is_const
}
Expand Down Expand Up @@ -160,4 +163,4 @@ macro_rules! impl_callable_trait {
}
};
}
pub(crate) use impl_callable_trait;
pub(crate) use impl_callable_data_trait;
2 changes: 1 addition & 1 deletion linter_api/src/ast/generic/bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::Lifetime;
#[repr(C)]
#[derive(Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TypeParamBound<'ast> {
pub enum TyParamBound<'ast> {
Lifetime(&'ast Lifetime<'ast>),
TraitBound(&'ast TraitBound<'ast>),
}
Expand Down
14 changes: 7 additions & 7 deletions linter_api/src/ast/generic/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
ffi::{FfiOption, FfiSlice},
};

use super::{GenericParams, Lifetime, TypeParamBound};
use super::{GenericParams, Lifetime, TyParamBound};

/// This represents a single clause in a where statement
///
Expand Down Expand Up @@ -58,13 +58,13 @@ impl<'ast> LifetimeClause<'ast> {
pub struct TyClause<'ast> {
params: FfiOption<GenericParams<'ast>>,
ty: TyKind<'ast>,
bounds: FfiSlice<'ast, TypeParamBound<'ast>>,
bounds: FfiSlice<'ast, TyParamBound<'ast>>,
}

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

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

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

#[cfg(feature = "driver-api")]
impl<'ast> TyClause<'ast> {
pub fn new(params: Option<GenericParams<'ast>>, ty: TyKind<'ast>, bounds: &'ast [TypeParamBound<'ast>]) -> Self {
pub fn new(params: Option<GenericParams<'ast>>, ty: TyKind<'ast>, bounds: &'ast [TyParamBound<'ast>]) -> Self {
Self {
params: params.into(),
ty,
Expand Down
6 changes: 3 additions & 3 deletions linter_api/src/ast/generic/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::ast::{GenericId, Span, SpanId, SymbolId};
use crate::context::with_cx;
use crate::ffi::{FfiOption, FfiSlice};

use super::{Lifetime, TypeParamBound};
use super::{Lifetime, TyParamBound};

/// A singular generic parameter, like `'a` and `T` in this example:
///
Expand Down Expand Up @@ -65,13 +65,13 @@ pub trait GenericParamData<'ast> {
pub struct TyParam<'ast> {
id: GenericId,
name: SymbolId,
bounds: FfiSlice<'ast, TypeParamBound<'ast>>,
bounds: FfiSlice<'ast, TyParamBound<'ast>>,
span: FfiOption<SpanId>,
}

#[cfg(feature = "driver-api")]
impl<'ast> TyParam<'ast> {
pub fn new(span: Option<SpanId>, name: SymbolId, id: GenericId, bounds: &'ast [TypeParamBound<'ast>]) -> Self {
pub fn new(span: Option<SpanId>, name: SymbolId, id: GenericId, bounds: &'ast [TyParamBound<'ast>]) -> Self {
Self {
id,
name,
Expand Down
Loading

0 comments on commit 3a7cd8f

Please sign in to comment.