X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Futils%2Fsugg.rs;h=73758b7eeb7eb28e27651a9ec36b9cc333e622d4;hb=6b3ee8f6000ea0fe88d1d19bceac9441a43d8694;hp=a817d2a9e860751d2d0e918a6f6f8ea1d18bc86e;hpb=d9e38f57c125c5ac50397ec8a006fe49f17cd96c;p=rust.git diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index a817d2a9e86..73758b7eeb7 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -2,21 +2,17 @@ #![deny(clippy::missing_docs_in_private_items)] use crate::utils::{higher, snippet, snippet_opt, snippet_with_macro_callsite}; -use matches::matches; -use rustc::hir; -use rustc::lint::{EarlyContext, LateContext, LintContext}; +use rustc_ast::util::parser::AssocOp; +use rustc_ast::{ast, token}; +use rustc_ast_pretty::pprust::token_kind_to_string; use rustc_errors::Applicability; +use rustc_hir as hir; +use rustc_lint::{EarlyContext, LateContext, LintContext}; +use rustc_span::source_map::{CharPos, Span}; use rustc_span::{BytePos, Pos}; use std::borrow::Cow; use std::convert::TryInto; use std::fmt::Display; -use syntax::ast; -use syntax::print::pprust::token_kind_to_string; -use syntax::source_map::{CharPos, Span}; -use syntax::token; -use syntax::util::parser::AssocOp; - -pub use crate::literal_representation::format_numeric_literal; /// A helper type to build suggestion correctly handling parenthesis. pub enum Sugg<'a> { @@ -113,6 +109,7 @@ fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, snippet: Cow | hir::ExprKind::Field(..) | hir::ExprKind::Index(..) | hir::ExprKind::InlineAsm(..) + | hir::ExprKind::LlvmInlineAsm(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Loop(..) | hir::ExprKind::MethodCall(..) @@ -133,7 +130,7 @@ fn hir_from_snippet(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, snippet: Cow /// Prepare a suggestion from an expression. pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self { - use syntax::ast::RangeLimits; + use rustc_ast::ast::RangeLimits; let snippet = snippet(cx, expr.span, default); @@ -155,9 +152,10 @@ pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self { | ast::ExprKind::ForLoop(..) | ast::ExprKind::Index(..) | ast::ExprKind::InlineAsm(..) + | ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::Lit(..) | ast::ExprKind::Loop(..) - | ast::ExprKind::Mac(..) + | ast::ExprKind::MacCall(..) | ast::ExprKind::MethodCall(..) | ast::ExprKind::Paren(..) | ast::ExprKind::Path(..) @@ -427,7 +425,10 @@ enum Associativity { /// associative. #[must_use] fn associativity(op: &AssocOp) -> Associativity { - use syntax::util::parser::AssocOp::*; + use rustc_ast::util::parser::AssocOp::{ + Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater, + GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract, + }; match *op { Assign | AssignOp(_) => Associativity::Right, @@ -440,7 +441,7 @@ fn associativity(op: &AssocOp) -> Associativity { /// Converts a `hir::BinOp` to the corresponding assigning binary operator. fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { - use syntax::token::BinOpToken::*; + use rustc_ast::token::BinOpToken::{And, Caret, Minus, Or, Percent, Plus, Shl, Shr, Slash, Star}; AssocOp::AssignOp(match op.node { hir::BinOpKind::Add => Plus, @@ -467,8 +468,10 @@ fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { /// Converts an `ast::BinOp` to the corresponding assigning binary operator. fn astbinop2assignop(op: ast::BinOp) -> AssocOp { - use syntax::ast::BinOpKind::*; - use syntax::token::BinOpToken; + use rustc_ast::ast::BinOpKind::{ + Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub, + }; + use rustc_ast::token::BinOpToken; AssocOp::AssignOp(match op.node { Add => BinOpToken::Plus, @@ -514,7 +517,7 @@ pub trait DiagnosticBuilderExt<'a, T: LintContext> { /// # Example /// /// ```rust,ignore - /// db.suggest_item_with_attr(cx, item, "#[derive(Default)]"); + /// diag.suggest_item_with_attr(cx, item, "#[derive(Default)]"); /// ``` fn suggest_item_with_attr( &mut self, @@ -527,12 +530,12 @@ fn suggest_item_with_attr( /// Suggest to add an item before another. /// - /// The item should not be indented (expect for inner indentation). + /// The item should not be indented (except for inner indentation). /// /// # Example /// /// ```rust,ignore - /// db.suggest_prepend_item(cx, item, + /// diag.suggest_prepend_item(cx, item, /// "fn foo() { /// bar(); /// }"); @@ -548,7 +551,7 @@ fn suggest_item_with_attr( /// # Example /// /// ```rust,ignore - /// db.suggest_remove_item(cx, item, "remove this") + /// diag.suggest_remove_item(cx, item, "remove this") /// ``` fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability); }