Struct rustc_lint::LateContext[−][src]

pub struct LateContext<'tcx> {
    pub tcx: TyCtxt<'tcx>,
    pub enclosing_body: Option<BodyId>,
    pub(crate) cached_typeck_results: Cell<Option<&'tcx TypeckResults<'tcx>>>,
    pub param_env: ParamEnv<'tcx>,
    pub access_levels: &'tcx AccessLevels,
    pub lint_store: &'tcx LintStore,
    pub last_node_with_lint_attrs: HirId,
    pub generics: Option<&'tcx Generics<'tcx>>,
    pub only_module: bool,
}
Expand description

Context for lint checking after type checking.

Fields

tcx: TyCtxt<'tcx>
Expand description

Type context we’re checking in.

enclosing_body: Option<BodyId>
Expand description

Current body, or None if outside a body.

cached_typeck_results: Cell<Option<&'tcx TypeckResults<'tcx>>>
Expand description

Type-checking results for the current body. Access using the typeck_results and maybe_typeck_results methods, which handle querying the typeck results on demand.

param_env: ParamEnv<'tcx>
Expand description

Parameter environment for the item we are in.

access_levels: &'tcx AccessLevels
Expand description

Items accessible from the crate being checked.

lint_store: &'tcx LintStore
Expand description

The store of registered lints and the lint levels.

last_node_with_lint_attrs: HirIdgenerics: Option<&'tcx Generics<'tcx>>
Expand description

Generic type parameters in scope for the item we are in.

only_module: bool
Expand description

We are only looking at one module

Implementations

impl<'tcx> LateContext<'tcx>[src]

pub fn maybe_typeck_results(&self) -> Option<&'tcx TypeckResults<'tcx>>[src]

Gets the type-checking results for the current body, or None if outside a body.

pub fn typeck_results(&self) -> &'tcx TypeckResults<'tcx>[src]

Gets the type-checking results for the current body. As this will ICE if called outside bodies, only call when working with Expr or Pat nodes (they are guaranteed to be found only in bodies).

pub fn qpath_res(&self, qpath: &QPath<'_>, id: HirId) -> Res[src]

Returns the final resolution of a QPath, or Res::Err if unavailable. Unlike .typeck_results().qpath_res(qpath, id), this can be used even outside bodies (e.g. for paths in hir::Ty), without any risk of ICE-ing.

pub fn match_def_path(&self, def_id: DefId, path: &[Symbol]) -> bool[src]

Check if a DefId’s path matches the given absolute type path usage.

Anonymous scopes such as extern imports are matched with kw::Empty; inherent impl blocks are matched with the name of the type.

Instead of using this method, it is often preferable to instead use rustc_diagnostic_item or a lang_item. This is less prone to errors as paths get invalidated if the target definition moves.

Examples

ⓘ
if cx.match_def_path(def_id, &[sym::core, sym::option, sym::Option]) {
    // The given `def_id` is that of an `Option` type
}

Used by clippy, but should be replaced by diagnostic items eventually.

pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol>[src]

Gets the absolute path of def_id as a vector of Symbol.

Examples

ⓘ
let def_path = cx.get_def_path(def_id);
if let &[sym::core, sym::option, sym::Option] = &def_path[..] {
    // The given `def_id` is that of an `Option` type
}

Trait Implementations

impl<'tcx> LayoutOf for LateContext<'tcx>[src]

type Ty = Ty<'tcx>

type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>

fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout[src]

fn spanned_layout_of(&self, ty: Self::Ty, _span: Span) -> Self::TyAndLayout[src]

impl LintContext for LateContext<'_>[src]

fn sess(&self) -> &Session[src]

Gets the overall compiler Session object.

type PassObject = Box<dyn LateLintPass<'tcx> + Send + Sync + 'static>

fn lints(&self) -> &LintStore[src]

fn lookup<S: Into<MultiSpan>>(
    &self,
    lint: &'static Lint,
    span: Option<S>,
    decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)
[src]

fn lookup_with_diagnostics(
    &self,
    lint: &'static Lint,
    span: Option<impl Into<MultiSpan>>,
    decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
    diagnostic: BuiltinLintDiagnostics
)
[src]

fn struct_span_lint<S: Into<MultiSpan>>(
    &self,
    lint: &'static Lint,
    span: S,
    decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)
[src]

fn lint(
    &self,
    lint: &'static Lint,
    decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)
[src]

Emit a lint at the appropriate level, with no associated span.

Auto Trait Implementations

impl<'tcx> !RefUnwindSafe for LateContext<'tcx>

impl<'tcx> !Send for LateContext<'tcx>

impl<'tcx> !Sync for LateContext<'tcx>

impl<'tcx> Unpin for LateContext<'tcx>

impl<'tcx> !UnwindSafe for LateContext<'tcx>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.