|
1 | 1 | use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg};
|
2 | 2 | use if_chain::if_chain;
|
3 |
| -use rustc_ast::ast::{Expr, ExprKind, UnOp, Mutability}; |
| 3 | +use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp}; |
4 | 4 | use rustc_errors::Applicability;
|
5 | 5 | use rustc_lint::{EarlyContext, EarlyLintPass};
|
6 | 6 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
@@ -53,22 +53,20 @@ impl EarlyLintPass for DerefAddrOf {
|
53 | 53 | // Remove leading whitespace from the given span
|
54 | 54 | // e.g: ` $visitor` turns into `$visitor`
|
55 | 55 | let trim_leading_whitespaces = |span| {
|
56 |
| - if let Some(start_no_whitespace) = snippet_opt(cx, span).and_then(|snip| { |
| 56 | + snippet_opt(cx, span).and_then(|snip| { |
| 57 | + #[allow(clippy::cast_possible_truncation)] |
57 | 58 | snip.find(|c: char| !c.is_whitespace()).map(|pos| {
|
58 | 59 | span.lo() + BytePos(pos as u32)
|
59 | 60 | })
|
60 |
| - }) { |
61 |
| - e.span.with_lo(start_no_whitespace) |
62 |
| - } else { |
63 |
| - span |
64 |
| - } |
| 61 | + }).map_or(span, |start_no_whitespace| e.span.with_lo(start_no_whitespace)) |
65 | 62 | };
|
66 | 63 |
|
67 | 64 | let rpos = if *mutability == Mutability::Mut {
|
68 | 65 | macro_source.rfind("mut").expect("already checked this is a mutable reference") + "mut".len()
|
69 | 66 | } else {
|
70 |
| - macro_source.rfind("&").expect("already checked this is a reference") + "&".len() |
| 67 | + macro_source.rfind('&').expect("already checked this is a reference") + "&".len() |
71 | 68 | };
|
| 69 | + #[allow(clippy::cast_possible_truncation)] |
72 | 70 | let span_after_ref = e.span.with_lo(BytePos(e.span.lo().0 + rpos as u32));
|
73 | 71 | let span = trim_leading_whitespaces(span_after_ref);
|
74 | 72 | snippet_with_applicability(cx, span, "_", &mut applicability).to_string()
|
|
0 commit comments