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