#[repr(C)]
pub struct AstContext<'ast> { /* private fields */ }
Expand description

This context will be passed to each LintPass call to enable the user to emit lints and to retrieve nodes by the given ids.

Implementations§

source§

impl<'ast> AstContext<'ast>

source

pub fn lint_level_at( &self, lint: &'static Lint, node: impl Into<EmissionNode> ) -> Level

source

pub fn emit_lint<F>( &self, lint: &'static Lint, node: impl Into<EmissionNode>, msg: impl ToString, span: &Span<'ast>, decorate: F )where F: FnOnce(&mut DiagnosticBuilder<'ast>),

source

pub fn item(&self, id: ItemId) -> Option<ItemKind<'ast>>

This returns the ItemKind belonging to the given ItemId. It can return None in special cases depending on the used driver.

Driver information
  • Rustc’s driver will always return a valid item.
source

pub fn body(&self, id: BodyId) -> &Body<'ast>

source

pub fn resolve_ty_ids(&self, path: &str) -> &[TyDefId]

This function tries to resolve the given path to the corresponding TyDefId.

The slice might be empty if the path could not be resolved. This could be due to an error in the path or because the linted crate doesn’t have the required dependency. The function can also return multiple TyDefIds, if there are multiple crates with different versions in the dependency tree.

The returned ids are unordered and, depending on the driver, can also change during different calls. The slice should not be stored across check_* calls.

Here is a simple example, how the method could be used:

// Get the type of an expression and check that it's an ADT
if let SemTyKind::Adt(ty) = expr.ty() {
    // Check if the id belongs to the path
    if cx.resolve_ty_ids("example::path::Item").contains(&ty.ty_id()) {
        // ...
    }
}

Trait Implementations§

source§

impl<'ast> Debug for AstContext<'ast>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'ast> Hash for AstContext<'ast>

source§

fn hash<H: Hasher>(&self, _state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'ast> PartialEq<AstContext<'ast>> for AstContext<'ast>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ast> Eq for AstContext<'ast>

Auto Trait Implementations§

§

impl<'ast> RefUnwindSafe for AstContext<'ast>

§

impl<'ast> Send for AstContext<'ast>

§

impl<'ast> Sync for AstContext<'ast>

§

impl<'ast> Unpin for AstContext<'ast>

§

impl<'ast> UnwindSafe for AstContext<'ast>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.