-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::syntax::ast;
-use crate::syntax::ptr::P;
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
+use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use syntax::ast;
+use syntax::ptr::P;
-/// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-`
-/// operators.
-///
-/// **Why is this bad?** This is either a typo of `*=`, `!=` or `-=` or
-/// confusing.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust,ignore
-/// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
-/// ```
declare_clippy_lint! {
+ /// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-`
+ /// operators.
+ ///
+ /// **Why is this bad?** This is either a typo of `*=`, `!=` or `-=` or
+ /// confusing.
+ ///
+ /// **Known problems:** None.
+ ///
+ /// **Example:**
+ /// ```rust,ignore
+ /// a =- 42; // confusing, should it be `a -= 42` or `a = -42`?
+ /// ```
pub SUSPICIOUS_ASSIGNMENT_FORMATTING,
style,
"suspicious formatting of `*=`, `-=` or `!=`"
}
-/// **What it does:** Checks for formatting of `else`. It lints if the `else`
-/// is followed immediately by a newline or the `else` seems to be missing.
-///
-/// **Why is this bad?** This is probably some refactoring remnant, even if the
-/// code is correct, it might look confusing.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust,ignore
-/// if foo {
-/// } { // looks like an `else` is missing here
-/// }
-///
-/// if foo {
-/// } if bar { // looks like an `else` is missing here
-/// }
-///
-/// if foo {
-/// } else
-///
-/// { // this is the `else` block of the previous `if`, but should it be?
-/// }
-///
-/// if foo {
-/// } else
-///
-/// if bar { // this is the `else` block of the previous `if`, but should it be?
-/// }
-/// ```
declare_clippy_lint! {
+ /// **What it does:** Checks for formatting of `else`. It lints if the `else`
+ /// is followed immediately by a newline or the `else` seems to be missing.
+ ///
+ /// **Why is this bad?** This is probably some refactoring remnant, even if the
+ /// code is correct, it might look confusing.
+ ///
+ /// **Known problems:** None.
+ ///
+ /// **Example:**
+ /// ```rust,ignore
+ /// if foo {
+ /// } { // looks like an `else` is missing here
+ /// }
+ ///
+ /// if foo {
+ /// } if bar { // looks like an `else` is missing here
+ /// }
+ ///
+ /// if foo {
+ /// } else
+ ///
+ /// { // this is the `else` block of the previous `if`, but should it be?
+ /// }
+ ///
+ /// if foo {
+ /// } else
+ ///
+ /// if bar { // this is the `else` block of the previous `if`, but should it be?
+ /// }
+ /// ```
pub SUSPICIOUS_ELSE_FORMATTING,
style,
"suspicious formatting of `else`"
}
-/// **What it does:** Checks for possible missing comma in an array. It lints if
-/// an array element is a binary operator expression and it lies on two lines.
-///
-/// **Why is this bad?** This could lead to unexpected results.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust,ignore
-/// let a = &[
-/// -1, -2, -3 // <= no comma here
-/// -4, -5, -6
-/// ];
-/// ```
declare_clippy_lint! {
+ /// **What it does:** Checks for possible missing comma in an array. It lints if
+ /// an array element is a binary operator expression and it lies on two lines.
+ ///
+ /// **Why is this bad?** This could lead to unexpected results.
+ ///
+ /// **Known problems:** None.
+ ///
+ /// **Example:**
+ /// ```rust,ignore
+ /// let a = &[
+ /// -1, -2, -3 // <= no comma here
+ /// -4, -5, -6
+ /// ];
+ /// ```
pub POSSIBLE_MISSING_COMMA,
correctness,
"possible missing comma in array"
POSSIBLE_MISSING_COMMA
)
}
+
+ fn name(&self) -> &'static str {
+ "Formatting"
+ }
}
impl EarlyLintPass for Formatting {
if (is_block(else_) || unsugar_if(else_).is_some())
&& !differing_macro_contexts(then.span, else_.span)
&& !in_macro(then.span)
+ && !in_external_macro(cx.sess, expr.span)
{
// workaround for rust-lang/rust#43081
if expr.span.lo().0 == 0 && expr.span.hi().0 == 0 {