[−][src]Struct rustc_lint::context::LateContext

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,
}

Context for lint checking after type checking.

Fields

tcx: TyCtxt<'tcx>

Type context we're checking in.

enclosing_body: Option<BodyId>

Current body, or None if outside a body.

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

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>

Parameter environment for the item we are in.

access_levels: &'tcx AccessLevels

Items accessible from the crate being checked.

lint_store: &'tcx LintStore

The store of registered lints and the lint levels.

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

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

only_module: bool

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::Invalid; 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

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

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

ⓘThis example is not tested
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>>

impl<'_> LintContext for LateContext<'_>[src]

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

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

Gets the overall compiler Session object.

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]

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

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

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

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

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.

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.