1 use rustc::declare_lint_pass;
2 use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
3 use rustc_session::declare_tool_lint;
6 use crate::utils::span_help_and_lint;
9 /// **What it does:** Checks for usage of `as` conversions.
11 /// **Why is this bad?** `as` conversions will perform many kinds of
12 /// conversions, including silently lossy conversions and dangerous coercions.
13 /// There are cases when it makes sense to use `as`, so the lint is
16 /// **Known problems:** None.
25 /// Usually better represents the semantics you expect:
31 /// f(a.try_into().expect("Unexpected u16 overflow in f"));
36 "using a potentially dangerous silent `as` conversion"
39 declare_lint_pass!(AsConversions => [AS_CONVERSIONS]);
41 impl EarlyLintPass for AsConversions {
42 fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
43 if in_external_macro(cx.sess(), expr.span) {
47 if let ExprKind::Cast(_, _) = expr.kind {
52 "using a potentially dangerous silent `as` conversion",
53 "consider using a safe wrapper for this conversion",