X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Futils%2Fsugg.rs;h=d1e4db6264f74ad3dc2e5e6ddbdf6bdee4d2257f;hb=c67d2b121adb614eb21b56020d730081cdff0abb;hp=3fa08e0a11cbc5e678cd304a919f109e0a74b428;hpb=1cf5d7f04cc73f99ee19be6b93304666f5845665;p=rust.git diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 3fa08e0a11c..d1e4db6264f 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -1,7 +1,7 @@ //! Contains utility functions to generate suggestions. #![deny(clippy::missing_docs_in_private_items)] -use crate::utils::{higher, in_macro, snippet, snippet_opt, snippet_with_macro_callsite}; +use crate::utils::{higher, in_macro_or_desugar, snippet, snippet_opt, snippet_with_macro_callsite}; use matches::matches; use rustc::hir; use rustc::lint::{EarlyContext, LateContext, LintContext}; @@ -69,7 +69,7 @@ pub fn hir_with_applicability( default: &'a str, applicability: &mut Applicability, ) -> Self { - if *applicability != Applicability::Unspecified && in_macro(expr.span) { + if *applicability != Applicability::Unspecified && in_macro_or_desugar(expr.span) { *applicability = Applicability::MaybeIncorrect; } Self::hir_opt(cx, expr).unwrap_or_else(|| { @@ -94,7 +94,6 @@ fn hir_from_snippet(expr: &hir::Expr, snippet: Cow<'a, str>) -> Self { hir::ExprKind::AddrOf(..) | hir::ExprKind::Box(..) | hir::ExprKind::Closure(.., _) - | hir::ExprKind::If(..) | hir::ExprKind::Unary(..) | hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet), hir::ExprKind::Continue(..) @@ -137,7 +136,6 @@ pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self { | ast::ExprKind::Closure(..) | ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) - | ast::ExprKind::ObsoleteInPlace(..) | ast::ExprKind::Unary(..) | ast::ExprKind::Match(..) => Sugg::MaybeParen(snippet), ast::ExprKind::Async(..) @@ -165,6 +163,7 @@ pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self { | ast::ExprKind::Array(..) | ast::ExprKind::While(..) | ast::ExprKind::WhileLet(..) + | ast::ExprKind::Await(..) | ast::ExprKind::Err => Sugg::NonParen(snippet), ast::ExprKind::Range(.., RangeLimits::HalfOpen) => Sugg::BinOp(AssocOp::DotDot, snippet), ast::ExprKind::Range(.., RangeLimits::Closed) => Sugg::BinOp(AssocOp::DotDotEq, snippet), @@ -385,7 +384,6 @@ fn needs_paren(op: &AssocOp, other: &AssocOp, dir: Associativity) -> bool { rhs ), AssocOp::Assign => format!("{} = {}", lhs, rhs), - AssocOp::ObsoleteInPlace => format!("in ({}) {}", lhs, rhs), AssocOp::AssignOp(op) => format!("{} {}= {}", lhs, token_to_string(&token::BinOp(op)), rhs), AssocOp::As => format!("{} as {}", lhs, rhs), AssocOp::DotDot => format!("{}..{}", lhs, rhs), @@ -425,7 +423,7 @@ fn associativity(op: &AssocOp) -> Associativity { use syntax::util::parser::AssocOp::*; match *op { - ObsoleteInPlace | Assign | AssignOp(_) => Associativity::Right, + Assign | AssignOp(_) => Associativity::Right, Add | BitAnd | BitOr | BitXor | LAnd | LOr | Multiply | As | Colon => Associativity::Both, Divide | Equal | Greater | GreaterEqual | Less | LessEqual | Modulus | NotEqual | ShiftLeft | ShiftRight | Subtract => Associativity::Left,