Skip rustfmt as it is wanted for this test

This commit is contained in:
ThibsG 2020-11-02 18:03:16 +01:00
parent ce98468158
commit f83762b79c
5 changed files with 14 additions and 21 deletions

View File

@ -1,11 +1,10 @@
use crate::utils::{in_macro, snippet_opt, snippet_with_applicability, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_ast::ast::{Expr, ExprKind, UnOp, Mutability};
use rustc_ast::ast::{Expr, ExprKind, Mutability, UnOp};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::BytePos;
// use rustc_span::source_map::{BytePos, Span};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
@ -53,31 +52,29 @@ impl EarlyLintPass for DerefAddrOf {
// Remove leading whitespace from the given span
// e.g: ` $visitor` turns into `$visitor`
let trim_leading_whitespaces = |span| {
if let Some(start_no_whitespace) = snippet_opt(cx, span).and_then(|snip| {
snippet_opt(cx, span).and_then(|snip| {
#[allow(clippy::cast_possible_truncation)]
snip.find(|c: char| !c.is_whitespace()).map(|pos| {
span.lo() + BytePos(pos as u32)
})
}) {
e.span.with_lo(start_no_whitespace)
} else {
span
}
}).map_or(span, |start_no_whitespace| e.span.with_lo(start_no_whitespace))
};
let rpos = if *mutability == Mutability::Mut {
macro_source.rfind("mut").expect("already checked this is a mutable reference") + "mut".len()
} else {
macro_source.rfind("&").expect("already checked this is a reference") + "&".len()
macro_source.rfind('&').expect("already checked this is a reference") + "&".len()
};
#[allow(clippy::cast_possible_truncation)]
let span_after_ref = e.span.with_lo(BytePos(e.span.lo().0 + rpos as u32));
let span = trim_leading_whitespaces(span_after_ref);
snippet_with_applicability(cx, span, "_", &mut applicability).to_string()
snippet_with_applicability(cx, span, "_", &mut applicability)
} else {
snippet_with_applicability(cx, e.span, "_", &mut applicability).to_string()
snippet_with_applicability(cx, e.span, "_", &mut applicability)
}
} else {
snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability).to_string()
};
snippet_with_applicability(cx, addrof_target.span, "_", &mut applicability)
}.to_string();
span_lint_and_sugg(
cx,
DEREF_ADDROF,

View File

@ -92,13 +92,9 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
let expr_err_ty = cx.typeck_results().expr_ty(err_arg);
// println!("\n\n{:?}", in_macro(expr.span));
// println!("{:#?}", snippet(cx, err_arg.span, "_"));
let origin_snippet = if err_arg.span.from_expansion() && !in_macro(expr.span) {
// println!("from expansion");
snippet_with_macro_callsite(cx, err_arg.span, "_")
} else {
// println!("just a snippet");
snippet(cx, err_arg.span, "_")
};
let suggestion = if err_ty == expr_err_ty {
@ -106,8 +102,6 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
} else {
format!("return {}{}.into(){}", prefix, origin_snippet, suffix)
};
// println!("origin_snippet: {:#?}", origin_snippet);
// println!("suggestion: {:#?}", suggestion);
span_lint_and_sugg(
cx,

View File

@ -38,6 +38,7 @@ fn main() {
let b = *aref;
}
#[rustfmt::skip]
macro_rules! m {
($visitor: expr) => {
$visitor

View File

@ -38,6 +38,7 @@ fn main() {
let b = **&aref;
}
#[rustfmt::skip]
macro_rules! m {
($visitor: expr) => {
*& $visitor

View File

@ -49,7 +49,7 @@ LL | let b = **&aref;
| ^^^^^^ help: try this: `aref`
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:43:9
--> $DIR/deref_addrof.rs:44:9
|
LL | *& $visitor
| ^^^^^^^^^^^ help: try this: `$visitor`
@ -60,7 +60,7 @@ LL | m!(self)
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:50:9
--> $DIR/deref_addrof.rs:51:9
|
LL | *& mut $visitor
| ^^^^^^^^^^^^^^^ help: try this: `$visitor`