clippy_lints 0.0.155

A bunch of helpful lints to avoid common pitfalls in Rust
Documentation
//! A late lint context that is aware of tables and bodies

use rustc::lint::{LateContext, LintContext, LintStore, LateLintPassObject, Lint};
use rustc::ty::{TypeckTables, TyCtxt};
use rustc::session::Session;
use rustc_errors::DiagnosticBuilder;

use syntax::ast;
use syntax::codemap::MultiSpan;

struct ClippyContext<'a, 'tcx: 'a> {
    pub cx: &'a LateContext<'a, 'tcx>,
    pub tables: &'a TypeckTables<'tcx>,
}

impl<'a, 'tcx> ClippyContext<'a, 'tcx> {

}

impl<'a, 'tcx> ::std::ops::Deref for ClippyContext<'a, 'tcx> {
    type Target = TyCtxt<'a, 'tcx, 'tcx>;
    fn deref(&self) -> &Self::Target {
        &self.cx.tcx
    }
}

impl<'a, 'tcx> From<&'a LateContext<'a, 'tcx>> for ClippyContext<'a, 'tcx> {
    fn from(cx: &'a LateContext<'a, 'tcx>) -> Self {
        Self {
            cx,
            tables: cx.tables,
        }
    }
}

impl<'a, 'tcx> LintContext<'tcx> for ClippyContext<'a, 'tcx> {
    type PassObject = LateLintPassObject;
    fn sess(&self) -> &Session {
        self.cx.sess()
    }

    fn lints(&self) -> &LintStore {
        self.cx.lints()
    }

    fn lint_sess(&self) -> &LintSession<'tcx, Self::PassObject> {
        self.cx.lint_sess()
    }

    fn lint_sess_mut(&mut self) -> &mut LintSession<'tcx, Self::PassObject> {
        self.cx.lint_sess_mut()
    }

    fn lookup<S: Into<MultiSpan>>(&self,
                                  lint: &'static Lint,
                                  span: Option<S>,
                                  msg: &str)
                                  -> DiagnosticBuilder {
        self.cx.lookup(lint, span, msg)
    }

    fn with_lint_attrs<F>(&mut self,
                          _: ast::NodeId,
                          _: &'tcx [ast::Attribute],
                          _: F)
        where F: FnOnce(&mut Self)
    {
        panic!("not needed")
    }

    fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
        self.cx.enter_attrs(attrs)
    }

    fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]) {
        self.cx.exit_attrs(attrs)
    }
}