use matches::matches;
-use rustc::hir;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass, in_external_macro, Lint, LintContext};
-use rustc::{declare_tool_lint, lint_array};
+use crate::rustc::hir;
+use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass, in_external_macro, Lint, LintContext};
+use crate::rustc::{declare_tool_lint, lint_array};
use if_chain::if_chain;
-use rustc::ty::{self, Ty};
-use rustc::hir::def::Def;
+use crate::rustc::ty::{self, Ty};
+use crate::rustc::hir::def::Def;
use std::borrow::Cow;
use std::fmt;
use std::iter;
-use syntax::ast;
-use syntax::source_map::{Span, BytePos};
+use crate::syntax::ast;
+use crate::syntax::source_map::{Span, BytePos};
use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_macro, is_copy, is_expn_of, is_self,
is_self_ty, iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
match_type, method_chain_args, match_var, return_ty, remove_blocks, same_tys, single_segment_path, snippet,
use crate::utils::paths;
use crate::utils::sugg;
use crate::consts::{constant, Constant};
+use crate::rustc_errors::Applicability;
#[derive(Clone)]
pub struct Pass;
///
/// **Example:**
/// ```rust
-/// foo.expect(&format("Err {}: {}", err_code, err_msg))
+/// foo.expect(&format!("Err {}: {}", err_code, err_msg))
/// ```
/// or
/// ```rust
-/// foo.expect(format("Err {}: {}", err_code, err_msg).as_str())
+/// foo.expect(format!("Err {}: {}", err_code, err_msg).as_str())
/// ```
/// this can instead be written:
/// ```rust
/// foo.unwrap_or_else(|_| panic!("Err {}: {}", err_code, err_msg))
/// ```
-/// or
-/// ```rust
-/// foo.unwrap_or_else(|_| panic!(format("Err {}: {}", err_code, err_msg).as_str()))
-/// ```
declare_clippy_lint! {
pub EXPECT_FUN_CALL,
perf,
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
- #[allow(cyclomatic_complexity)]
+ #[allow(clippy::cyclomatic_complexity)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if in_macro(expr.span) {
return;
}
/// Check for `*or(foo())`.
- #[allow(too_many_arguments)]
+ #[allow(clippy::too_many_arguments)]
fn check_general_case(
cx: &LateContext<'_, '_>,
name: &str,
let refs: String = iter::repeat('&').take(n + 1).collect();
let derefs: String = iter::repeat('*').take(n).collect();
let explicit = format!("{}{}::clone({})", refs, ty, snip);
- db.span_suggestion(expr.span, "try dereferencing it", format!("{}({}{}).clone()", refs, derefs, snip.deref()));
- db.span_suggestion(expr.span, "or try being explicit about what type to clone", explicit);
+ db.span_suggestion_with_applicability(
+ expr.span,
+ "try dereferencing it",
+ format!("{}({}{}).clone()", refs, derefs, snip.deref()),
+ Applicability::Unspecified,
+ );
+ db.span_suggestion_with_applicability(
+ expr.span,
+ "or try being explicit about what type to clone",
+ explicit,
+ Applicability::Unspecified,
+ );
},
);
return; // don't report clone_on_copy
}
span_lint_and_then(cx, CLONE_ON_COPY, expr.span, "using `clone` on a `Copy` type", |db| {
if let Some((text, snip)) = snip {
- db.span_suggestion(expr.span, text, snip);
+ db.span_suggestion_with_applicability(
+ expr.span,
+ text,
+ snip,
+ Applicability::Unspecified,
+ );
}
});
}
let map_or_func_snippet = snippet(cx, map_or_args[2].span, "..");
let hint = format!("{0}.and_then({1})", map_or_self_snippet, map_or_func_snippet);
span_lint_and_then(cx, OPTION_MAP_OR_NONE, expr.span, msg, |db| {
- db.span_suggestion(expr.span, "try using and_then instead", hint);
+ db.span_suggestion_with_applicability(
+ expr.span,
+ "try using and_then instead",
+ hint,
+ Applicability::Unspecified,
+ );
});
}
}