Fix fallout

This commit is contained in:
Oliver Schneider 2017-04-06 16:49:13 +02:00
parent f32fab1c8f
commit a679f41fa3
11 changed files with 19 additions and 20 deletions

View File

@ -103,7 +103,7 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
if_let_chain! {[
let ast::ExprKind::Block(ref block) = else_.node,
let Some(ref else_) = expr_block(block),
let Some(else_) = expr_block(block),
!in_macro(else_.span),
], {
match else_.node {

View File

@ -228,7 +228,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node {
conds.push(&**cond);
if let ExprBlock(ref block) = then_expr.node {
blocks.push(&block);
blocks.push(block);
} else {
panic!("ExprIf node is not an ExprBlock");
}

View File

@ -894,7 +894,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
match def {
Def::Local(..) | Def::Upvar(..) => {
let def_id = def.def_id();
let node_id = self.cx.tcx.hir.as_local_node_id(def_id).unwrap();
let node_id = self.cx.tcx.hir.as_local_node_id(def_id).expect("local/upvar are local nodes");
let extent = self.cx.tcx.region_maps.var_scope(node_id);
self.indexed.insert(seqvar.segments[0].name, Some(extent));

View File

@ -649,7 +649,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if name == method_name &&
sig.decl.inputs.len() == n_args &&
out_type.matches(&sig.decl.output) &&
self_kind.matches(&first_arg_ty, &first_arg, &self_ty, false) {
self_kind.matches(first_arg_ty, first_arg, self_ty, false) {
span_lint(cx, SHOULD_IMPLEMENT_TRAIT, implitem.span, &format!(
"defining a method called `{}` on this type; consider implementing \
the `{}` trait or choosing a less ambiguous name", name, trait_name));
@ -662,7 +662,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
for &(ref conv, self_kinds) in &CONVENTIONS {
if_let_chain! {[
conv.check(&name.as_str()),
!self_kinds.iter().any(|k| k.matches(&first_arg_ty, &first_arg, &self_ty, is_copy)),
!self_kinds.iter().any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy)),
], {
let lint = if item.vis == hir::Visibility::Public {
WRONG_PUB_SELF_CONVENTION

View File

@ -499,9 +499,9 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
/// Test whether an expression is in a macro expansion (e.g. something generated by
/// `#[derive(...)`] or the like).
fn in_attributes_expansion(expr: &Expr) -> bool {
expr.span.ctxt.outer().expn_info().map(|info| {
expr.span.ctxt.outer().expn_info().map_or(false, |info| {
matches!(info.callee.format, ExpnFormat::MacroAttribute(_))
}).unwrap_or(false)
})
}
/// Test whether `def` is a variable defined outside a macro.

View File

@ -40,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if_let_chain! {[
let ItemImpl(_, _, _, Some(ref trait_ref), _, ref impl_items) = item.node,
!is_automatically_derived(&*item.attrs),
trait_ref.path.def.def_id() == cx.tcx.lang_items.eq_trait().unwrap(),
let Some(eq_trait) = cx.tcx.lang_items.eq_trait(),
trait_ref.path.def.def_id() == eq_trait
], {
for impl_item in impl_items {
if impl_item.name == "ne" {

View File

@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StepByZero {
let ExprMethodCall( Spanned { node: iter_name, .. }, _, ref iter_args ) = *iter,
iter_name == "iter",
// range expression in .zip() call: 0..x.len()
let Some(higher::Range { start: Some(ref start), end: Some(ref end), .. }) = higher::range(zip_arg),
let Some(higher::Range { start: Some(start), end: Some(end), .. }) = higher::range(zip_arg),
is_integer_literal(start, 0),
// .len() call
let ExprMethodCall(Spanned { node: len_name, .. }, _, ref len_args) = end.node,

View File

@ -107,7 +107,7 @@ impl ReturnPass {
// we need both a let-binding stmt and an expr
if_let_chain! {[
let Some(ref retexpr) = it.next_back(),
let Some(retexpr) = it.next_back(),
let ast::StmtKind::Expr(ref retexpr) = retexpr.node,
let Some(stmt) = it.next_back(),
let ast::StmtKind::Local(ref local) = stmt.node,

View File

@ -115,13 +115,11 @@ fn check_manual_swap(cx: &LateContext, block: &Block) {
} else {
(false, "".to_owned(), "".to_owned())
}
} else {
if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) {
} else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) {
(true, format!(" `{}` and `{}`", first, second),
format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr()))
} else {
(true, "".to_owned(), "".to_owned())
}
};
let span = Span { lo: w[0].span.lo, hi: second.span.hi, ctxt: NO_EXPANSION};

View File

@ -118,7 +118,7 @@ fn check_ty(cx: &LateContext, ast_ty: &Ty) {
let last = last_path_segment(qpath);
if_let_chain! {[
let PathParameters::AngleBracketedParameters(ref ag) = last.parameters,
let Some(ref vec) = ag.types.get(0),
let Some(vec) = ag.types.get(0),
let TyPath(ref qpath) = vec.node,
let def::Def::Struct(..) = cx.tables.qpath_def(qpath, vec.id),
let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, vec.id)),

View File

@ -112,12 +112,12 @@ pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
/// Returns true if this `expn_info` was expanded by any macro.
pub fn in_macro(span: Span) -> bool {
span.ctxt.outer().expn_info().map(|info| {
span.ctxt.outer().expn_info().map_or(false, |info| {
match info.callee.format {// don't treat range expressions desugared to structs as "in_macro"
ExpnFormat::CompilerDesugaring(name) => name != "...",
_ => true,
}
}).unwrap_or(false)
})
}
/// Returns true if the macro that expanded the crate was outside of the current crate or was a
@ -138,7 +138,7 @@ pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool {
})
}
span.ctxt.outer().expn_info().map(|info| in_macro_ext(cx, &info)).unwrap_or(false)
span.ctxt.outer().expn_info().map_or(false, |info| in_macro_ext(cx, &info))
}
/// Check if a `DefId`'s path matches the given absolute type path usage.