From fd6aa149bca7b896650c5f15a9c0000fc4f0056d Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Fri, 20 Apr 2018 00:04:08 +0200 Subject: [PATCH 1/7] First step towards rustfix compiletest mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the first small step towards testing auto-fixable compiler suggestions using compiletest. Currently, it only checks if next to a UI test there also happens to a `*.rs.fixed` file, and then uses rustfix (added as external crate) on the original file, and asserts that it produces the fixed version. To show that this works, I've included one such test. I picked this test case at random (and because it was simple) -- It is not relevant to the 2018 edition. Indeed, in the near future, we want to be able to restrict rustfix to edition-lints, so this test cast might go away soon. In case you still think this is somewhat feature-complete, here's a quick list of things currently missing that I want to add before telling people they can use this: - [ ] Make this an actual compiletest mode, with `test [fix] …` output and everything - [ ] Assert that fixed files still compile - [ ] Assert that fixed files produce no (or a known set of) diagnostics output - [ ] Update `update-references.sh` to support rustfix - [ ] Use a published version of rustfix (i.e.: publish a new version rustfix that exposes a useful API for this) --- .../closure-immutable-outer-variable.rs.fixed | 20 ++++++ src/tools/compiletest/Cargo.toml | 1 + src/tools/compiletest/src/autofix.rs | 70 +++++++++++++++++++ src/tools/compiletest/src/common.rs | 3 +- src/tools/compiletest/src/main.rs | 2 + src/tools/compiletest/src/runtest.rs | 16 ++++- 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed create mode 100644 src/tools/compiletest/src/autofix.rs diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed new file mode 100644 index 0000000000000..80a5a45a30580 --- /dev/null +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.rs.fixed @@ -0,0 +1,20 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let mut y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index 7d02f0b746d95..1710a44380f95 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -13,6 +13,7 @@ regex = "0.2" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" +rustfix = { git = "https://github.com/rust-lang-nursery/rustfix" } [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/tools/compiletest/src/autofix.rs b/src/tools/compiletest/src/autofix.rs new file mode 100644 index 0000000000000..29ea5cdff8f9d --- /dev/null +++ b/src/tools/compiletest/src/autofix.rs @@ -0,0 +1,70 @@ +use rustfix::{get_suggestions_from_json, Replacement}; +use std::collections::HashSet; +use std::error::Error; + +pub fn run_rustfix(code: &str, json: &str) -> String { + let suggestions = get_suggestions_from_json(&json, &HashSet::new()) + .expect("could not load suggestions"); + + let mut fixed = code.to_string(); + + for sug in suggestions.into_iter().rev() { + for sol in sug.solutions { + for r in sol.replacements { + fixed = apply_suggestion(&mut fixed, &r) + .expect("could not apply suggestion"); + } + } + } + + fixed +} + +fn apply_suggestion( + file_content: &mut String, + suggestion: &Replacement, +) -> Result> { + use std::cmp::max; + + let mut new_content = String::new(); + + // Add the lines before the section we want to replace + new_content.push_str(&file_content + .lines() + .take(max(suggestion.snippet.line_range.start.line - 1, 0) as usize) + .collect::>() + .join("\n")); + new_content.push_str("\n"); + + // Parts of line before replacement + new_content.push_str(&file_content + .lines() + .nth(suggestion.snippet.line_range.start.line - 1) + .unwrap_or("") + .chars() + .take(suggestion.snippet.line_range.start.column - 1) + .collect::()); + + // Insert new content! Finally! + new_content.push_str(&suggestion.replacement); + + // Parts of line after replacement + new_content.push_str(&file_content + .lines() + .nth(suggestion.snippet.line_range.end.line - 1) + .unwrap_or("") + .chars() + .skip(suggestion.snippet.line_range.end.column - 1) + .collect::()); + + // Add the lines after the section we want to replace + new_content.push_str("\n"); + new_content.push_str(&file_content + .lines() + .skip(suggestion.snippet.line_range.end.line as usize) + .collect::>() + .join("\n")); + new_content.push_str("\n"); + + Ok(new_content) +} diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 365b47447f23a..5159b1a692efb 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -269,6 +269,7 @@ pub fn expected_output_path(testpaths: &TestPaths, testpaths.file.with_extension(extension) } -pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT]; +pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED]; pub const UI_STDERR: &str = "stderr"; pub const UI_STDOUT: &str = "stdout"; +pub const UI_FIXED: &str = "rs.fixed"; diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 37f7af0abe8f5..3e7c6500433b1 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -26,6 +26,7 @@ extern crate regex; extern crate serde_derive; extern crate serde_json; extern crate test; +extern crate rustfix; use std::env; use std::ffi::OsString; @@ -52,6 +53,7 @@ pub mod common; pub mod errors; mod raise_fd_limit; mod read2; +mod autofix; fn main() { env_logger::init(); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 01d9f52424da8..20456a21cb5c4 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -12,7 +12,7 @@ use common::{Config, TestPaths}; use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind}; use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc}; use common::{Incremental, MirOpt, RunMake, Ui}; -use common::{expected_output_path, UI_STDERR, UI_STDOUT}; +use common::{expected_output_path, UI_STDERR, UI_STDOUT, UI_FIXED}; use common::CompareMode; use diff; use errors::{self, Error, ErrorKind}; @@ -35,6 +35,7 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str; +use autofix::run_rustfix; use extract_gdb_version; /// The name of the environment variable that holds dynamic library locations. @@ -2603,6 +2604,19 @@ impl<'test> TestCx<'test> { self.check_error_patterns(&proc_res.stderr, &proc_res); } } + + let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); + if fixture_path.exists() { + let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) + .unwrap(); + let expected_fixed = self.load_expected_output_from_path(&fixture_path).unwrap(); + let fixed_code = run_rustfix(&unfixed_code, &proc_res.stderr); + let errors = self.compare_output("rs.fixed", &fixed_code, &expected_fixed); + if errors > 0 { + panic!("rustfix produced different fixed file!"); + // TODO: Add info for update-references.sh call + } + } } fn run_mir_opt_test(&self) { From c02aedfcafafe3d2d0fbb4e9d85b2bbbbfa9abb2 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 2 May 2018 00:32:31 +0200 Subject: [PATCH 2/7] Use rustfix' suggestion fixing API Uses branch from until we publish a new release. --- src/tools/compiletest/Cargo.toml | 2 +- src/tools/compiletest/src/autofix.rs | 70 ---------------------------- src/tools/compiletest/src/main.rs | 1 - src/tools/compiletest/src/runtest.rs | 7 ++- 4 files changed, 6 insertions(+), 74 deletions(-) delete mode 100644 src/tools/compiletest/src/autofix.rs diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index 1710a44380f95..476e5927a2f2b 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -13,7 +13,7 @@ regex = "0.2" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -rustfix = { git = "https://github.com/rust-lang-nursery/rustfix" } +rustfix = { git = "https://github.com/rust-lang-nursery/rustfix", branch = "apply_suggestion" } [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/tools/compiletest/src/autofix.rs b/src/tools/compiletest/src/autofix.rs deleted file mode 100644 index 29ea5cdff8f9d..0000000000000 --- a/src/tools/compiletest/src/autofix.rs +++ /dev/null @@ -1,70 +0,0 @@ -use rustfix::{get_suggestions_from_json, Replacement}; -use std::collections::HashSet; -use std::error::Error; - -pub fn run_rustfix(code: &str, json: &str) -> String { - let suggestions = get_suggestions_from_json(&json, &HashSet::new()) - .expect("could not load suggestions"); - - let mut fixed = code.to_string(); - - for sug in suggestions.into_iter().rev() { - for sol in sug.solutions { - for r in sol.replacements { - fixed = apply_suggestion(&mut fixed, &r) - .expect("could not apply suggestion"); - } - } - } - - fixed -} - -fn apply_suggestion( - file_content: &mut String, - suggestion: &Replacement, -) -> Result> { - use std::cmp::max; - - let mut new_content = String::new(); - - // Add the lines before the section we want to replace - new_content.push_str(&file_content - .lines() - .take(max(suggestion.snippet.line_range.start.line - 1, 0) as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); - - // Parts of line before replacement - new_content.push_str(&file_content - .lines() - .nth(suggestion.snippet.line_range.start.line - 1) - .unwrap_or("") - .chars() - .take(suggestion.snippet.line_range.start.column - 1) - .collect::()); - - // Insert new content! Finally! - new_content.push_str(&suggestion.replacement); - - // Parts of line after replacement - new_content.push_str(&file_content - .lines() - .nth(suggestion.snippet.line_range.end.line - 1) - .unwrap_or("") - .chars() - .skip(suggestion.snippet.line_range.end.column - 1) - .collect::()); - - // Add the lines after the section we want to replace - new_content.push_str("\n"); - new_content.push_str(&file_content - .lines() - .skip(suggestion.snippet.line_range.end.line as usize) - .collect::>() - .join("\n")); - new_content.push_str("\n"); - - Ok(new_content) -} diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 3e7c6500433b1..a7849d53c3d75 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -53,7 +53,6 @@ pub mod common; pub mod errors; mod raise_fd_limit; mod read2; -mod autofix; fn main() { env_logger::init(); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 20456a21cb5c4..f0feb9b50f1b7 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -35,7 +35,6 @@ use std::path::{Path, PathBuf}; use std::process::{Child, Command, ExitStatus, Output, Stdio}; use std::str; -use autofix::run_rustfix; use extract_gdb_version; /// The name of the environment variable that holds dynamic library locations. @@ -2607,10 +2606,14 @@ impl<'test> TestCx<'test> { let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); if fixture_path.exists() { + use std::collections::HashSet; + use rustfix::{apply_suggestions, get_suggestions_from_json}; + let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) .unwrap(); let expected_fixed = self.load_expected_output_from_path(&fixture_path).unwrap(); - let fixed_code = run_rustfix(&unfixed_code, &proc_res.stderr); + let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); + let fixed_code = apply_suggestions(&unfixed_code, &suggestions); let errors = self.compare_output("rs.fixed", &fixed_code, &expected_fixed); if errors > 0 { panic!("rustfix produced different fixed file!"); From 9680f3b381767010c97b5d3ea0a14fdc19efde0c Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 2 May 2018 00:33:59 +0200 Subject: [PATCH 3/7] Skip NLL compiletest in rustfix mode for now --- src/tools/compiletest/src/common.rs | 4 ++-- src/tools/compiletest/src/runtest.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 5159b1a692efb..df0cf61e7c4a0 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -95,9 +95,9 @@ impl fmt::Display for Mode { } } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub enum CompareMode { - Nll + Nll, } impl CompareMode { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f0feb9b50f1b7..a7c34921842de 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2605,7 +2605,10 @@ impl<'test> TestCx<'test> { } let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); - if fixture_path.exists() { + + // TODO(killercup): Add `nll.rs.fixed` files matching + let nll = self.config.compare_mode.as_ref().map(|x| *x == CompareMode::Nll).unwrap_or(false); + if fixture_path.exists() && !nll { use std::collections::HashSet; use rustfix::{apply_suggestions, get_suggestions_from_json}; From b2645044039cb59858ec494e0ddacbe597757cdb Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 2 May 2018 00:44:39 +0200 Subject: [PATCH 4/7] tidy --- src/tools/compiletest/src/runtest.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index a7c34921842de..745952ddf9e60 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2606,8 +2606,11 @@ impl<'test> TestCx<'test> { let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); - // TODO(killercup): Add `nll.rs.fixed` files matching - let nll = self.config.compare_mode.as_ref().map(|x| *x == CompareMode::Nll).unwrap_or(false); + // FIXME(killercup): Add `nll.rs.fixed` files matching + let nll = self.config.compare_mode + .as_ref() + .map(|x| *x == CompareMode::Nll) + .unwrap_or(false); if fixture_path.exists() && !nll { use std::collections::HashSet; use rustfix::{apply_suggestions, get_suggestions_from_json}; @@ -2620,7 +2623,7 @@ impl<'test> TestCx<'test> { let errors = self.compare_output("rs.fixed", &fixed_code, &expected_fixed); if errors > 0 { panic!("rustfix produced different fixed file!"); - // TODO: Add info for update-references.sh call + // FIXME(killercup): Add info for update-references.sh call } } } From fa9e55faeb0b4fac282ed47f20780c05f4efc86d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 2 May 2018 08:43:15 -0700 Subject: [PATCH 5/7] test: Make a dedicated testsuite for rustfix This commit adds a dedicated mode to compiletest for running rustfix tests, adding a new `src/test/rustfix` directory which will execute all tests as a "rustfix" test, namely requiring that a `*.fixed` is next to the main file which is the result of the rustfix project's application of fixes. The `rustfix` crate is pulled in to actually perform the fixing, and the rustfix compiletest mode will assert a few properties about the fixing: * The expected fixed output must be the same as rustc's output suggestions applied to the original code. * The fixed code must compile successfully * The fixed code must have no further diagnostics emitted about it --- src/Cargo.lock | 15 ++++ src/bootstrap/builder.rs | 2 +- src/bootstrap/test.rs | 6 ++ .../closure-immutable-outer-variable.fixed | 20 +++++ .../closure-immutable-outer-variable.rs | 20 +++++ src/test/rustfix/empty-no-fixes.fixed | 11 +++ src/test/rustfix/empty-no-fixes.rs | 11 +++ src/test/rustfix/empty-no-fixes.rs.fixed | 12 +++ src/test/rustfix/issue-45562.fixed | 13 +++ src/test/rustfix/issue-45562.rs | 13 +++ ...n-crate-rename-suggestion-formatting.fixed | 12 +++ ...tern-crate-rename-suggestion-formatting.rs | 12 +++ ...6-consider-borrowing-cast-or-binexpr.fixed | 22 +++++ ...6756-consider-borrowing-cast-or-binexpr.rs | 22 +++++ src/test/rustfix/main-no-fixes.fixed | 11 +++ src/test/rustfix/main-no-fixes.rs | 11 +++ src/test/rustfix/main-no-fixes.rs.fixed | 11 +++ src/test/rustfix/missing-comma-in-match.fixed | 17 ++++ src/test/rustfix/missing-comma-in-match.rs | 17 ++++ src/test/rustfix/str-as-char.fixed | 13 +++ src/test/rustfix/str-as-char.rs | 13 +++ src/test/rustfix/tuple-float-index.fixed | 15 ++++ src/test/rustfix/tuple-float-index.rs | 15 ++++ src/test/rustfix/update-all-references.sh | 31 +++++++ src/test/rustfix/update-references.sh | 45 ++++++++++ src/tools/compiletest/src/common.rs | 41 ++++----- src/tools/compiletest/src/runtest.rs | 84 +++++++++++++------ 27 files changed, 471 insertions(+), 44 deletions(-) create mode 100644 src/test/rustfix/closure-immutable-outer-variable.fixed create mode 100644 src/test/rustfix/closure-immutable-outer-variable.rs create mode 100644 src/test/rustfix/empty-no-fixes.fixed create mode 100644 src/test/rustfix/empty-no-fixes.rs create mode 100644 src/test/rustfix/empty-no-fixes.rs.fixed create mode 100644 src/test/rustfix/issue-45562.fixed create mode 100644 src/test/rustfix/issue-45562.rs create mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed create mode 100644 src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs create mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed create mode 100644 src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs create mode 100644 src/test/rustfix/main-no-fixes.fixed create mode 100644 src/test/rustfix/main-no-fixes.rs create mode 100644 src/test/rustfix/main-no-fixes.rs.fixed create mode 100644 src/test/rustfix/missing-comma-in-match.fixed create mode 100644 src/test/rustfix/missing-comma-in-match.rs create mode 100644 src/test/rustfix/str-as-char.fixed create mode 100644 src/test/rustfix/str-as-char.rs create mode 100644 src/test/rustfix/tuple-float-index.fixed create mode 100644 src/test/rustfix/tuple-float-index.rs create mode 100755 src/test/rustfix/update-all-references.sh create mode 100755 src/test/rustfix/update-references.sh diff --git a/src/Cargo.lock b/src/Cargo.lock index ccdb24d737551..113369c997130 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -394,6 +394,7 @@ dependencies = [ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustfix 0.1.0 (git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion)", "serde 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2234,6 +2235,19 @@ dependencies = [ "rustdoc 0.0.0", ] +[[package]] +name = "rustfix" +version = "0.1.0" +source = "git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion#571b43a1a1777561ddd7a41b37512bf0e3452c1a" +dependencies = [ + "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", + "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustfmt-nightly" version = "0.6.1" @@ -3146,6 +3160,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-ap-syntax_pos 113.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "55793c2a775230c42661194c48d44b35d4c8439d79ad8528e56651e854c48c63" "checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" +"checksum rustfix 0.1.0 (git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion)" = "" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" "checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637" "checksum schannel 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "85fd9df495640643ad2d00443b3d78aae69802ad488debab4f1dd52fc1806ade" diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 08bb8ab481513..5920e356bca40 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -326,7 +326,7 @@ impl<'a> Builder<'a> { test::TheBook, test::UnstableBook, test::RustcBook, test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme, // Run run-make last, since these won't pass without make on Windows - test::RunMake, test::RustdocUi), + test::RunMake, test::RustdocUi, test::Rustfix), Kind::Bench => describe!(test::Crate, test::CrateLibrustc), Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook, doc::Standalone, doc::Std, doc::Test, doc::WhitelistedRustc, doc::Rustc, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index e8c40dfdb0ad2..fa32dd3163560 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -716,6 +716,12 @@ default_test!(RunFail { suite: "run-fail" }); +default_test!(Rustfix { + path: "src/test/rustfix", + mode: "rustfix", + suite: "rustfix" +}); + default_test!(RunPassValgrind { path: "src/test/run-pass-valgrind", mode: "run-pass-valgrind", diff --git a/src/test/rustfix/closure-immutable-outer-variable.fixed b/src/test/rustfix/closure-immutable-outer-variable.fixed new file mode 100644 index 0000000000000..bddc2eab16dd8 --- /dev/null +++ b/src/test/rustfix/closure-immutable-outer-variable.fixed @@ -0,0 +1,20 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let mut y = true; + foo(Box::new(move || y = false) as Box<_>); +} diff --git a/src/test/rustfix/closure-immutable-outer-variable.rs b/src/test/rustfix/closure-immutable-outer-variable.rs new file mode 100644 index 0000000000000..fe8e2bc6c8ed1 --- /dev/null +++ b/src/test/rustfix/closure-immutable-outer-variable.rs @@ -0,0 +1,20 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let y = true; + foo(Box::new(move || y = false) as Box<_>); +} diff --git a/src/test/rustfix/empty-no-fixes.fixed b/src/test/rustfix/empty-no-fixes.fixed new file mode 100644 index 0000000000000..39e19566d7652 --- /dev/null +++ b/src/test/rustfix/empty-no-fixes.fixed @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs b/src/test/rustfix/empty-no-fixes.rs new file mode 100644 index 0000000000000..39e19566d7652 --- /dev/null +++ b/src/test/rustfix/empty-no-fixes.rs @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:--crate-type lib diff --git a/src/test/rustfix/empty-no-fixes.rs.fixed b/src/test/rustfix/empty-no-fixes.rs.fixed new file mode 100644 index 0000000000000..ee58e77825343 --- /dev/null +++ b/src/test/rustfix/empty-no-fixes.rs.fixed @@ -0,0 +1,12 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:--crate-type lib +fn foo() {} diff --git a/src/test/rustfix/issue-45562.fixed b/src/test/rustfix/issue-45562.fixed new file mode 100644 index 0000000000000..d7a27a11fc07a --- /dev/null +++ b/src/test/rustfix/issue-45562.fixed @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[no_mangle] pub static RAH: usize = 5; + +fn main() {} diff --git a/src/test/rustfix/issue-45562.rs b/src/test/rustfix/issue-45562.rs new file mode 100644 index 0000000000000..39576e9c845e4 --- /dev/null +++ b/src/test/rustfix/issue-45562.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[no_mangle] pub const RAH: usize = 5; + +fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed new file mode 100644 index 0000000000000..d931f90cd0431 --- /dev/null +++ b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed @@ -0,0 +1,12 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate std as other_std; +fn main() {} diff --git a/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs new file mode 100644 index 0000000000000..7c55f9c4eb9f0 --- /dev/null +++ b/src/test/rustfix/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs @@ -0,0 +1,12 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate std; +fn main() {} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed new file mode 100644 index 0000000000000..aaa04ef40042d --- /dev/null +++ b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.fixed @@ -0,0 +1,22 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused)] + +fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { + and_yet + 1 +} + +fn main() { + let behold: isize = 2; + let with_tears: usize = 3; + light_flows_our_war_of_mocking_words(&(behold as usize)); + light_flows_our_war_of_mocking_words(&(with_tears + 4)); +} diff --git a/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs new file mode 100644 index 0000000000000..d21681747e9d3 --- /dev/null +++ b/src/test/rustfix/issue-46756-consider-borrowing-cast-or-binexpr.rs @@ -0,0 +1,22 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused)] + +fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { + and_yet + 1 +} + +fn main() { + let behold: isize = 2; + let with_tears: usize = 3; + light_flows_our_war_of_mocking_words(behold as usize); + light_flows_our_war_of_mocking_words(with_tears + 4); +} diff --git a/src/test/rustfix/main-no-fixes.fixed b/src/test/rustfix/main-no-fixes.fixed new file mode 100644 index 0000000000000..3f07b46791d22 --- /dev/null +++ b/src/test/rustfix/main-no-fixes.fixed @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs b/src/test/rustfix/main-no-fixes.rs new file mode 100644 index 0000000000000..3f07b46791d22 --- /dev/null +++ b/src/test/rustfix/main-no-fixes.rs @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {} diff --git a/src/test/rustfix/main-no-fixes.rs.fixed b/src/test/rustfix/main-no-fixes.rs.fixed new file mode 100644 index 0000000000000..3f07b46791d22 --- /dev/null +++ b/src/test/rustfix/main-no-fixes.rs.fixed @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() {} diff --git a/src/test/rustfix/missing-comma-in-match.fixed b/src/test/rustfix/missing-comma-in-match.fixed new file mode 100644 index 0000000000000..621a4127bc293 --- /dev/null +++ b/src/test/rustfix/missing-comma-in-match.fixed @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + match &Some(3) { + &None => 1, + &Some(2) => { 3 } + _ => 2 + }; +} diff --git a/src/test/rustfix/missing-comma-in-match.rs b/src/test/rustfix/missing-comma-in-match.rs new file mode 100644 index 0000000000000..8ccad7b9c9411 --- /dev/null +++ b/src/test/rustfix/missing-comma-in-match.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + match &Some(3) { + &None => 1 + &Some(2) => { 3 } + _ => 2 + }; +} diff --git a/src/test/rustfix/str-as-char.fixed b/src/test/rustfix/str-as-char.fixed new file mode 100644 index 0000000000000..0ace6d96613d7 --- /dev/null +++ b/src/test/rustfix/str-as-char.fixed @@ -0,0 +1,13 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + println!("●●"); +} diff --git a/src/test/rustfix/str-as-char.rs b/src/test/rustfix/str-as-char.rs new file mode 100644 index 0000000000000..fa0e474fc7fb7 --- /dev/null +++ b/src/test/rustfix/str-as-char.rs @@ -0,0 +1,13 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + println!('●●'); +} diff --git a/src/test/rustfix/tuple-float-index.fixed b/src/test/rustfix/tuple-float-index.fixed new file mode 100644 index 0000000000000..9cb7537b42807 --- /dev/null +++ b/src/test/rustfix/tuple-float-index.fixed @@ -0,0 +1,15 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn main () { + ((1, (2, 3)).1).1; +} diff --git a/src/test/rustfix/tuple-float-index.rs b/src/test/rustfix/tuple-float-index.rs new file mode 100644 index 0000000000000..8bfbd0e74db22 --- /dev/null +++ b/src/test/rustfix/tuple-float-index.rs @@ -0,0 +1,15 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z parse-only + +fn main () { + (1, (2, 3)).1.1; +} diff --git a/src/test/rustfix/update-all-references.sh b/src/test/rustfix/update-all-references.sh new file mode 100755 index 0000000000000..c3f615066bbbd --- /dev/null +++ b/src/test/rustfix/update-all-references.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Copyright 2015 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 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# A script to update the references for all tests. The idea is that +# you do a run, which will generate files in the build directory +# containing the (normalized) actual output of the compiler. You then +# run this script, which will copy those files over. If you find +# yourself manually editing a foo.stderr file, you're doing it wrong. +# +# See all `update-references.sh`, if you just want to update a single test. + +if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" != "" ]]; then + echo "usage: $0 " + echo "" + echo "For example:" + echo " $0 ../../../build/x86_64-apple-darwin/test/rustfix" +fi + +BUILD_DIR=$PWD/$1 +MY_DIR=$(dirname $0) +cd $MY_DIR +find . -name '*.rs' | xargs ./update-references.sh $BUILD_DIR diff --git a/src/test/rustfix/update-references.sh b/src/test/rustfix/update-references.sh new file mode 100755 index 0000000000000..bcca2fec10d33 --- /dev/null +++ b/src/test/rustfix/update-references.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Copyright 2015 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 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +# A script to update the references for particular tests. The idea is +# that you do a run, which will generate files in the build directory +# containing the (normalized) actual output of the compiler. This +# script will then copy that output and replace the "expected output" +# files. You can then commit the changes. +# +# If you find yourself manually editing a foo.stderr file, you're +# doing it wrong. + +if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then + echo "usage: $0 " + echo "" + echo "For example:" + echo " $0 ../../../build/x86_64-apple-darwin/test/rustfix *.rs */*.rs" +fi + +MYDIR=$(dirname $0) + +BUILD_DIR="$1" +shift + +shopt -s nullglob + +while [[ "$1" != "" ]]; do + for OUT_NAME in $BUILD_DIR/${1%.rs}.*fixed; do + OUT_BASE=`basename "$OUT_NAME"` + if ! (diff $OUT_NAME $MYDIR/$OUT_BASE >& /dev/null); then + echo updating $MYDIR/$OUT_BASE + cp $OUT_NAME $MYDIR + fi + done + shift +done diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index df0cf61e7c4a0..733fc1f16d24b 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -32,6 +32,7 @@ pub enum Mode { RunMake, Ui, MirOpt, + Rustfix, } impl Mode { @@ -67,6 +68,7 @@ impl FromStr for Mode { "run-make" => Ok(RunMake), "ui" => Ok(Ui), "mir-opt" => Ok(MirOpt), + "rustfix" => Ok(Rustfix), _ => Err(()), } } @@ -74,24 +76,25 @@ impl FromStr for Mode { impl fmt::Display for Mode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(match *self { - CompileFail => "compile-fail", - ParseFail => "parse-fail", - RunFail => "run-fail", - RunPass => "run-pass", - RunPassValgrind => "run-pass-valgrind", - Pretty => "pretty", - DebugInfoGdb => "debuginfo-gdb", - DebugInfoLldb => "debuginfo-lldb", - Codegen => "codegen", - Rustdoc => "rustdoc", - CodegenUnits => "codegen-units", - Incremental => "incremental", - RunMake => "run-make", - Ui => "ui", - MirOpt => "mir-opt", - }, - f) + let s = match *self { + CompileFail => "compile-fail", + ParseFail => "parse-fail", + RunFail => "run-fail", + RunPass => "run-pass", + RunPassValgrind => "run-pass-valgrind", + Pretty => "pretty", + DebugInfoGdb => "debuginfo-gdb", + DebugInfoLldb => "debuginfo-lldb", + Codegen => "codegen", + Rustdoc => "rustdoc", + CodegenUnits => "codegen-units", + Incremental => "incremental", + RunMake => "run-make", + Ui => "ui", + MirOpt => "mir-opt", + Rustfix => "rustfix", + }; + fmt::Display::fmt(s, f) } } @@ -272,4 +275,4 @@ pub fn expected_output_path(testpaths: &TestPaths, pub const UI_EXTENSIONS: &[&str] = &[UI_STDERR, UI_STDOUT, UI_FIXED]; pub const UI_STDERR: &str = "stderr"; pub const UI_STDOUT: &str = "stdout"; -pub const UI_FIXED: &str = "rs.fixed"; +pub const UI_FIXED: &str = "fixed"; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 745952ddf9e60..ea1863b2fd16c 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -11,7 +11,7 @@ use common::{Config, TestPaths}; use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind}; use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc}; -use common::{Incremental, MirOpt, RunMake, Ui}; +use common::{Incremental, MirOpt, RunMake, Ui, Rustfix}; use common::{expected_output_path, UI_STDERR, UI_STDOUT, UI_FIXED}; use common::CompareMode; use diff; @@ -21,6 +21,7 @@ use json; use header::TestProps; use util::logv; use regex::Regex; +use rustfix::{apply_suggestions, get_suggestions_from_json}; use std::collections::VecDeque; use std::collections::HashMap; @@ -241,6 +242,7 @@ impl<'test> TestCx<'test> { CodegenUnits => self.run_codegen_units_test(), Incremental => self.run_incremental_test(), RunMake => self.run_rmake_test(), + Rustfix => self.run_rustfix_test(), Ui => self.run_ui_test(), MirOpt => self.run_mir_opt_test(), } @@ -1687,6 +1689,7 @@ impl<'test> TestCx<'test> { rustc.arg(dir_opt); } + Rustfix | RunPass | RunFail | RunPassValgrind | @@ -2603,29 +2606,6 @@ impl<'test> TestCx<'test> { self.check_error_patterns(&proc_res.stderr, &proc_res); } } - - let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); - - // FIXME(killercup): Add `nll.rs.fixed` files matching - let nll = self.config.compare_mode - .as_ref() - .map(|x| *x == CompareMode::Nll) - .unwrap_or(false); - if fixture_path.exists() && !nll { - use std::collections::HashSet; - use rustfix::{apply_suggestions, get_suggestions_from_json}; - - let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) - .unwrap(); - let expected_fixed = self.load_expected_output_from_path(&fixture_path).unwrap(); - let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); - let fixed_code = apply_suggestions(&unfixed_code, &suggestions); - let errors = self.compare_output("rs.fixed", &fixed_code, &expected_fixed); - if errors > 0 { - panic!("rustfix produced different fixed file!"); - // FIXME(killercup): Add info for update-references.sh call - } - } } fn run_mir_opt_test(&self) { @@ -2950,6 +2930,62 @@ impl<'test> TestCx<'test> { println!("Actual {} saved to {}", kind, output_file.display()); 1 } + + fn run_rustfix_test(&self) { + // First up, compile the test with --error-format=json + let mut rustc = self.make_compile_args( + &self.testpaths.file, + TargetLocation::ThisFile(self.make_exe_name()), + ); + rustc.arg("--error-format").arg("json") + .arg("-L").arg(&self.aux_output_dir_name()); + let proc_res = self.compose_and_run_compiler(rustc, None); + + // Now apply suggestions from rustc to the code itself + let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) + .unwrap(); + let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); + let fixed_code = apply_suggestions(&unfixed_code, &suggestions); + + // Load up what the expected result of fixing should be + let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); + let expected_fixed = self.load_expected_output_from_path(&fixture_path) + .unwrap_or(String::new()); + + // Make sure our fixed code is the same as what we're expecting + let errors = self.compare_output(UI_FIXED, &fixed_code, &expected_fixed); + if errors > 0 { + println!("To update references, run this command from build directory:"); + let relative_path_to_file = self.testpaths + .relative_dir + .join(self.testpaths.file.file_name().unwrap()); + println!( + "{}/update-references.sh '{}' '{}'", + self.config.src_base.display(), + self.config.build_base.display(), + relative_path_to_file.display() + ); + self.fatal_proc_rec( + &format!("{} errors occurred comparing output.", errors), + &proc_res, + ); + } + + // And finally, compile the fixed code and make sure it both succeeds + // and has no diagnostics. + let mut rustc = self.make_compile_args( + &self.testpaths.file.with_extension(UI_FIXED), + TargetLocation::ThisFile(self.make_exe_name()), + ); + rustc.arg("-L").arg(&self.aux_output_dir_name()); + let res = self.compose_and_run_compiler(rustc, None); + if !res.status.success() { + self.fatal_proc_rec("failed to compile fixed code", &res); + } + if !res.stderr.is_empty() { + self.fatal_proc_rec("fixed code is still producing diagnostics", &res); + } + } } struct ProcArgs { From a563027cb8f2cb1c46d2a1e59f3686d3f3a3213a Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Thu, 3 May 2018 15:35:42 +0200 Subject: [PATCH 6/7] Use published rustfix 0.2 version --- src/Cargo.lock | 10 ++++------ src/tools/compiletest/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 113369c997130..0f08eaf596a8f 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -394,7 +394,7 @@ dependencies = [ "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfix 0.1.0 (git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion)", + "rustfix 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2237,11 +2237,9 @@ dependencies = [ [[package]] name = "rustfix" -version = "0.1.0" -source = "git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion#571b43a1a1777561ddd7a41b37512bf0e3452c1a" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", - "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3160,7 +3158,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-ap-syntax_pos 113.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "55793c2a775230c42661194c48d44b35d4c8439d79ad8528e56651e854c48c63" "checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" -"checksum rustfix 0.1.0 (git+https://github.com/rust-lang-nursery/rustfix?branch=apply_suggestion)" = "" +"checksum rustfix 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "165a212dd11124d7070892da20f71d82970ef1d1dd41cd804b70f39740a21c85" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" "checksum same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfb6eded0b06a0b512c8ddbcf04089138c9b4362c2f696f3c3d76039d68f3637" "checksum schannel 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "85fd9df495640643ad2d00443b3d78aae69802ad488debab4f1dd52fc1806ade" diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index 476e5927a2f2b..77554f244c862 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -13,7 +13,7 @@ regex = "0.2" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -rustfix = { git = "https://github.com/rust-lang-nursery/rustfix", branch = "apply_suggestion" } +rustfix = "0.2" [target.'cfg(unix)'.dependencies] libc = "0.2" From 6f2d023028bbd666be2c211b923b32faf10a41da Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 3 May 2018 11:26:58 -0700 Subject: [PATCH 7/7] Fold rustfix tests back into the UI test suite --- src/bootstrap/builder.rs | 2 +- src/bootstrap/test.rs | 6 -- .../closure-immutable-outer-variable.fixed | 22 +++++ ...closure-immutable-outer-variable.nll.fixed | 22 +++++ ...losure-immutable-outer-variable.nll.stderr | 2 +- .../closure-immutable-outer-variable.rs | 2 + .../closure-immutable-outer-variable.stderr | 2 +- src/test/ui/suggestions/issue-45562.fixed | 16 ++++ src/test/ui/suggestions/issue-45562.rs | 2 + src/test/ui/suggestions/issue-45562.stderr | 2 +- ...n-crate-rename-suggestion-formatting.fixed | 15 +++ ...tern-crate-rename-suggestion-formatting.rs | 2 + ...-crate-rename-suggestion-formatting.stderr | 2 +- ...6-consider-borrowing-cast-or-binexpr.fixed | 26 ++++++ ...6756-consider-borrowing-cast-or-binexpr.rs | 2 + ...-consider-borrowing-cast-or-binexpr.stderr | 4 +- .../suggestions/missing-comma-in-match.fixed | 21 +++++ .../ui/suggestions/missing-comma-in-match.rs | 2 + .../suggestions/missing-comma-in-match.stderr | 2 +- src/test/ui/suggestions/str-as-char.fixed | 16 ++++ src/test/ui/suggestions/str-as-char.rs | 2 + src/test/ui/suggestions/str-as-char.stderr | 2 +- .../ui/suggestions/tuple-float-index.fixed | 16 ++++ src/test/ui/suggestions/tuple-float-index.rs | 1 + .../ui/suggestions/tuple-float-index.stderr | 2 +- src/test/ui/update-references.sh | 4 +- src/tools/compiletest/src/common.rs | 3 - src/tools/compiletest/src/header.rs | 10 ++ src/tools/compiletest/src/runtest.rs | 93 +++++++------------ 29 files changed, 223 insertions(+), 80 deletions(-) create mode 100644 src/test/ui/suggestions/closure-immutable-outer-variable.fixed create mode 100644 src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed create mode 100644 src/test/ui/suggestions/issue-45562.fixed create mode 100644 src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed create mode 100644 src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed create mode 100644 src/test/ui/suggestions/missing-comma-in-match.fixed create mode 100644 src/test/ui/suggestions/str-as-char.fixed create mode 100644 src/test/ui/suggestions/tuple-float-index.fixed diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 5920e356bca40..08bb8ab481513 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -326,7 +326,7 @@ impl<'a> Builder<'a> { test::TheBook, test::UnstableBook, test::RustcBook, test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme, // Run run-make last, since these won't pass without make on Windows - test::RunMake, test::RustdocUi, test::Rustfix), + test::RunMake, test::RustdocUi), Kind::Bench => describe!(test::Crate, test::CrateLibrustc), Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook, doc::Standalone, doc::Std, doc::Test, doc::WhitelistedRustc, doc::Rustc, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index fa32dd3163560..e8c40dfdb0ad2 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -716,12 +716,6 @@ default_test!(RunFail { suite: "run-fail" }); -default_test!(Rustfix { - path: "src/test/rustfix", - mode: "rustfix", - suite: "rustfix" -}); - default_test!(RunPassValgrind { path: "src/test/run-pass-valgrind", mode: "run-pass-valgrind", diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.fixed new file mode 100644 index 0000000000000..b3a0d592f7601 --- /dev/null +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.fixed @@ -0,0 +1,22 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let mut y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed new file mode 100644 index 0000000000000..e162678460c6c --- /dev/null +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.fixed @@ -0,0 +1,22 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +// Point at the captured immutable outer variable + +fn foo(mut f: Box) { + f(); +} + +fn main() { + let y = true; + foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable +} diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr index e4e93ecac8e62..bc655114c2b47 100644 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.nll.stderr @@ -1,5 +1,5 @@ error[E0594]: cannot assign to immutable item `y` - --> $DIR/closure-immutable-outer-variable.rs:19:26 + --> $DIR/closure-immutable-outer-variable.rs:21:26 | LL | foo(Box::new(move || y = false) as Box<_>); //~ ERROR cannot assign to captured outer variable | ^^^^^^^^^ cannot mutate diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.rs b/src/test/ui/suggestions/closure-immutable-outer-variable.rs index 1d14afd6a01ac..e162678460c6c 100644 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.rs +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + // Point at the captured immutable outer variable fn foo(mut f: Box) { diff --git a/src/test/ui/suggestions/closure-immutable-outer-variable.stderr b/src/test/ui/suggestions/closure-immutable-outer-variable.stderr index 3353e2c729172..0ee11d8cf15de 100644 --- a/src/test/ui/suggestions/closure-immutable-outer-variable.stderr +++ b/src/test/ui/suggestions/closure-immutable-outer-variable.stderr @@ -1,5 +1,5 @@ error[E0594]: cannot assign to captured outer variable in an `FnMut` closure - --> $DIR/closure-immutable-outer-variable.rs:19:26 + --> $DIR/closure-immutable-outer-variable.rs:21:26 | LL | let y = true; | - help: consider making `y` mutable: `mut y` diff --git a/src/test/ui/suggestions/issue-45562.fixed b/src/test/ui/suggestions/issue-45562.fixed new file mode 100644 index 0000000000000..7c01f0d1ee532 --- /dev/null +++ b/src/test/ui/suggestions/issue-45562.fixed @@ -0,0 +1,16 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#[no_mangle] pub static RAH: usize = 5; +//~^ ERROR const items should never be #[no_mangle] + +fn main() {} diff --git a/src/test/ui/suggestions/issue-45562.rs b/src/test/ui/suggestions/issue-45562.rs index f493df56f949d..c27d52fcdd392 100644 --- a/src/test/ui/suggestions/issue-45562.rs +++ b/src/test/ui/suggestions/issue-45562.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + #[no_mangle] pub const RAH: usize = 5; //~^ ERROR const items should never be #[no_mangle] diff --git a/src/test/ui/suggestions/issue-45562.stderr b/src/test/ui/suggestions/issue-45562.stderr index d6960dca0546f..d9e624cadc705 100644 --- a/src/test/ui/suggestions/issue-45562.stderr +++ b/src/test/ui/suggestions/issue-45562.stderr @@ -1,5 +1,5 @@ error: const items should never be #[no_mangle] - --> $DIR/issue-45562.rs:11:14 + --> $DIR/issue-45562.rs:13:14 | LL | #[no_mangle] pub const RAH: usize = 5; | ---------^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed new file mode 100644 index 0000000000000..e3287030408d1 --- /dev/null +++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.fixed @@ -0,0 +1,15 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +extern crate std as other_std; +fn main() {} +//~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs index 4d75127b645bd..f47ea474d510b 100644 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs +++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + extern crate std; fn main() {} //~^^ ERROR the name `std` is defined multiple times [E0259] diff --git a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr index 8e2b2d845e9b0..ecdfec2b3bfd6 100644 --- a/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr +++ b/src/test/ui/suggestions/issue-45799-bad-extern-crate-rename-suggestion-formatting.stderr @@ -1,5 +1,5 @@ error[E0259]: the name `std` is defined multiple times - --> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:11:1 + --> $DIR/issue-45799-bad-extern-crate-rename-suggestion-formatting.rs:13:1 | LL | extern crate std; | ^^^^^^^^^^^^^^^^^ `std` reimported here diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed new file mode 100644 index 0000000000000..77171cad6e714 --- /dev/null +++ b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.fixed @@ -0,0 +1,26 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +#![allow(unused)] + +fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { + and_yet + 1 +} + +fn main() { + let behold: isize = 2; + let with_tears: usize = 3; + light_flows_our_war_of_mocking_words(&(behold as usize)); + //~^ ERROR mismatched types [E0308] + light_flows_our_war_of_mocking_words(&(with_tears + 4)); + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs index 5617c46afa94c..e5ea9b5ed099d 100644 --- a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs +++ b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + #![allow(unused)] fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { diff --git a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr index e89e9dce94dc4..9c492751ca1a0 100644 --- a/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr +++ b/src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:20:42 + --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:22:42 | LL | light_flows_our_war_of_mocking_words(behold as usize); | ^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL | light_flows_our_war_of_mocking_words(behold as usize); found type `usize` error[E0308]: mismatched types - --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:22:42 + --> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:24:42 | LL | light_flows_our_war_of_mocking_words(with_tears + 4); | ^^^^^^^^^^^^^^ diff --git a/src/test/ui/suggestions/missing-comma-in-match.fixed b/src/test/ui/suggestions/missing-comma-in-match.fixed new file mode 100644 index 0000000000000..4832f35f42d2a --- /dev/null +++ b/src/test/ui/suggestions/missing-comma-in-match.fixed @@ -0,0 +1,21 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + match &Some(3) { + &None => 1, + &Some(2) => { 3 } + //~^ ERROR expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` + //~| NOTE expected one of `,`, `.`, `?`, `}`, or an operator here + _ => 2 + }; +} diff --git a/src/test/ui/suggestions/missing-comma-in-match.rs b/src/test/ui/suggestions/missing-comma-in-match.rs index 6f86cdea3cf5e..e39b20e77ea80 100644 --- a/src/test/ui/suggestions/missing-comma-in-match.rs +++ b/src/test/ui/suggestions/missing-comma-in-match.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + fn main() { match &Some(3) { &None => 1 diff --git a/src/test/ui/suggestions/missing-comma-in-match.stderr b/src/test/ui/suggestions/missing-comma-in-match.stderr index b71a50b66318e..779359341073e 100644 --- a/src/test/ui/suggestions/missing-comma-in-match.stderr +++ b/src/test/ui/suggestions/missing-comma-in-match.stderr @@ -1,5 +1,5 @@ error: expected one of `,`, `.`, `?`, `}`, or an operator, found `=>` - --> $DIR/missing-comma-in-match.rs:14:18 + --> $DIR/missing-comma-in-match.rs:16:18 | LL | &None => 1 | - help: missing a comma here to end this `match` arm diff --git a/src/test/ui/suggestions/str-as-char.fixed b/src/test/ui/suggestions/str-as-char.fixed new file mode 100644 index 0000000000000..c0dad38e43687 --- /dev/null +++ b/src/test/ui/suggestions/str-as-char.fixed @@ -0,0 +1,16 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix + +fn main() { + println!("●●"); + //~^ ERROR character literal may only contain one codepoint +} diff --git a/src/test/ui/suggestions/str-as-char.rs b/src/test/ui/suggestions/str-as-char.rs index 09aca61147df0..b5a5df0af7f94 100644 --- a/src/test/ui/suggestions/str-as-char.rs +++ b/src/test/ui/suggestions/str-as-char.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix + fn main() { println!('●●'); //~^ ERROR character literal may only contain one codepoint diff --git a/src/test/ui/suggestions/str-as-char.stderr b/src/test/ui/suggestions/str-as-char.stderr index d881becf00c9e..60eb182adf145 100644 --- a/src/test/ui/suggestions/str-as-char.stderr +++ b/src/test/ui/suggestions/str-as-char.stderr @@ -1,5 +1,5 @@ error: character literal may only contain one codepoint - --> $DIR/str-as-char.rs:12:14 + --> $DIR/str-as-char.rs:14:14 | LL | println!('●●'); | ^^^^ diff --git a/src/test/ui/suggestions/tuple-float-index.fixed b/src/test/ui/suggestions/tuple-float-index.fixed new file mode 100644 index 0000000000000..55bc2f77dada9 --- /dev/null +++ b/src/test/ui/suggestions/tuple-float-index.fixed @@ -0,0 +1,16 @@ +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix +// compile-flags: -Z parse-only + +fn main () { + ((1, (2, 3)).1).1; //~ ERROR unexpected token: `1.1` +} diff --git a/src/test/ui/suggestions/tuple-float-index.rs b/src/test/ui/suggestions/tuple-float-index.rs index 0a188305a9228..d569ca4cb861e 100644 --- a/src/test/ui/suggestions/tuple-float-index.rs +++ b/src/test/ui/suggestions/tuple-float-index.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix // compile-flags: -Z parse-only fn main () { diff --git a/src/test/ui/suggestions/tuple-float-index.stderr b/src/test/ui/suggestions/tuple-float-index.stderr index 4a1e34890f484..15af0834f0372 100644 --- a/src/test/ui/suggestions/tuple-float-index.stderr +++ b/src/test/ui/suggestions/tuple-float-index.stderr @@ -1,5 +1,5 @@ error: unexpected token: `1.1` - --> $DIR/tuple-float-index.rs:14:17 + --> $DIR/tuple-float-index.rs:15:17 | LL | (1, (2, 3)).1.1; //~ ERROR unexpected token: `1.1` | ------------^^^ diff --git a/src/test/ui/update-references.sh b/src/test/ui/update-references.sh index 4fc11daaa3afa..47a85352b0044 100755 --- a/src/test/ui/update-references.sh +++ b/src/test/ui/update-references.sh @@ -26,7 +26,6 @@ if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then echo " $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs" fi -MYDIR=$(dirname $0) BUILD_DIR="$1" shift @@ -34,7 +33,8 @@ shift shopt -s nullglob while [[ "$1" != "" ]]; do - for EXT in "stderr" "stdout"; do + MYDIR=$(dirname $1) + for EXT in "stderr" "stdout" "fixed"; do for OUT_NAME in $BUILD_DIR/${1%.rs}.*$EXT; do OUT_BASE=`basename "$OUT_NAME"` if ! (diff $OUT_NAME $MYDIR/$OUT_BASE >& /dev/null); then diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 733fc1f16d24b..2df5281659934 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -32,7 +32,6 @@ pub enum Mode { RunMake, Ui, MirOpt, - Rustfix, } impl Mode { @@ -68,7 +67,6 @@ impl FromStr for Mode { "run-make" => Ok(RunMake), "ui" => Ok(Ui), "mir-opt" => Ok(MirOpt), - "rustfix" => Ok(Rustfix), _ => Err(()), } } @@ -92,7 +90,6 @@ impl fmt::Display for Mode { RunMake => "run-make", Ui => "ui", MirOpt => "mir-opt", - Rustfix => "rustfix", }; fmt::Display::fmt(s, f) } diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 73dd079cf0ccb..7ac3f5b5b25e8 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -236,6 +236,7 @@ pub struct TestProps { pub normalize_stdout: Vec<(String, String)>, pub normalize_stderr: Vec<(String, String)>, pub failure_status: i32, + pub run_rustfix: bool, } impl TestProps { @@ -267,6 +268,7 @@ impl TestProps { normalize_stdout: vec![], normalize_stderr: vec![], failure_status: 101, + run_rustfix: false, } } @@ -403,6 +405,10 @@ impl TestProps { if let Some(code) = config.parse_failure_status(ln) { self.failure_status = code; } + + if !self.run_rustfix { + self.run_rustfix = config.parse_run_rustfix(ln); + } }); for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] { @@ -642,6 +648,10 @@ impl Config { None } + + fn parse_run_rustfix(&self, line: &str) -> bool { + self.parse_name_directive(line, "run-rustfix") + } } pub fn lldb_version_to_int(version_string: &str) -> isize { diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ea1863b2fd16c..fae75c352da1f 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -11,7 +11,7 @@ use common::{Config, TestPaths}; use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind}; use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc}; -use common::{Incremental, MirOpt, RunMake, Ui, Rustfix}; +use common::{Incremental, MirOpt, RunMake, Ui}; use common::{expected_output_path, UI_STDERR, UI_STDOUT, UI_FIXED}; use common::CompareMode; use diff; @@ -242,7 +242,6 @@ impl<'test> TestCx<'test> { CodegenUnits => self.run_codegen_units_test(), Incremental => self.run_incremental_test(), RunMake => self.run_rmake_test(), - Rustfix => self.run_rustfix_test(), Ui => self.run_ui_test(), MirOpt => self.run_mir_opt_test(), } @@ -1689,7 +1688,6 @@ impl<'test> TestCx<'test> { rustc.arg(dir_opt); } - Rustfix | RunPass | RunFail | RunPassValgrind | @@ -2555,6 +2553,7 @@ impl<'test> TestCx<'test> { let expected_stderr = self.load_expected_output(UI_STDERR); let expected_stdout = self.load_expected_output(UI_STDOUT); + let expected_fixed = self.load_expected_output(UI_FIXED); let normalized_stdout = self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout); @@ -2571,6 +2570,21 @@ impl<'test> TestCx<'test> { errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout); errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr); + if self.config.compare_mode.is_some() { + // don't test rustfix with nll right now + } else if self.props.run_rustfix { + // Apply suggestions from rustc to the code itself + let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) + .unwrap(); + let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); + let fixed_code = apply_suggestions(&unfixed_code, &suggestions); + + errors += self.compare_output("fixed", &fixed_code, &expected_fixed); + } else if !expected_fixed.is_empty() { + panic!("the `// run-rustfix` directive wasn't found but a `*.fixed` \ + file was found"); + } + if errors > 0 { println!("To update references, run this command from build directory:"); let relative_path_to_file = self.testpaths @@ -2606,6 +2620,23 @@ impl<'test> TestCx<'test> { self.check_error_patterns(&proc_res.stderr, &proc_res); } } + + if self.props.run_rustfix && self.config.compare_mode.is_none() { + // And finally, compile the fixed code and make sure it both + // succeeds and has no diagnostics. + let mut rustc = self.make_compile_args( + &self.testpaths.file.with_extension(UI_FIXED), + TargetLocation::ThisFile(self.make_exe_name()), + ); + rustc.arg("-L").arg(&self.aux_output_dir_name()); + let res = self.compose_and_run_compiler(rustc, None); + if !res.status.success() { + self.fatal_proc_rec("failed to compile fixed code", &res); + } + if !res.stderr.is_empty() { + self.fatal_proc_rec("fixed code is still producing diagnostics", &res); + } + } } fn run_mir_opt_test(&self) { @@ -2930,62 +2961,6 @@ impl<'test> TestCx<'test> { println!("Actual {} saved to {}", kind, output_file.display()); 1 } - - fn run_rustfix_test(&self) { - // First up, compile the test with --error-format=json - let mut rustc = self.make_compile_args( - &self.testpaths.file, - TargetLocation::ThisFile(self.make_exe_name()), - ); - rustc.arg("--error-format").arg("json") - .arg("-L").arg(&self.aux_output_dir_name()); - let proc_res = self.compose_and_run_compiler(rustc, None); - - // Now apply suggestions from rustc to the code itself - let unfixed_code = self.load_expected_output_from_path(&self.testpaths.file) - .unwrap(); - let suggestions = get_suggestions_from_json(&proc_res.stderr, &HashSet::new()).unwrap(); - let fixed_code = apply_suggestions(&unfixed_code, &suggestions); - - // Load up what the expected result of fixing should be - let fixture_path = expected_output_path(&self.testpaths, None, &None, UI_FIXED); - let expected_fixed = self.load_expected_output_from_path(&fixture_path) - .unwrap_or(String::new()); - - // Make sure our fixed code is the same as what we're expecting - let errors = self.compare_output(UI_FIXED, &fixed_code, &expected_fixed); - if errors > 0 { - println!("To update references, run this command from build directory:"); - let relative_path_to_file = self.testpaths - .relative_dir - .join(self.testpaths.file.file_name().unwrap()); - println!( - "{}/update-references.sh '{}' '{}'", - self.config.src_base.display(), - self.config.build_base.display(), - relative_path_to_file.display() - ); - self.fatal_proc_rec( - &format!("{} errors occurred comparing output.", errors), - &proc_res, - ); - } - - // And finally, compile the fixed code and make sure it both succeeds - // and has no diagnostics. - let mut rustc = self.make_compile_args( - &self.testpaths.file.with_extension(UI_FIXED), - TargetLocation::ThisFile(self.make_exe_name()), - ); - rustc.arg("-L").arg(&self.aux_output_dir_name()); - let res = self.compose_and_run_compiler(rustc, None); - if !res.status.success() { - self.fatal_proc_rec("failed to compile fixed code", &res); - } - if !res.stderr.is_empty() { - self.fatal_proc_rec("fixed code is still producing diagnostics", &res); - } - } } struct ProcArgs {