From a56a6d7525464b4fd7779927b57e67b750f1a831 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 12 Jun 2019 00:43:44 +0200 Subject: [PATCH 1/8] bootstrap: pass '--pass' on to compiletest. --- src/bootstrap/builder/tests.rs | 2 ++ src/bootstrap/flags.rs | 17 +++++++++++++++++ src/bootstrap/test.rs | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/bootstrap/builder/tests.rs b/src/bootstrap/builder/tests.rs index 46c58d118f743..cab7443bf3fe8 100644 --- a/src/bootstrap/builder/tests.rs +++ b/src/bootstrap/builder/tests.rs @@ -598,6 +598,7 @@ fn test_with_no_doc_stage0() { bless: false, compare_mode: None, rustfix_coverage: false, + pass: None, }; let build = Build::new(config); @@ -640,6 +641,7 @@ fn test_exclude() { bless: false, compare_mode: None, rustfix_coverage: false, + pass: None, }; let build = Build::new(config); diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 4774c0a51c09a..179accda0c8b2 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -58,6 +58,7 @@ pub enum Subcommand { /// Whether to automatically update stderr/stdout files bless: bool, compare_mode: Option, + pass: Option, test_args: Vec, rustc_args: Vec, fail_fast: bool, @@ -199,6 +200,12 @@ To learn more about a subcommand, run `./x.py -h`" "mode describing what file the actual ui output will be compared to", "COMPARE MODE", ); + opts.optopt( + "", + "pass", + "force {check,build,run}-pass tests to this mode.", + "check | build | run" + ); opts.optflag( "", "rustfix-coverage", @@ -401,6 +408,7 @@ Arguments: paths, bless: matches.opt_present("bless"), compare_mode: matches.opt_str("compare-mode"), + pass: matches.opt_str("pass"), test_args: matches.opt_strs("test-args"), rustc_args: matches.opt_strs("rustc-args"), fail_fast: !matches.opt_present("no-fail-fast"), @@ -524,6 +532,15 @@ impl Subcommand { _ => None, } } + + pub fn pass(&self) -> Option<&str> { + match *self { + Subcommand::Test { + ref pass, .. + } => pass.as_ref().map(|s| &s[..]), + _ => None, + } + } } fn split(s: &[String]) -> Vec { diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 2f9bd067c3115..1d54ca16a315b 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1065,6 +1065,11 @@ impl Step for Compiletest { } }); + if let Some(ref pass) = builder.config.cmd.pass() { + cmd.arg("--pass"); + cmd.arg(pass); + } + if let Some(ref nodejs) = builder.config.nodejs { cmd.arg("--nodejs").arg(nodejs); } From 54337fab39f4c610bd5e5c51cea6a965e7bd7cdb Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 12 Jun 2019 22:54:52 +0200 Subject: [PATCH 2/8] compiletest: support '--pass check' and '// ignore-pass'. --- src/tools/compiletest/src/common.rs | 33 ++++++++++++++++++++++ src/tools/compiletest/src/header.rs | 20 +++++++------ src/tools/compiletest/src/main.rs | 16 ++++++++++- src/tools/compiletest/src/runtest.rs | 42 +++++++++++++++++++--------- 4 files changed, 89 insertions(+), 22 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 722979c3c1402..a75d9f0b0bb9b 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -99,6 +99,36 @@ impl fmt::Display for Mode { } } +#[derive(Clone, Copy, PartialEq, Debug, Hash)] +pub enum PassMode { + Check, + Build, + Run, +} + +impl FromStr for PassMode { + type Err = (); + fn from_str(s: &str) -> Result { + match s { + "check" => Ok(PassMode::Check), + "build" => Ok(PassMode::Build), + "run" => Ok(PassMode::Run), + _ => Err(()), + } + } +} + +impl fmt::Display for PassMode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let s = match *self { + PassMode::Check => "check", + PassMode::Build => "build", + PassMode::Run => "run", + }; + fmt::Display::fmt(s, f) + } +} + #[derive(Clone, Debug, PartialEq)] pub enum CompareMode { Nll, @@ -184,6 +214,9 @@ pub struct Config { /// Exactly match the filter, rather than a substring pub filter_exact: bool, + /// Force the pass mode of a check/build/run-pass test to this mode. + pub force_pass_mode: Option, + /// Write out a parseable log of tests that were run pub logfile: Option, diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 6ce7461f759a4..8202218f7d1cc 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use log::*; -use crate::common::{self, CompareMode, Config, Mode}; +use crate::common::{self, CompareMode, Config, Mode, PassMode}; use crate::util; use crate::extract_gdb_version; @@ -290,13 +290,6 @@ impl EarlyProps { } } -#[derive(Clone, Copy, PartialEq, Debug)] -pub enum PassMode { - Check, - Build, - Run, -} - #[derive(Clone, Debug)] pub struct TestProps { // Lines that should be expected, in order, on standard out @@ -358,6 +351,8 @@ pub struct TestProps { pub incremental_dir: Option, // How far should the test proceed while still passing. pub pass_mode: Option, + // Ignore `--pass` overrides from the command line for this test. + pub ignore_pass: bool, // rustdoc will test the output of the `--test` option pub check_test_line_numbers_match: bool, // Do not pass `-Z ui-testing` to UI tests @@ -400,6 +395,7 @@ impl TestProps { forbid_output: vec![], incremental_dir: None, pass_mode: None, + ignore_pass: false, check_test_line_numbers_match: false, disable_ui_testing_normalization: false, normalize_stdout: vec![], @@ -528,6 +524,10 @@ impl TestProps { self.update_pass_mode(ln, cfg, config); + if !self.ignore_pass { + self.ignore_pass = config.parse_ignore_pass(ln); + } + if !self.disable_ui_testing_normalization { self.disable_ui_testing_normalization = config.parse_disable_ui_testing_normalization(ln); @@ -743,6 +743,10 @@ impl Config { self.parse_name_directive(line, "check-test-line-numbers-match") } + fn parse_ignore_pass(&self, line: &str) -> bool { + self.parse_name_directive(line, "ignore-pass") + } + fn parse_assembly_output(&self, line: &str) -> Option { self.parse_name_value_directive(line, "assembly-output") .map(|r| r.trim().to_string()) diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index d0dc9d11d3963..288853d5e1866 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -5,7 +5,7 @@ extern crate test; -use crate::common::CompareMode; +use crate::common::{CompareMode, PassMode}; use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS}; use crate::common::{Config, TestPaths}; use crate::common::{DebugInfoCdb, DebugInfoGdbLldb, DebugInfoGdb, DebugInfoLldb, Mode, Pretty}; @@ -128,6 +128,12 @@ pub fn parse_config(args: Vec) -> Config { "(compile-fail|run-fail|run-pass|\ run-pass-valgrind|pretty|debug-info|incremental|mir-opt)", ) + .optopt( + "", + "pass", + "force {check,build,run}-pass tests to this mode.", + "check | build | run" + ) .optflag("", "ignored", "run tests marked as ignored") .optflag("", "exact", "filters match exactly") .optopt( @@ -320,6 +326,10 @@ pub fn parse_config(args: Vec) -> Config { run_ignored, filter: matches.free.first().cloned(), filter_exact: matches.opt_present("exact"), + force_pass_mode: matches.opt_str("pass").map(|mode| + mode.parse::() + .unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given.", mode)) + ), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), runtool: matches.opt_str("runtool"), host_rustcflags: matches.opt_str("host-rustcflags"), @@ -382,6 +392,10 @@ pub fn log_config(config: &Config) { ), ); logv(c, format!("filter_exact: {}", config.filter_exact)); + logv(c, format!( + "force_pass_mode: {}", + opt_str(&config.force_pass_mode.map(|m| format!("{}", m))), + )); logv(c, format!("runtool: {}", opt_str(&config.runtool))); logv( c, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8b52a529d440a..270420991e9f5 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1,6 +1,6 @@ // ignore-tidy-filelength -use crate::common::CompareMode; +use crate::common::{CompareMode, PassMode}; use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT}; use crate::common::{output_base_dir, output_base_name, output_testname_unique}; use crate::common::{Codegen, CodegenUnits, Rustdoc}; @@ -10,7 +10,7 @@ use crate::common::{Config, TestPaths}; use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest, Assembly}; use diff; use crate::errors::{self, Error, ErrorKind}; -use crate::header::{TestProps, PassMode}; +use crate::header::TestProps; use crate::json; use regex::{Captures, Regex}; use rustfix::{apply_suggestions, get_suggestions_from_json, Filter}; @@ -211,6 +211,7 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { props: &props, testpaths, revision: revision, + is_aux: false, }; create_dir_all(&cx.output_base_dir()).unwrap(); @@ -229,6 +230,7 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { props: &revision_props, testpaths, revision: Some(revision), + is_aux: false, }; rev_cx.run_revision(); } @@ -260,6 +262,10 @@ pub fn compute_stamp_hash(config: &Config) -> String { env::var_os("PYTHONPATH").hash(&mut hash); } + if let Ui | RunPass = config.mode { + config.force_pass_mode.hash(&mut hash); + } + format!("{:x}", hash.finish()) } @@ -268,6 +274,7 @@ struct TestCx<'test> { props: &'test TestProps, testpaths: &'test TestPaths, revision: Option<&'test str>, + is_aux: bool, } struct DebuggerCommands { @@ -309,10 +316,18 @@ impl<'test> TestCx<'test> { } } + fn effective_pass_mode(&self) -> Option { + if !self.props.ignore_pass { + if let (mode @ Some(_), Some(_)) = (self.config.force_pass_mode, self.props.pass_mode) { + return mode; + } + } + self.props.pass_mode + } + fn should_run_successfully(&self) -> bool { match self.config.mode { - RunPass => true, - Ui => self.props.pass_mode == Some(PassMode::Run), + RunPass | Ui => self.effective_pass_mode() == Some(PassMode::Run), mode => panic!("unimplemented for mode {:?}", mode), } } @@ -1563,6 +1578,7 @@ impl<'test> TestCx<'test> { props: &aux_props, testpaths: &aux_testpaths, revision: self.revision, + is_aux: true, }; // Create the directory for the stdout/stderr files. create_dir_all(aux_cx.output_base_dir()).unwrap(); @@ -1732,6 +1748,7 @@ impl<'test> TestCx<'test> { props: &aux_props, testpaths: &aux_testpaths, revision: self.revision, + is_aux: true, }; // Create the directory for the stdout/stderr files. create_dir_all(aux_cx.output_base_dir()).unwrap(); @@ -1871,7 +1888,11 @@ impl<'test> TestCx<'test> { result } - fn make_compile_args(&self, input_file: &Path, output_file: TargetLocation) -> Command { + fn make_compile_args( + &self, + input_file: &Path, + output_file: TargetLocation, + ) -> Command { let is_rustdoc = self.config.src_base.ends_with("rustdoc-ui") || self.config.src_base.ends_with("rustdoc-js"); let mut rustc = if !is_rustdoc { @@ -1968,14 +1989,8 @@ impl<'test> TestCx<'test> { } } - if self.props.pass_mode == Some(PassMode::Check) { - assert!( - !self - .props - .compile_flags - .iter() - .any(|s| s.starts_with("--emit")) - ); + let pass_mode = if self.is_aux { self.props.pass_mode } else { self.effective_pass_mode() }; + if let Some(PassMode::Check) = pass_mode { rustc.args(&["--emit", "metadata"]); } @@ -2713,6 +2728,7 @@ impl<'test> TestCx<'test> { props: &revision_props, testpaths: self.testpaths, revision: self.revision, + is_aux: false, }; if self.config.verbose { From e364eb40d5652d3aa668fe4b50e78098a83fe04e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 12 Jun 2019 22:55:38 +0200 Subject: [PATCH 3/8] add '// ignore-pass' where applicable. --- src/test/ui/emit-artifact-notifications.rs | 2 ++ src/test/ui/print_type_sizes/generics.rs | 3 +++ src/test/ui/print_type_sizes/niche-filling.rs | 3 +++ src/test/ui/print_type_sizes/no_duplicates.rs | 3 +++ src/test/ui/print_type_sizes/packed.rs | 3 +++ src/test/ui/print_type_sizes/repr-align.rs | 3 +++ src/test/ui/print_type_sizes/uninhabited.rs | 3 +++ 7 files changed, 20 insertions(+) diff --git a/src/test/ui/emit-artifact-notifications.rs b/src/test/ui/emit-artifact-notifications.rs index c2c930c8b1bae..2f17f95b7a3be 100644 --- a/src/test/ui/emit-artifact-notifications.rs +++ b/src/test/ui/emit-artifact-notifications.rs @@ -1,5 +1,7 @@ // compile-flags:--emit=metadata --error-format=json -Z emit-artifact-notifications // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. // A very basic test for the emission of artifact notifications in JSON output. diff --git a/src/test/ui/print_type_sizes/generics.rs b/src/test/ui/print_type_sizes/generics.rs index 360c995868654..ecfc03717db46 100644 --- a/src/test/ui/print_type_sizes/generics.rs +++ b/src/test/ui/print_type_sizes/generics.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. // This file illustrates how generics are handled: types have to be // monomorphized, in the MIR of the original function in which they diff --git a/src/test/ui/print_type_sizes/niche-filling.rs b/src/test/ui/print_type_sizes/niche-filling.rs index 0127261b2b7d0..98b506b1f0db1 100644 --- a/src/test/ui/print_type_sizes/niche-filling.rs +++ b/src/test/ui/print_type_sizes/niche-filling.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. // This file illustrates how niche-filling enums are handled, // modelled after cases like `Option<&u32>`, `Option` and such. diff --git a/src/test/ui/print_type_sizes/no_duplicates.rs b/src/test/ui/print_type_sizes/no_duplicates.rs index 7307c0fd8b406..f1b8a28ae304b 100644 --- a/src/test/ui/print_type_sizes/no_duplicates.rs +++ b/src/test/ui/print_type_sizes/no_duplicates.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. // This file illustrates that when the same type occurs repeatedly // (even if multiple functions), it is only printed once in the diff --git a/src/test/ui/print_type_sizes/packed.rs b/src/test/ui/print_type_sizes/packed.rs index ec3efd6923aef..a8d409a91a240 100644 --- a/src/test/ui/print_type_sizes/packed.rs +++ b/src/test/ui/print_type_sizes/packed.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. // This file illustrates how packing is handled; it should cause // the elimination of padding that would normally be introduced diff --git a/src/test/ui/print_type_sizes/repr-align.rs b/src/test/ui/print_type_sizes/repr-align.rs index fd452f411c51e..3b5248b6f7ebb 100644 --- a/src/test/ui/print_type_sizes/repr-align.rs +++ b/src/test/ui/print_type_sizes/repr-align.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. // This file illustrates how padding is handled: alignment // requirements can lead to the introduction of padding, either before diff --git a/src/test/ui/print_type_sizes/uninhabited.rs b/src/test/ui/print_type_sizes/uninhabited.rs index 14245d0dc9a28..c33965c4f53ea 100644 --- a/src/test/ui/print_type_sizes/uninhabited.rs +++ b/src/test/ui/print_type_sizes/uninhabited.rs @@ -1,5 +1,8 @@ // compile-flags: -Z print-type-sizes // compile-pass +// ignore-pass +// ^-- needed because `--pass check` does not emit the output needed. +// FIXME: consider using an attribute instead of side-effects. #![feature(never_type)] #![feature(start)] From e4e0f959ce23a6a7c33f0178b1c03d1ca19f3746 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 12 Jun 2019 22:53:00 +0200 Subject: [PATCH 4/8] promoted_errors: warn -> deny. --- .../ui/consts/const-eval/promoted_errors.rs | 24 ++++++----- .../consts/const-eval/promoted_errors.stderr | 42 ++++++++++--------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/test/ui/consts/const-eval/promoted_errors.rs b/src/test/ui/consts/const-eval/promoted_errors.rs index ebf80e7d2e670..fa8859cbb3bb6 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.rs +++ b/src/test/ui/consts/const-eval/promoted_errors.rs @@ -1,19 +1,23 @@ -#![warn(const_err)] - -// compile-pass // compile-flags: -O + +#![deny(const_err)] + fn main() { println!("{}", 0u32 - 1); let _x = 0u32 - 1; - //~^ WARN const_err + //~^ ERROR this expression will panic at runtime [const_err] println!("{}", 1/(1-1)); - //~^ WARN const_err + //~^ ERROR this expression will panic at runtime [const_err] + //~| ERROR attempt to divide by zero [const_err] + //~| ERROR reaching this expression at runtime will panic or abort [const_err] let _x = 1/(1-1); - //~^ WARN const_err - //~| WARN const_err + //~^ ERROR const_err + //~| ERROR const_err println!("{}", 1/(false as u32)); - //~^ WARN const_err + //~^ ERROR this expression will panic at runtime [const_err] + //~| ERROR attempt to divide by zero [const_err] + //~| ERROR reaching this expression at runtime will panic or abort [const_err] let _x = 1/(false as u32); - //~^ WARN const_err - //~| WARN const_err + //~^ ERROR const_err + //~| ERROR const_err } diff --git a/src/test/ui/consts/const-eval/promoted_errors.stderr b/src/test/ui/consts/const-eval/promoted_errors.stderr index c9f3a7659f9cd..12407accf096f 100644 --- a/src/test/ui/consts/const-eval/promoted_errors.stderr +++ b/src/test/ui/consts/const-eval/promoted_errors.stderr @@ -1,72 +1,74 @@ -warning: this expression will panic at runtime +error: this expression will panic at runtime --> $DIR/promoted_errors.rs:7:14 | LL | let _x = 0u32 - 1; | ^^^^^^^^ attempt to subtract with overflow | note: lint level defined here - --> $DIR/promoted_errors.rs:1:9 + --> $DIR/promoted_errors.rs:3:9 | -LL | #![warn(const_err)] +LL | #![deny(const_err)] | ^^^^^^^^^ -warning: attempt to divide by zero +error: attempt to divide by zero --> $DIR/promoted_errors.rs:9:20 | LL | println!("{}", 1/(1-1)); | ^^^^^^^ -warning: this expression will panic at runtime +error: this expression will panic at runtime --> $DIR/promoted_errors.rs:9:20 | LL | println!("{}", 1/(1-1)); | ^^^^^^^ attempt to divide by zero -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:11:14 +error: attempt to divide by zero + --> $DIR/promoted_errors.rs:13:14 | LL | let _x = 1/(1-1); | ^^^^^^^ -warning: this expression will panic at runtime - --> $DIR/promoted_errors.rs:11:14 +error: this expression will panic at runtime + --> $DIR/promoted_errors.rs:13:14 | LL | let _x = 1/(1-1); | ^^^^^^^ attempt to divide by zero -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:14:20 +error: attempt to divide by zero + --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1/(false as u32)); | ^^^^^^^^^^^^^^^^ -warning: this expression will panic at runtime - --> $DIR/promoted_errors.rs:14:20 +error: this expression will panic at runtime + --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1/(false as u32)); | ^^^^^^^^^^^^^^^^ attempt to divide by zero -warning: attempt to divide by zero - --> $DIR/promoted_errors.rs:16:14 +error: attempt to divide by zero + --> $DIR/promoted_errors.rs:20:14 | LL | let _x = 1/(false as u32); | ^^^^^^^^^^^^^^^^ -warning: this expression will panic at runtime - --> $DIR/promoted_errors.rs:16:14 +error: this expression will panic at runtime + --> $DIR/promoted_errors.rs:20:14 | LL | let _x = 1/(false as u32); | ^^^^^^^^^^^^^^^^ attempt to divide by zero -warning: reaching this expression at runtime will panic or abort - --> $DIR/promoted_errors.rs:14:20 +error: reaching this expression at runtime will panic or abort + --> $DIR/promoted_errors.rs:16:20 | LL | println!("{}", 1/(false as u32)); | ^^^^^^^^^^^^^^^^ attempt to divide by zero -warning: reaching this expression at runtime will panic or abort +error: reaching this expression at runtime will panic or abort --> $DIR/promoted_errors.rs:9:20 | LL | println!("{}", 1/(1-1)); | ^^^^^^^ attempt to divide by zero +error: aborting due to 11 previous errors + From 5baac07d4bad3bde857d70338a8cabf28bcf0b64 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 12 Jun 2019 22:53:17 +0200 Subject: [PATCH 5/8] lint-type-overflow2: warn -> deny. --- src/test/ui/lint/lint-type-overflow2.rs | 17 +++++----- src/test/ui/lint/lint-type-overflow2.stderr | 36 ++++++++------------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/test/ui/lint/lint-type-overflow2.rs b/src/test/ui/lint/lint-type-overflow2.rs index 507e8d0734970..684df604205d3 100644 --- a/src/test/ui/lint/lint-type-overflow2.rs +++ b/src/test/ui/lint/lint-type-overflow2.rs @@ -1,15 +1,14 @@ // compile-flags: -O -#![warn(overflowing_literals)] -#![warn(const_err)] -// compile-pass -#[allow(unused_variables)] +#![deny(overflowing_literals)] +#![deny(const_err)] +#![allow(unused_variables)] fn main() { - let x2: i8 = --128; //~ warn: literal out of range for i8 + let x2: i8 = --128; //~ ERROR literal out of range for `i8` - let x = -3.40282357e+38_f32; //~ warn: literal out of range for f32 - let x = 3.40282357e+38_f32; //~ warn: literal out of range for f32 - let x = -1.7976931348623159e+308_f64; //~ warn: literal out of range for f64 - let x = 1.7976931348623159e+308_f64; //~ warn: literal out of range for f64 + let x = -3.40282357e+38_f32; //~ ERROR literal out of range for `f32` + let x = 3.40282357e+38_f32; //~ ERROR literal out of range for `f32` + let x = -1.7976931348623159e+308_f64; //~ ERROR literal out of range for `f64` + let x = 1.7976931348623159e+308_f64; //~ ERROR literal out of range for `f64` } diff --git a/src/test/ui/lint/lint-type-overflow2.stderr b/src/test/ui/lint/lint-type-overflow2.stderr index c76e9e25d5a93..6d8197eb4fe3a 100644 --- a/src/test/ui/lint/lint-type-overflow2.stderr +++ b/src/test/ui/lint/lint-type-overflow2.stderr @@ -1,48 +1,38 @@ -warning: literal out of range for `i8` - --> $DIR/lint-type-overflow2.rs:9:20 +error: literal out of range for `i8` + --> $DIR/lint-type-overflow2.rs:8:20 | LL | let x2: i8 = --128; | ^^^ | note: lint level defined here - --> $DIR/lint-type-overflow2.rs:2:9 + --> $DIR/lint-type-overflow2.rs:3:9 | -LL | #![warn(overflowing_literals)] +LL | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ -warning: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:11:14 +error: literal out of range for `f32` + --> $DIR/lint-type-overflow2.rs:10:14 | LL | let x = -3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ -warning: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:12:14 +error: literal out of range for `f32` + --> $DIR/lint-type-overflow2.rs:11:14 | LL | let x = 3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ -warning: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:13:14 +error: literal out of range for `f64` + --> $DIR/lint-type-overflow2.rs:12:14 | LL | let x = -1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:14:14 +error: literal out of range for `f64` + --> $DIR/lint-type-overflow2.rs:13:14 | LL | let x = 1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: this expression will panic at runtime - --> $DIR/lint-type-overflow2.rs:9:18 - | -LL | let x2: i8 = --128; - | ^^^^^ attempt to negate with overflow - | -note: lint level defined here - --> $DIR/lint-type-overflow2.rs:3:9 - | -LL | #![warn(const_err)] - | ^^^^^^^^^ +error: aborting due to 5 previous errors From 5eaedda9f52e23f6f11a832159c2b6ddb531665c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 24 Jun 2019 18:32:52 +0200 Subject: [PATCH 6/8] Address review comments. --- src/test/ui/lint/lint-type-overflow2.rs | 1 - .../ui/proc-macro/auxiliary/generate-mod.rs | 1 + .../ui/save-analysis/emit-notifications.rs | 3 ++ src/tools/compiletest/src/header.rs | 13 +++++++-- src/tools/compiletest/src/main.rs | 2 +- src/tools/compiletest/src/runtest.rs | 28 ++++++------------- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/test/ui/lint/lint-type-overflow2.rs b/src/test/ui/lint/lint-type-overflow2.rs index 684df604205d3..c1f874c079cb5 100644 --- a/src/test/ui/lint/lint-type-overflow2.rs +++ b/src/test/ui/lint/lint-type-overflow2.rs @@ -2,7 +2,6 @@ #![deny(overflowing_literals)] #![deny(const_err)] -#![allow(unused_variables)] fn main() { let x2: i8 = --128; //~ ERROR literal out of range for `i8` diff --git a/src/test/ui/proc-macro/auxiliary/generate-mod.rs b/src/test/ui/proc-macro/auxiliary/generate-mod.rs index 8b41e8b3b3eb8..e950f7d62d645 100644 --- a/src/test/ui/proc-macro/auxiliary/generate-mod.rs +++ b/src/test/ui/proc-macro/auxiliary/generate-mod.rs @@ -1,6 +1,7 @@ // run-pass // force-host // no-prefer-dynamic +// ignore-pass #![crate_type = "proc-macro"] diff --git a/src/test/ui/save-analysis/emit-notifications.rs b/src/test/ui/save-analysis/emit-notifications.rs index 411acbb14db68..ebc2717499843 100644 --- a/src/test/ui/save-analysis/emit-notifications.rs +++ b/src/test/ui/save-analysis/emit-notifications.rs @@ -1,4 +1,7 @@ // compile-pass // compile-flags: -Zsave-analysis -Zemit-artifact-notifications // compile-flags: --crate-type rlib --error-format=json +// ignore-pass +// ^-- needed because otherwise, the .stderr file changes with --pass check + pub fn foo() {} diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 8202218f7d1cc..52f777db2daa6 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -350,9 +350,9 @@ pub struct TestProps { // arguments. (In particular, it propagates to the aux-builds.) pub incremental_dir: Option, // How far should the test proceed while still passing. - pub pass_mode: Option, + pass_mode: Option, // Ignore `--pass` overrides from the command line for this test. - pub ignore_pass: bool, + ignore_pass: bool, // rustdoc will test the output of the `--test` option pub check_test_line_numbers_match: bool, // Do not pass `-Z ui-testing` to UI tests @@ -608,6 +608,15 @@ impl TestProps { (_, None) => {} } } + + pub fn pass_mode(&self, config: &Config) -> Option { + if !self.ignore_pass { + if let (mode @ Some(_), Some(_)) = (config.force_pass_mode, self.pass_mode) { + return mode; + } + } + self.pass_mode + } } fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) { diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 288853d5e1866..597fdf2d95e30 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -328,7 +328,7 @@ pub fn parse_config(args: Vec) -> Config { filter_exact: matches.opt_present("exact"), force_pass_mode: matches.opt_str("pass").map(|mode| mode.parse::() - .unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given.", mode)) + .unwrap_or_else(|_| panic!("unknown `--pass` option `{}` given", mode)) ), logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)), runtool: matches.opt_str("runtool"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 270420991e9f5..cb58663242669 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -211,7 +211,6 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { props: &props, testpaths, revision: revision, - is_aux: false, }; create_dir_all(&cx.output_base_dir()).unwrap(); @@ -230,7 +229,6 @@ pub fn run(config: Config, testpaths: &TestPaths, revision: Option<&str>) { props: &revision_props, testpaths, revision: Some(revision), - is_aux: false, }; rev_cx.run_revision(); } @@ -262,7 +260,7 @@ pub fn compute_stamp_hash(config: &Config) -> String { env::var_os("PYTHONPATH").hash(&mut hash); } - if let Ui | RunPass = config.mode { + if let Ui | RunPass | Incremental = config.mode { config.force_pass_mode.hash(&mut hash); } @@ -274,7 +272,6 @@ struct TestCx<'test> { props: &'test TestProps, testpaths: &'test TestPaths, revision: Option<&'test str>, - is_aux: bool, } struct DebuggerCommands { @@ -316,18 +313,13 @@ impl<'test> TestCx<'test> { } } - fn effective_pass_mode(&self) -> Option { - if !self.props.ignore_pass { - if let (mode @ Some(_), Some(_)) = (self.config.force_pass_mode, self.props.pass_mode) { - return mode; - } - } - self.props.pass_mode + fn pass_mode(&self) -> Option { + self.props.pass_mode(self.config) } fn should_run_successfully(&self) -> bool { match self.config.mode { - RunPass | Ui => self.effective_pass_mode() == Some(PassMode::Run), + RunPass | Ui => self.pass_mode() == Some(PassMode::Run), mode => panic!("unimplemented for mode {:?}", mode), } } @@ -337,7 +329,7 @@ impl<'test> TestCx<'test> { CompileFail => false, RunPass => true, JsDocTest => true, - Ui => self.props.pass_mode.is_some(), + Ui => self.pass_mode().is_some(), Incremental => { let revision = self.revision .expect("incremental tests require a list of revisions"); @@ -345,7 +337,7 @@ impl<'test> TestCx<'test> { true } else if revision.starts_with("cfail") { // FIXME: would be nice if incremental revs could start with "cpass" - self.props.pass_mode.is_some() + self.pass_mode().is_some() } else { panic!("revision name must begin with rpass, rfail, or cfail"); } @@ -1356,7 +1348,7 @@ impl<'test> TestCx<'test> { fn check_error_patterns(&self, output_to_check: &str, proc_res: &ProcRes) { debug!("check_error_patterns"); if self.props.error_patterns.is_empty() { - if self.props.pass_mode.is_some() { + if self.pass_mode().is_some() { return; } else { self.fatal(&format!( @@ -1578,7 +1570,6 @@ impl<'test> TestCx<'test> { props: &aux_props, testpaths: &aux_testpaths, revision: self.revision, - is_aux: true, }; // Create the directory for the stdout/stderr files. create_dir_all(aux_cx.output_base_dir()).unwrap(); @@ -1748,7 +1739,6 @@ impl<'test> TestCx<'test> { props: &aux_props, testpaths: &aux_testpaths, revision: self.revision, - is_aux: true, }; // Create the directory for the stdout/stderr files. create_dir_all(aux_cx.output_base_dir()).unwrap(); @@ -1989,8 +1979,7 @@ impl<'test> TestCx<'test> { } } - let pass_mode = if self.is_aux { self.props.pass_mode } else { self.effective_pass_mode() }; - if let Some(PassMode::Check) = pass_mode { + if let Some(PassMode::Check) = self.pass_mode() { rustc.args(&["--emit", "metadata"]); } @@ -2728,7 +2717,6 @@ impl<'test> TestCx<'test> { props: &revision_props, testpaths: self.testpaths, revision: self.revision, - is_aux: false, }; if self.config.verbose { From a60bbb0f6b27f7456cb4f85c67faa9794a7c2cf7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 24 Jun 2019 20:45:19 +0200 Subject: [PATCH 7/8] --bless you. --- src/test/ui/lint/lint-type-overflow2.stderr | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/ui/lint/lint-type-overflow2.stderr b/src/test/ui/lint/lint-type-overflow2.stderr index 6d8197eb4fe3a..761b095464fe8 100644 --- a/src/test/ui/lint/lint-type-overflow2.stderr +++ b/src/test/ui/lint/lint-type-overflow2.stderr @@ -1,5 +1,5 @@ error: literal out of range for `i8` - --> $DIR/lint-type-overflow2.rs:8:20 + --> $DIR/lint-type-overflow2.rs:7:20 | LL | let x2: i8 = --128; | ^^^ @@ -11,25 +11,25 @@ LL | #![deny(overflowing_literals)] | ^^^^^^^^^^^^^^^^^^^^ error: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:10:14 + --> $DIR/lint-type-overflow2.rs:9:14 | LL | let x = -3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ error: literal out of range for `f32` - --> $DIR/lint-type-overflow2.rs:11:14 + --> $DIR/lint-type-overflow2.rs:10:14 | LL | let x = 3.40282357e+38_f32; | ^^^^^^^^^^^^^^^^^^ error: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:12:14 + --> $DIR/lint-type-overflow2.rs:11:14 | LL | let x = -1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: literal out of range for `f64` - --> $DIR/lint-type-overflow2.rs:13:14 + --> $DIR/lint-type-overflow2.rs:12:14 | LL | let x = 1.7976931348623159e+308_f64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 93077f3f3922817a70013c403831bf1db4a30114 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 26 Jun 2019 14:32:23 +0200 Subject: [PATCH 8/8] Hash force_pass_mode when config.mode == Pretty. --- src/tools/compiletest/src/runtest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index cb58663242669..35caf82dd7128 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -260,7 +260,7 @@ pub fn compute_stamp_hash(config: &Config) -> String { env::var_os("PYTHONPATH").hash(&mut hash); } - if let Ui | RunPass | Incremental = config.mode { + if let Ui | RunPass | Incremental | Pretty = config.mode { config.force_pass_mode.hash(&mut hash); }