Skip to content

Commit f83762b

Browse files
committed
Skip rustfmt as it is wanted for this test
1 parent ce98468 commit f83762b

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

clippy_lints/src/reference.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg};
22
use if_chain::if_chain;
3-
use rustc_ast::ast::{Expr, ExprKind, UnOp, Mutability};
3+
use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
44
use rustc_errors::Applicability;
55
use rustc_lint::{EarlyContext, EarlyLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::BytePos;
8-
// use rustc_span::source_map::{BytePos, Span};
98

109
declare_clippy_lint! {
1110
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
@@ -53,31 +52,29 @@ impl EarlyLintPass for DerefAddrOf {
5352
// Remove leading whitespace from the given span
5453
// e.g: ` $visitor` turns into `$visitor`
5554
let trim_leading_whitespaces = |span| {
56-
if let Some(start_no_whitespace) = snippet_opt(cx, span).and_then(|snip| {
55+
snippet_opt(cx, span).and_then(|snip| {
56+
#[allow(clippy::cast_possible_truncation)]
5757
snip.find(|c: char| !c.is_whitespace()).map(|pos| {
5858
span.lo() + BytePos(pos as u32)
5959
})
60-
}) {
61-
e.span.with_lo(start_no_whitespace)
62-
} else {
63-
span
64-
}
60+
}).map_or(span, |start_no_whitespace| e.span.with_lo(start_no_whitespace))
6561
};
6662

6763
let rpos = if *mutability == Mutability::Mut {
6864
macro_source.rfind("mut").expect("already checked this is a mutable reference") + "mut".len()
6965
} else {
70-
macro_source.rfind("&").expect("already checked this is a reference") + "&".len()
66+
macro_source.rfind('&').expect("already checked this is a reference") + "&".len()
7167
};
68+
#[allow(clippy::cast_possible_truncation)]
7269
let span_after_ref = e.span.with_lo(BytePos(e.span.lo().0 + rpos as u32));
7370
let span = trim_leading_whitespaces(span_after_ref);
74-
snippet_with_applicability(cx, span, "_", &mut applicability).to_string()
71+
snippet_with_applicability(cx, span, "_", &mut applicability)
7572
} else {
76-
snippet_with_applicability(cx, e.span, "_", &mut applicability).to_string()
73+
snippet_with_applicability(cx, e.span, "_", &mut applicability)
7774
}
7875
} else {
79-
snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability).to_string()
80-
};
76+
snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability)
77+
}.to_string();
8178
span_lint_and_sugg(
8279
cx,
8380
DEREF_ADDROF,

clippy_lints/src/try_err.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,16 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
9292

9393
let expr_err_ty = cx.typeck_results().expr_ty(err_arg);
9494

95-
// println!("\n\n{:?}", in_macro(expr.span));
96-
// println!("{:#?}", snippet(cx, err_arg.span, "_"));
9795
let origin_snippet = if err_arg.span.from_expansion() && !in_macro(expr.span) {
98-
// println!("from expansion");
9996
snippet_with_macro_callsite(cx, err_arg.span, "_")
10097
} else {
101-
// println!("just a snippet");
10298
snippet(cx, err_arg.span, "_")
10399
};
104100
let suggestion = if err_ty == expr_err_ty {
105101
format!("return {}{}{}", prefix, origin_snippet, suffix)
106102
} else {
107103
format!("return {}{}.into(){}", prefix, origin_snippet, suffix)
108104
};
109-
// println!("origin_snippet: {:#?}", origin_snippet);
110-
// println!("suggestion: {:#?}", suggestion);
111105

112106
span_lint_and_sugg(
113107
cx,

tests/ui/deref_addrof.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn main() {
3838
let b = *aref;
3939
}
4040

41+
#[rustfmt::skip]
4142
macro_rules! m {
4243
($visitor: expr) => {
4344
$visitor

tests/ui/deref_addrof.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn main() {
3838
let b = **&aref;
3939
}
4040

41+
#[rustfmt::skip]
4142
macro_rules! m {
4243
($visitor: expr) => {
4344
*& $visitor

tests/ui/deref_addrof.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ LL | let b = **&aref;
4949
| ^^^^^^ help: try this: `aref`
5050

5151
error: immediately dereferencing a reference
52-
--> $DIR/deref_addrof.rs:43:9
52+
--> $DIR/deref_addrof.rs:44:9
5353
|
5454
LL | *& $visitor
5555
| ^^^^^^^^^^^ help: try this: `$visitor`
@@ -60,7 +60,7 @@ LL | m!(self)
6060
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6161

6262
error: immediately dereferencing a reference
63-
--> $DIR/deref_addrof.rs:50:9
63+
--> $DIR/deref_addrof.rs:51:9
6464
|
6565
LL | *& mut $visitor
6666
| ^^^^^^^^^^^^^^^ help: try this: `$visitor`

0 commit comments

Comments
 (0)