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 AccessLevelsExpand description
Items accessible from the crate being checked.
lint_store: &'tcx LintStoreExpand 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: boolExpand description
We are only looking at one module
Implementations
impl<'tcx> LateContext<'tcx>[src]
impl<'tcx> LateContext<'tcx>[src]pub fn maybe_typeck_results(&self) -> Option<&'tcx TypeckResults<'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]
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]
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]
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.
Trait Implementations
impl<'tcx> LayoutOf for LateContext<'tcx>[src]
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]
impl LintContext for LateContext<'_>[src]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]
&self,
lint: &'static Lint,
span: Option<S>,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)
fn lookup_with_diagnostics(
&self,
lint: &'static Lint,
span: Option<impl Into<MultiSpan>>,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
diagnostic: BuiltinLintDiagnostics
)[src]
&self,
lint: &'static Lint,
span: Option<impl Into<MultiSpan>>,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>),
diagnostic: BuiltinLintDiagnostics
)
fn struct_span_lint<S: Into<MultiSpan>>(
&self,
lint: &'static Lint,
span: S,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)[src]
&self,
lint: &'static Lint,
span: S,
decorate: impl for<'a> FnOnce(LintDiagnosticBuilder<'a>)
)
fn lint(
&self,
lint: &'static Lint,
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.