mirror of https://github.com/rwf2/Rocket.git
Update lints for latest nightly.
This commit is contained in:
parent
74805df1fc
commit
35589738a1
|
@ -8,8 +8,8 @@ use yansi::Color::{Red, Yellow, Blue, White};
|
|||
use version_check::{supports_features, is_min_version, is_min_date};
|
||||
|
||||
// Specifies the minimum nightly version needed to compile Rocket's codegen.
|
||||
const MIN_DATE: &'static str = "2017-08-10";
|
||||
const MIN_VERSION: &'static str = "1.21.0-nightly";
|
||||
const MIN_DATE: &'static str = "2017-09-01";
|
||||
const MIN_VERSION: &'static str = "1.22.0-nightly";
|
||||
|
||||
fn main() {
|
||||
let ok_channel = supports_features();
|
||||
|
|
|
@ -37,13 +37,15 @@ struct InstanceInfo {
|
|||
enum Receiver {
|
||||
Instance(DefId, Span),
|
||||
Call(NodeId, Span),
|
||||
Relative(Span),
|
||||
}
|
||||
|
||||
impl Receiver {
|
||||
/// Returns the span associated with the receiver.
|
||||
pub fn span(&self) -> Span {
|
||||
use self::Receiver::*;
|
||||
match *self {
|
||||
Receiver::Instance(_, sp) | Receiver::Call(_, sp) => sp
|
||||
Instance(_, sp) | Call(_, sp) | Relative(sp) => sp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,9 +144,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RocketLint {
|
|||
// the receiver in the type table we've constructed. If it's there, we use
|
||||
// it, if not, we use the call as the receiver.
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
/// Fetches the top-level `Receiver` instance given that a method call
|
||||
/// was made to the receiver `rexpr`. Top-level here means "the
|
||||
/// original". We search the `instance_vars` table to retrieve it.
|
||||
// Fetches the top-level `Receiver` instance given that a method call
|
||||
// was made to the receiver `rexpr`. Top-level here means "the
|
||||
// original". We search the `instance_vars` table to retrieve it.
|
||||
let instance_for = |lint: &mut RocketLint, rexpr: &Expr| -> Option<Receiver> {
|
||||
match rexpr.node {
|
||||
ExprPath(QPath::Resolved(_, ref p)) => {
|
||||
|
@ -152,8 +154,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RocketLint {
|
|||
.and_then(|id| lint.instance_vars.get(&id))
|
||||
.map(|recvr| recvr.clone())
|
||||
}
|
||||
ExprPath(QPath::TypeRelative(_, _)) => {
|
||||
Some(Receiver::Relative(rexpr.span))
|
||||
}
|
||||
ExprCall(ref c, ..) => Some(Receiver::Call(c.id, rexpr.span)),
|
||||
_ => unreachable!()
|
||||
_ => panic!("Unexpected node: {:?}", rexpr.node)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -256,7 +261,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RocketLint {
|
|||
|
||||
// Collect all of the `State` types and spans into `tys` and `spans`.
|
||||
let mut ty_and_spans: Vec<(Ty<'static>, Span)> = vec![];
|
||||
if let Some(sig) = cx.tables.liberated_fn_sigs.get(&fn_id) {
|
||||
let fn_hir_id = cx.tcx.hir.node_to_hir_id(fn_id);
|
||||
if let Some(sig) = cx.tables.liberated_fn_sigs().get(fn_hir_id) {
|
||||
for (i, input_ty) in sig.inputs().iter().enumerate() {
|
||||
let def_id = match input_ty.ty_to_def_id() {
|
||||
Some(id) => id,
|
||||
|
|
|
@ -46,8 +46,9 @@ pub fn match_def_path(tcx: ty::TyCtxt, def_id: DefId, path: &[&str]) -> bool {
|
|||
|
||||
/// Check if the method call given in `expr` belongs to given type.
|
||||
pub fn is_impl_method(cx: &LateContext, expr: &Expr, path: &[&str]) -> bool {
|
||||
cx.tables.type_dependent_defs
|
||||
.get(&expr.id)
|
||||
let hir_id = cx.tcx.hir.node_to_hir_id(expr.id);
|
||||
cx.tables.type_dependent_defs()
|
||||
.get(hir_id)
|
||||
.and_then(|callee| cx.tcx.impl_of_method(callee.def_id()))
|
||||
.map(|trt_id| match_def_path(cx.tcx, trt_id, path))
|
||||
.unwrap_or(false)
|
||||
|
@ -82,7 +83,8 @@ pub fn rocket_method_call<'e>(method: &str,
|
|||
pub fn is_rocket_start_call(cx: &LateContext, expr: &Expr) -> bool {
|
||||
if let ExprCall(ref expr, ..) = expr.node {
|
||||
if let ExprPath(ref qpath) = expr.node {
|
||||
let def_id = cx.tables.qpath_def(qpath, expr.id).def_id();
|
||||
let hir_id = cx.tcx.hir.node_to_hir_id(expr.id);
|
||||
let def_id = cx.tables.qpath_def(qpath, hir_id).def_id();
|
||||
if match_def_path(cx.tcx, def_id, ROCKET_IGNITE_FN) {
|
||||
return true;
|
||||
} else if match_def_path(cx.tcx, def_id, ROCKET_IGNITE_STATIC) {
|
||||
|
@ -116,7 +118,8 @@ pub fn extract_mount_fn_def_ids(cx: &LateContext, expr: &Expr) -> Vec<DefId> {
|
|||
if let ExprAddrOf(_, ref expr) = args[0].node {
|
||||
// path to info_struct
|
||||
if let ExprPath(ref qpath) = expr.node {
|
||||
let def = cx.tables.qpath_def(qpath, expr.id);
|
||||
let hir_id = cx.tcx.hir.node_to_hir_id(expr.id);
|
||||
let def = cx.tables.qpath_def(qpath, hir_id);
|
||||
output.push(def.def_id());
|
||||
}
|
||||
}
|
||||
|
@ -167,11 +170,11 @@ pub fn msg_and_help<'a, T: LintContext<'a>>(cx: &T,
|
|||
note: &str,
|
||||
help_sp: Option<Span>,
|
||||
help: &str) {
|
||||
let mut b = cx.struct_span_lint(lint, msg_sp, msg);
|
||||
b.note(note);
|
||||
// Be conservative. If we don't know the receiver, don't emit the warning.
|
||||
if let Some(span) = help_sp {
|
||||
b.span_help(span, help);
|
||||
cx.struct_span_lint(lint, msg_sp, msg)
|
||||
.note(note)
|
||||
.span_help(span, help)
|
||||
.emit()
|
||||
}
|
||||
|
||||
b.emit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue