From c1a73d2f4a8ef0003b93c4307930438be4aae9a5 Mon Sep 17 00:00:00 2001
From: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
Date: Fri, 9 Mar 2018 17:11:06 +0300
Subject: [PATCH] tidy: Add a check for stray `.stderr` and `.stdout` files in
 UI test directories

---
 .../ex3-both-anon-regions-4.stderr            | 19 ------
 .../propagate-approximated-to-empty.stderr    | 45 --------------
 src/test/ui/resolve-error.stderr              | 62 -------------------
 src/test/ui/span/loan-extend.stderr           | 14 -----
 src/tools/tidy/src/lib.rs                     |  1 +
 src/tools/tidy/src/main.rs                    |  1 +
 src/tools/tidy/src/ui_tests.rs                | 26 ++++++++
 7 files changed, 28 insertions(+), 140 deletions(-)
 delete mode 100644 src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr
 delete mode 100644 src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.stderr
 delete mode 100644 src/test/ui/resolve-error.stderr
 delete mode 100644 src/test/ui/span/loan-extend.stderr
 create mode 100644 src/tools/tidy/src/ui_tests.rs

diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr
deleted file mode 100644
index 19339800a7a98..0000000000000
--- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-4.stderr
+++ /dev/null
@@ -1,19 +0,0 @@
-error[E0623]: lifetime mismatch
-  --> $DIR/ex3-both-anon-regions-4.rs:12:13
-   |
-11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
-   |                     ---                 --- these references are declared with different lifetimes...
-12 |     z.push((x,y));
-   |             ^ ...but data flows into `z` here
-
-error[E0623]: lifetime mismatch
-  --> $DIR/ex3-both-anon-regions-4.rs:12:15
-   |
-11 | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
-   |                         ---                  --- these references are declared with different lifetimes...
-12 |     z.push((x,y));
-   |               ^ ...but data flows into `z` here
-
-error: aborting due to 2 previous errors
-
-If you want more information on this error, try using "rustc --explain E0623"
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.stderr
deleted file mode 100644
index 502b344c89e44..0000000000000
--- a/src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.stderr
+++ /dev/null
@@ -1,45 +0,0 @@
-warning: not reporting region error due to -Znll
-  --> $DIR/propagate-approximated-to-empty.rs:41:9
-   |
-41 |         demand_y(x, y, x.get())
-   |         ^^^^^^^^^^^^^^^^^^^^^^^
-
-error: free region `'_#6r` does not outlive free region `'_#4r`
-  --> $DIR/propagate-approximated-to-empty.rs:41:18
-   |
-41 |         demand_y(x, y, x.get())
-   |                  ^
-
-note: No external requirements
-  --> $DIR/propagate-approximated-to-empty.rs:39:47
-   |
-39 |       establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-   |  _______________________________________________^
-40 | |         // Only works if 'x: 'y:
-41 | |         demand_y(x, y, x.get())
-42 | |         //~^ WARN not reporting region error due to -Znll
-43 | |         //~| ERROR free region `'_#6r` does not outlive free region `'_#4r`
-44 | |     });
-   | |_____^
-   |
-   = note: defining type: DefId(0/1:18 ~ propagate_approximated_to_empty[317d]::supply[0]::{{closure}}[0]) with closure substs [
-               i16,
-               for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>))
-           ]
-
-note: No external requirements
-  --> $DIR/propagate-approximated-to-empty.rs:38:1
-   |
-38 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
-39 | |     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-40 | |         // Only works if 'x: 'y:
-41 | |         demand_y(x, y, x.get())
-...  |
-44 | |     });
-45 | | }
-   | |_^
-   |
-   = note: defining type: DefId(0/0:6 ~ propagate_approximated_to_empty[317d]::supply[0]) with substs []
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/resolve-error.stderr b/src/test/ui/resolve-error.stderr
deleted file mode 100644
index 27f93939246c0..0000000000000
--- a/src/test/ui/resolve-error.stderr
+++ /dev/null
@@ -1,62 +0,0 @@
-error: cannot find derive macro `FooWithLongNan` in this scope
-  --> $DIR/resolve-error.rs:37:10
-   |
-37 | #[derive(FooWithLongNan)]
-   |          ^^^^^^^^^^^^^^ help: try: `FooWithLongName`
-
-error: cannot find attribute macro `attr_proc_macra` in this scope
-  --> $DIR/resolve-error.rs:40:3
-   |
-40 | #[attr_proc_macra]
-   |   ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
-
-error: cannot find attribute macro `FooWithLongNan` in this scope
-  --> $DIR/resolve-error.rs:43:3
-   |
-43 | #[FooWithLongNan]
-   |   ^^^^^^^^^^^^^^
-
-error: cannot find derive macro `Dlone` in this scope
-  --> $DIR/resolve-error.rs:46:10
-   |
-46 | #[derive(Dlone)]
-   |          ^^^^^ help: try: `Clone`
-
-error: cannot find derive macro `Dlona` in this scope
-  --> $DIR/resolve-error.rs:49:10
-   |
-49 | #[derive(Dlona)]
-   |          ^^^^^ help: try: `Clona`
-
-error: cannot find derive macro `attr_proc_macra` in this scope
-  --> $DIR/resolve-error.rs:52:10
-   |
-52 | #[derive(attr_proc_macra)]
-   |          ^^^^^^^^^^^^^^^
-
-error: cannot find macro `FooWithLongNama!` in this scope
-  --> $DIR/resolve-error.rs:56:5
-   |
-56 |     FooWithLongNama!();
-   |     ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam!`
-
-error: cannot find macro `attr_proc_macra!` in this scope
-  --> $DIR/resolve-error.rs:58:5
-   |
-58 |     attr_proc_macra!();
-   |     ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac!`
-
-error: cannot find macro `Dlona!` in this scope
-  --> $DIR/resolve-error.rs:60:5
-   |
-60 |     Dlona!();
-   |     ^^^^^
-
-error: cannot find macro `bang_proc_macrp!` in this scope
-  --> $DIR/resolve-error.rs:62:5
-   |
-62 |     bang_proc_macrp!();
-   |     ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro!`
-
-error: aborting due to previous error(s)
-
diff --git a/src/test/ui/span/loan-extend.stderr b/src/test/ui/span/loan-extend.stderr
deleted file mode 100644
index af498129fc440..0000000000000
--- a/src/test/ui/span/loan-extend.stderr
+++ /dev/null
@@ -1,14 +0,0 @@
-error[E0597]: `short` does not live long enough
-  --> $DIR/loan-extend.rs:21:1
-   |
-19 |     long = borrow(&mut short);
-   |                        ----- borrow occurs here
-20 |
-21 | }
-   | ^ `short` dropped here while still borrowed
-   |
-   = note: values in a scope are dropped in the opposite order they are created
-
-error: aborting due to previous error
-
-If you want more information on this error, try using "rustc --explain E0597"
diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs
index c927ff19b279b..06eb055f68e06 100644
--- a/src/tools/tidy/src/lib.rs
+++ b/src/tools/tidy/src/lib.rs
@@ -51,6 +51,7 @@ pub mod features;
 pub mod cargo;
 pub mod pal;
 pub mod deps;
+pub mod ui_tests;
 pub mod unstable_book;
 
 fn filter_dirs(path: &Path) -> bool {
diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs
index afa3ebd198319..2497419279560 100644
--- a/src/tools/tidy/src/main.rs
+++ b/src/tools/tidy/src/main.rs
@@ -45,6 +45,7 @@ fn main() {
         deps::check(&path, &mut bad);
     }
     deps::check_whitelist(&path, &cargo, &mut bad);
+    ui_tests::check(&path, &mut bad);
 
     if bad {
         eprintln!("some tidy checks failed");
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs
new file mode 100644
index 0000000000000..f7fec2e667ab9
--- /dev/null
+++ b/src/tools/tidy/src/ui_tests.rs
@@ -0,0 +1,26 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// 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.
+
+//! Tidy check to ensure that there are no stray `.stderr` files in UI test directories.
+
+use std::path::Path;
+
+pub fn check(path: &Path, bad: &mut bool) {
+    super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
+                     &mut |_| false,
+                     &mut |file_path| {
+        if let Some(ext) = file_path.extension() {
+            if (ext == "stderr" || ext == "stdout") && !file_path.with_extension("rs").exists() {
+                println!("Stray file with UI testing output: {:?}", file_path);
+                *bad = true;
+            }
+        }
+    });
+}