use crate::{
ast::{expr::ConstExpr, ty::TyKind, TraitRef},
common::{SpanId, SymbolId},
context::with_cx,
span::Span,
};
use super::Lifetime;
#[repr(C)]
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub struct LifetimeArg<'ast> {
lifetime: Lifetime<'ast>,
}
impl<'ast> LifetimeArg<'ast> {
pub fn lifetime(&self) -> &Lifetime<'ast> {
&self.lifetime
}
pub fn span(&self) -> &Span<'ast> {
self.lifetime
.span()
.expect("every lifetime inside syntactic `SynLifetimeArg` should have a span")
}
}
#[cfg(feature = "driver-api")]
impl<'ast> LifetimeArg<'ast> {
pub fn new(lifetime: Lifetime<'ast>) -> Self {
Self { lifetime }
}
}
#[repr(C)]
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub struct TyArg<'ast> {
ty: TyKind<'ast>,
}
impl<'ast> TyArg<'ast> {
pub fn ty(&self) -> TyKind<'_> {
self.ty
}
pub fn span(&self) -> &Span<'ast> {
self.ty.span()
}
}
#[cfg(feature = "driver-api")]
impl<'ast> TyArg<'ast> {
pub fn new(ty: TyKind<'ast>) -> Self {
Self { ty }
}
}
#[repr(C)]
#[derive(Debug)]
pub struct BindingArg<'ast> {
span: SpanId,
ident: SymbolId,
ty: TyKind<'ast>,
}
impl<'ast> BindingArg<'ast> {
pub fn ident(&self) -> &str {
with_cx(self, |cx| cx.symbol_str(self.ident))
}
pub fn ty(&self) -> TyKind<'ast> {
self.ty
}
pub fn span(&self) -> &Span<'ast> {
with_cx(self, |cx| cx.span(self.span))
}
}
#[cfg(feature = "driver-api")]
impl<'ast> BindingArg<'ast> {
pub fn new(span: SpanId, ident: SymbolId, ty: TyKind<'ast>) -> Self {
Self { span, ident, ty }
}
}
#[derive(Debug)]
pub struct ConstArg<'ast> {
span: SpanId,
expr: ConstExpr<'ast>,
}
impl<'ast> ConstArg<'ast> {
pub fn expr(&self) -> &ConstExpr<'ast> {
&self.expr
}
pub fn span(&self) -> &Span<'ast> {
with_cx(self, |cx| cx.span(self.span))
}
}
#[cfg(feature = "driver-api")]
impl<'ast> ConstArg<'ast> {
pub fn new(span: SpanId, expr: ConstExpr<'ast>) -> Self {
Self { span, expr }
}
}
#[repr(C)]
#[derive(Debug)]
#[non_exhaustive]
pub enum TyParamBound<'ast> {
Lifetime(&'ast Lifetime<'ast>),
TraitBound(&'ast TraitBound<'ast>),
}
#[repr(C)]
#[derive(Debug)]
pub struct TraitBound<'ast> {
is_relaxed: bool,
trait_ref: TraitRef<'ast>,
span: SpanId,
}
impl<'ast> TraitBound<'ast> {
pub fn trait_ref(&self) -> &TraitRef<'ast> {
&self.trait_ref
}
pub fn is_relaxed(&self) -> bool {
self.is_relaxed
}
pub fn span(&self) -> &Span<'ast> {
with_cx(self, |cx| cx.span(self.span))
}
}
#[cfg(feature = "driver-api")]
impl<'ast> TraitBound<'ast> {
pub fn new(is_relaxed: bool, trait_ref: TraitRef<'ast>, span: SpanId) -> Self {
Self {
is_relaxed,
trait_ref,
span,
}
}
}