Auto merge of #3519 - phansch:brave_newer_ui_tests, r=flip1995
Integrate rustfix into Clippy test suite Once the [PR to compiletest-rs](https://github.com/laumann/compiletest-rs/pull/151) is reviewed and merged this fixes #2376. I will create a separate tracking issue for adding `run-rustfix` to all tests.
This commit is contained in:
commit
5b8b01e8dc
|
@ -156,6 +156,15 @@ Therefore you should use `tests/ui/update-all-references.sh` (after running
|
||||||
`cargo test`) and check whether the output looks as you expect with `git diff`. Commit all
|
`cargo test`) and check whether the output looks as you expect with `git diff`. Commit all
|
||||||
`*.stderr` files, too.
|
`*.stderr` files, too.
|
||||||
|
|
||||||
|
If the lint you are working on is making use of structured suggestions, the
|
||||||
|
test file should include a `// run-rustfix` comment at the top. This will
|
||||||
|
additionally run [rustfix](https://github.com/rust-lang-nursery/rustfix) for
|
||||||
|
that test. Rustfix will apply the suggestions from the lint to the code of the
|
||||||
|
test file and compare that to the contents of a `.fixed` file.
|
||||||
|
|
||||||
|
Use `tests/ui/update-all-references.sh` to automatically generate the
|
||||||
|
`.fixed` file after running `cargo test`.
|
||||||
|
|
||||||
### Running rustfmt
|
### Running rustfmt
|
||||||
|
|
||||||
[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code according
|
[Rustfmt](https://github.com/rust-lang/rustfmt) is a tool for formatting Rust code according
|
||||||
|
|
|
@ -48,7 +48,7 @@ rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"}
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
|
clippy_dev = { version = "0.0.1", path = "clippy_dev" }
|
||||||
cargo_metadata = "0.6.2"
|
cargo_metadata = "0.6.2"
|
||||||
compiletest_rs = "0.3.16"
|
compiletest_rs = "0.3.18"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
|
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl LintPass for DerefPass {
|
||||||
impl EarlyLintPass for DerefPass {
|
impl EarlyLintPass for DerefPass {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Field(ref object, ref field_name) = e.node;
|
if let ExprKind::Field(ref object, _) = e.node;
|
||||||
if let ExprKind::Paren(ref parened) = object.node;
|
if let ExprKind::Paren(ref parened) = object.node;
|
||||||
if let ExprKind::AddrOf(_, ref inner) = parened.node;
|
if let ExprKind::AddrOf(_, ref inner) = parened.node;
|
||||||
then {
|
then {
|
||||||
|
@ -109,11 +109,7 @@ impl EarlyLintPass for DerefPass {
|
||||||
object.span,
|
object.span,
|
||||||
"Creating a reference that is immediately dereferenced.",
|
"Creating a reference that is immediately dereferenced.",
|
||||||
"try this",
|
"try this",
|
||||||
format!(
|
snippet_with_applicability(cx, inner.span, "_", &mut applicability).to_string(),
|
||||||
"{}.{}",
|
|
||||||
snippet_with_applicability(cx, inner.span, "_", &mut applicability),
|
|
||||||
snippet_with_applicability(cx, field_name.span, "_", &mut applicability)
|
|
||||||
),
|
|
||||||
applicability,
|
applicability,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
|
struct Outer {
|
||||||
|
inner: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[deny(clippy::ref_in_deref)]
|
||||||
|
fn main() {
|
||||||
|
let outer = Outer { inner: 0 };
|
||||||
|
let inner = outer.inner;
|
||||||
|
}
|
|
@ -7,8 +7,10 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(tool_attributes)]
|
// run-rustfix
|
||||||
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
struct Outer {
|
struct Outer {
|
||||||
inner: u32,
|
inner: u32,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
error: Creating a reference that is immediately dereferenced.
|
error: Creating a reference that is immediately dereferenced.
|
||||||
--> $DIR/unnecessary_ref.rs:20:17
|
--> $DIR/unnecessary_ref.rs:22:17
|
||||||
|
|
|
|
||||||
LL | let inner = (&outer).inner;
|
LL | let inner = (&outer).inner;
|
||||||
| ^^^^^^^^ help: try this: `outer.inner`
|
| ^^^^^^^^ help: try this: `outer`
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/unnecessary_ref.rs:17:8
|
--> $DIR/unnecessary_ref.rs:19:8
|
||||||
|
|
|
|
||||||
LL | #[deny(clippy::ref_in_deref)]
|
LL | #[deny(clippy::ref_in_deref)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -34,6 +34,7 @@ shift
|
||||||
while [[ "$1" != "" ]]; do
|
while [[ "$1" != "" ]]; do
|
||||||
STDERR_NAME="${1/%.rs/.stderr}"
|
STDERR_NAME="${1/%.rs/.stderr}"
|
||||||
STDOUT_NAME="${1/%.rs/.stdout}"
|
STDOUT_NAME="${1/%.rs/.stdout}"
|
||||||
|
FIXED_NAME="${1/%.rs/.fixed}"
|
||||||
shift
|
shift
|
||||||
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
|
if [ -f $BUILD_DIR/$STDOUT_NAME ] && \
|
||||||
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
|
! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then
|
||||||
|
@ -45,6 +46,11 @@ while [[ "$1" != "" ]]; do
|
||||||
echo updating $MYDIR/$STDERR_NAME
|
echo updating $MYDIR/$STDERR_NAME
|
||||||
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
|
cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME
|
||||||
fi
|
fi
|
||||||
|
if [ -f $BUILD_DIR/$FIXED_NAME ] && \
|
||||||
|
! (diff $BUILD_DIR/$FIXED_NAME $MYDIR/$FIXED_NAME >& /dev/null); then
|
||||||
|
echo updating $MYDIR/$FIXED_NAME
|
||||||
|
cp $BUILD_DIR/$FIXED_NAME $MYDIR/$FIXED_NAME
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue