Remove unused cs parameter for is_macro and friends

This commit is contained in:
Enrico Schmitz 2017-04-01 00:14:04 +02:00 committed by Enrico Schmitz
parent 8aef64dfe8
commit 7a4f7c335b
29 changed files with 53 additions and 53 deletions

View File

@ -215,7 +215,7 @@ fn is_relevant_expr(tcx: ty::TyCtxt, tables: &ty::TypeckTables, expr: &Expr) ->
}
fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
if in_macro(cx, span) {
if in_macro(span) {
return;
}

View File

@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
if let Some(ref ex) = block.expr {
// don't dig into the expression here, just suggest that they remove
// the block
if in_macro(cx, expr.span) || differing_macro_contexts(expr.span, ex.span) {
if in_macro(expr.span) || differing_macro_contexts(expr.span, ex.span) {
return;
}
span_help_and_lint(cx,
@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
}
} else {
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
if in_macro(cx, span) || differing_macro_contexts(expr.span, span) {
if in_macro(span) || differing_macro_contexts(expr.span, span) {
return;
}
// move block higher

View File

@ -93,7 +93,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
// prevent folding of `cfg!` macros and the like
if !in_macro(self.cx, e.span) {
if !in_macro(e.span) {
match e.node {
ExprUnary(UnNot, ref inner) => return Ok(Bool::Not(box self.run(inner)?)),
ExprBinary(binop, ref lhs, ref rhs) => {
@ -394,7 +394,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
fn visit_expr(&mut self, e: &'tcx Expr) {
if in_macro(self.cx, e.span) {
if in_macro(e.span) {
return;
}
match e.node {

View File

@ -78,7 +78,7 @@ impl LintPass for CollapsibleIf {
impl EarlyLintPass for CollapsibleIf {
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) {
if !in_macro(cx, expr.span) {
if !in_macro(expr.span) {
check_if(cx, expr)
}
}
@ -104,7 +104,7 @@ 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),
!in_macro(cx, else_.span),
!in_macro(else_.span),
], {
match else_.node {
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {

View File

@ -111,7 +111,7 @@ impl LintPass for CopyAndPaste {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if !in_macro(cx, expr.span) {
if !in_macro(expr.span) {
// skip ifs directly in else, it will be checked in the parent if
if let Some(&Expr { node: ExprIf(_, _, Some(ref else_expr)), .. }) = get_parent_expr(cx, expr) {
if else_expr.id == expr.id {

View File

@ -42,7 +42,7 @@ impl LintPass for CyclomaticComplexity {
impl CyclomaticComplexity {
fn check<'a, 'tcx: 'a>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
if in_macro(cx, span) {
if in_macro(span) {
return;
}

View File

@ -228,7 +228,7 @@ impl EarlyLintPass for EnumVariantNames {
let item_name = item.ident.name.as_str();
let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name);
if !in_macro(cx, item.span) {
if !in_macro(item.span) {
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {

View File

@ -40,7 +40,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let Some(span) = is_expn_of(cx, expr.span, "format") {
if let Some(span) = is_expn_of(expr.span, "format") {
match expr.node {
// `format!("{}", foo)` expansion
ExprCall(ref fun, ref args) => {

View File

@ -99,7 +99,7 @@ impl EarlyLintPass for Formatting {
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(cx, lhs.span) {
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
let eq_span = Span { lo: lhs.span.hi, hi: rhs.span.lo, ctxt: NO_EXPANSION };
if let ast::ExprKind::Unary(op, ref sub_rhs) = rhs.node {
if let Some(eq_snippet) = snippet_opt(cx, eq_span) {
@ -124,7 +124,7 @@ fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else if`.
fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
if let Some((then, &Some(ref else_))) = unsugar_if(expr) {
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(cx, then.span) {
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(then.span) {
// this will be a span from the closing } of the “then” block (excluding) to the
// “if” of the “else if” block (excluding)
let else_span = Span { lo: then.span.hi, hi: else_.span.lo, ctxt: NO_EXPANSION };
@ -174,7 +174,7 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Expr) {
if !differing_macro_contexts(first.span, second.span) && !in_macro(cx, first.span) &&
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) &&
unsugar_if(first).is_some() && unsugar_if(second).is_some() {
// where the else would be
let else_span = Span { lo: first.span.hi, hi: second.span.lo, ctxt: NO_EXPANSION };

View File

@ -33,7 +33,7 @@ impl LintPass for IdentityOp {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(cx, e.span) {
if in_macro(e.span) {
return;
}
if let ExprBinary(ref cmp, ref left, ref right) = e.node {

View File

@ -42,7 +42,7 @@ impl LintPass for ItemsAfterStatements {
impl EarlyLintPass for ItemsAfterStatements {
fn check_block(&mut self, cx: &EarlyContext, item: &Block) {
if in_macro(cx, item.span) {
if in_macro(item.span) {
return;
}
@ -55,7 +55,7 @@ impl EarlyLintPass for ItemsAfterStatements {
// lint on all further items
for stmt in stmts {
if let StmtKind::Item(ref it) = *stmt {
if in_macro(cx, it.span) {
if in_macro(it.span) {
return;
}
if let ItemKind::MacroDef(..) = it.node {

View File

@ -61,7 +61,7 @@ impl LintPass for LenZero {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if in_macro(cx, item.span) {
if in_macro(item.span) {
return;
}
@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
}
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(cx, expr.span) {
if in_macro(expr.span) {
return;
}

View File

@ -342,7 +342,7 @@ fn check_wild_err_arm(cx: &LateContext, ex: &Expr, arms: &[Arm]) {
path_str == "Err",
inner.iter().any(|pat| pat.node == PatKind::Wild),
let ExprBlock(ref block) = arm.body.node,
is_panic_block(cx, block)
is_panic_block(block)
], {
// `Err(_)` arm with `panic!` found
span_note_and_lint(cx,
@ -359,13 +359,13 @@ fn check_wild_err_arm(cx: &LateContext, ex: &Expr, arms: &[Arm]) {
}
// If the block contains only a `panic!` macro (as expression or statement)
fn is_panic_block(cx: &LateContext, block: &Block) -> bool {
fn is_panic_block(block: &Block) -> bool {
match (&block.expr, block.stmts.len(), block.stmts.first()) {
(&Some(ref exp), 0, _) => {
is_expn_of(cx, exp.span, "panic").is_some() && is_expn_of(cx, exp.span, "unreachable").is_none()
is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none()
},
(&None, 1, Some(stmt)) => {
is_expn_of(cx, stmt.span, "panic").is_some() && is_expn_of(cx, stmt.span, "unreachable").is_none()
is_expn_of(stmt.span, "panic").is_some() && is_expn_of(stmt.span, "unreachable").is_none()
},
_ => false,
}

View File

@ -554,7 +554,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// ^ required because `cyclomatic_complexity` attribute shows up as unused
#[cyclomatic_complexity = "30"]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if in_macro(cx, expr.span) {
if in_macro(expr.span) {
return;
}

View File

@ -326,7 +326,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
},
_ => {},
}
if in_attributes_expansion(cx, expr) {
if in_attributes_expansion(expr) {
// Don't lint things expanded by #[derive(...)], etc
return;
}
@ -498,7 +498,7 @@ 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(cx: &LateContext, expr: &Expr) -> bool {
fn in_attributes_expansion(expr: &Expr) -> bool {
expr.span.ctxt.outer().expn_info().map(|info| {
matches!(info.callee.format, ExpnFormat::MacroAttribute(_))
}).unwrap_or(false)
@ -510,7 +510,7 @@ fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool {
def::Def::Local(id) |
def::Def::Upvar(id, _, _) => {
if let Some(span) = cx.tcx.hir.span_if_local(id) {
!in_macro(cx, span)
!in_macro(span)
} else {
true
}

View File

@ -73,7 +73,7 @@ impl MissingDoc {
return;
}
if in_macro(cx, sp) {
if in_macro(sp) {
return;
}

View File

@ -36,7 +36,7 @@ impl LintPass for NeedlessBorrow {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro(cx, e.span) {
if in_macro(e.span) {
return;
}
if let ExprAddrOf(MutImmutable, ref inner) = e.node {
@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
}
}
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
if in_macro(cx, pat.span) {
if in_macro(pat.span) {
return;
}
if_let_chain! {[

View File

@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
span: Span,
node_id: NodeId
) {
if in_macro(cx, span) {
if in_macro(span) {
return;
}

View File

@ -41,7 +41,7 @@ declare_lint! {
}
fn has_no_effect(cx: &LateContext, expr: &Expr) -> bool {
if in_macro(cx, expr.span) {
if in_macro(expr.span) {
return false;
}
match expr.node {
@ -110,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} else if let Some(reduced) = reduce_expression(cx, expr) {
let mut snippet = String::new();
for e in reduced {
if in_macro(cx, e.span) {
if in_macro(e.span) {
return;
}
if let Some(snip) = snippet_opt(cx, e.span) {
@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Expr>> {
if in_macro(cx, expr.span) {
if in_macro(expr.span) {
return None;
}
match expr.node {

View File

@ -135,7 +135,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
}
}
fn check_name(&mut self, span: Span, name: Name) {
if in_macro(self.0.cx, span) {
if in_macro(span) {
return;
}
let interned_name = name.as_str();

View File

@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
let ExprPath(ref qpath) = fun.node,
match_def_path(cx.tcx, resolve_node(cx, qpath, fun.id).def_id(), &paths::BEGIN_PANIC),
let ExprLit(ref lit) = params[0].node,
is_direct_expn_of(cx, params[0].span, "panic").is_some(),
is_direct_expn_of(params[0].span, "panic").is_some(),
let LitKind::Str(ref string, _) = lit.node,
let Some(par) = string.as_str().find('{'),
string.as_str()[par..].contains('}')

View File

@ -77,9 +77,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// Search for `std::io::_print(..)` which is unique in a
// `print!` expansion.
if match_def_path(cx.tcx, fun_id, &paths::IO_PRINT) {
if let Some(span) = is_expn_of(cx, expr.span, "print") {
if let Some(span) = is_expn_of(expr.span, "print") {
// `println!` uses `print!`.
let (span, name) = match is_expn_of(cx, span, "println") {
let (span, name) = match is_expn_of(span, "println") {
Some(span) => (span, "println"),
None => (span, "print"),
};
@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
if let ExprPath(ref qpath) = args[1].node {
let def_id = cx.tables.qpath_def(qpath, args[1].id).def_id();
if match_def_path(cx.tcx, def_id, &paths::DEBUG_FMT_METHOD) && !is_in_debug_impl(cx, expr) &&
is_expn_of(cx, expr.span, "panic").is_none() {
is_expn_of(expr.span, "panic").is_none() {
span_lint(cx, USE_DEBUG, args[0].span, "use of `Debug`-based formatting");
}
}

View File

@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
self.last.is_none(),
let Some(ref expr) = block.expr,
match_type(cx, cx.tables.expr_ty(expr), &paths::REGEX),
let Some(span) = is_expn_of(cx, expr.span, "regex"),
let Some(span) = is_expn_of(expr.span, "regex"),
], {
if !self.spans.contains(&span) {
span_lint(cx,

View File

@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ShouldAssertEq {
let ExprIf(ref cond, ..) = e.node,
let ExprUnary(UnOp::UnNot, ref cond) = cond.node,
let ExprBinary(ref binop, ref expr1, ref expr2) = cond.node,
is_direct_expn_of(cx, e.span, "assert").is_some(),
is_direct_expn_of(e.span, "assert").is_some(),
let Some(debug_trait) = cx.tcx.lang_items.debug_trait(),
], {
let sugg = match binop.node {

View File

@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
if name.node == "as_bytes" {
if let ExprLit(ref lit) = args[0].node {
if let LitKind::Str(ref lit_content, _) = lit.node {
if lit_content.as_str().chars().all(|c| c.is_ascii()) && !in_macro(cx, args[0].span) {
if lit_content.as_str().chars().all(|c| c.is_ascii()) && !in_macro(args[0].span) {
span_lint_and_then(cx,
STRING_LIT_AS_BYTES,
e.span,

View File

@ -107,7 +107,7 @@ fn check_fn_decl(cx: &LateContext, decl: &FnDecl) {
}
fn check_ty(cx: &LateContext, ast_ty: &Ty) {
if in_macro(cx, ast_ty.span) {
if in_macro(ast_ty.span) {
return;
}
match ast_ty.node {
@ -199,7 +199,7 @@ fn check_let_unit(cx: &LateContext, decl: &Decl) {
let bindtype = &cx.tables.pat_ty(&local.pat).sty;
match *bindtype {
ty::TyTuple(slice, _) if slice.is_empty() => {
if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) {
if in_external_macro(cx, decl.span) || in_macro(local.pat.span) {
return;
}
if higher::is_from_for_desugar(decl) {
@ -261,7 +261,7 @@ impl LintPass for UnitCmp {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if in_macro(cx, expr.span) {
if in_macro(expr.span) {
return;
}
if let ExprBinary(ref cmp, ref left, _) = expr.node {
@ -694,7 +694,7 @@ impl<'a, 'tcx> TypeComplexityPass {
}
fn check_type(&self, cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty) {
if in_macro(cx, ty.span) {
if in_macro(ty.span) {
return;
}
let score = {
@ -797,7 +797,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
if let ExprCast(ref e, _) = expr.node {
if let ExprLit(ref l) = e.node {
if let LitKind::Char(_) = l.node {
if ty::TyUint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !in_macro(cx, expr.span) {
if ty::TyUint(UintTy::U8) == cx.tables.expr_ty(expr).sty && !in_macro(expr.span) {
let msg = "casting character literal to u8. `char`s \
are 4 bytes wide in rust, so casting to u8 \
truncates them";
@ -971,7 +971,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
if let ExprBinary(ref cmp, ref lhs, ref rhs) = expr.node {
if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) {
if !in_macro(cx, expr.span) {
if !in_macro(expr.span) {
let msg = "this comparison involving the minimum or maximum element for this \
type contains a case that is always true or always false";

View File

@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
span: Span,
fn_id: ast::NodeId
) {
if in_macro(cx, span) {
if in_macro(span) {
return;
}

View File

@ -156,7 +156,7 @@ pub fn vec_macro<'e>(cx: &LateContext, expr: &'e hir::Expr) -> Option<VecArgs<'e
if_let_chain!{[
let hir::ExprCall(ref fun, ref args) = expr.node,
let hir::ExprPath(ref path) = fun.node,
is_expn_of(cx, fun.span, "vec").is_some(),
is_expn_of(fun.span, "vec").is_some(),
], {
let fun_def = resolve_node(cx, path, fun.id);
return if match_def_path(cx.tcx, fun_def.def_id(), &paths::VEC_FROM_ELEM) && args.len() == 2 {

View File

@ -111,7 +111,7 @@ pub fn in_constant(cx: &LateContext, id: NodeId) -> bool {
}
/// Returns true if this `expn_info` was expanded by any macro.
pub fn in_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool {
pub fn in_macro(span: Span) -> bool {
span.ctxt.outer().expn_info().map(|info| {
match info.callee.format {// don't treat range expressions desugared to structs as "in_macro"
ExpnFormat::CompilerDesugaring(name) => name != "...",
@ -685,7 +685,7 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
/// Return the pre-expansion span if is this comes from an expansion of the macro `name`.
/// See also `is_direct_expn_of`.
pub fn is_expn_of(cx: &LateContext, mut span: Span, name: &str) -> Option<Span> {
pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
loop {
let span_name_span = span.ctxt.outer()
.expn_info().map(|ei| (ei.callee.name(), ei.call_site));
@ -705,7 +705,7 @@ pub fn is_expn_of(cx: &LateContext, mut span: Span, name: &str) -> Option<Span>
/// ```
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only `bar!` by
/// `is_direct_expn_of`.
pub fn is_direct_expn_of(cx: &LateContext, span: Span, name: &str) -> Option<Span> {
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
let span_name_span = span.ctxt.outer()
.expn_info().map(|ei| (ei.callee.name(), ei.call_site));