Skip to content

Commit

Permalink
Auto merge of rust-lang#81889 - m-ou-se:rollup-k63log3, r=m-ou-se
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#71531 (Move treat err as bug tests to ui)
 - rust-lang#81356 (libtest: allow multiple filters)
 - rust-lang#81735 (faster few span methods)
 - rust-lang#81779 (improve error message for disallowed ptr-to-int casts in const eval)
 - rust-lang#81817 (Add option to emit compiler stderr per bitwidth.)
 - rust-lang#81828 (parse_format: treat r" as a literal)
 - rust-lang#81840 (fix formatting of std::iter::Map)
 - rust-lang#81861 (Show MIR bytes separately in -Zmeta-stats output)
 - rust-lang#81865 (Clean up weird Option mapping)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 8, 2021
2 parents 921ec4b + 9d1e8fe commit 0fc6756
Show file tree
Hide file tree
Showing 35 changed files with 203 additions and 71 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

let tcx = self.tcx;

// Encode MIR.
i = self.position();
self.encode_mir();
let mir_bytes = self.position() - i;

// Encode the items.
i = self.position();
self.encode_def_ids();
self.encode_mir();
self.encode_info_for_items();
let item_bytes = self.position() - i;

Expand Down Expand Up @@ -700,6 +704,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
println!(" def-path table bytes: {}", def_path_table_bytes);
println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
println!(" mir bytes: {}", mir_bytes);
println!(" item bytes: {}", item_bytes);
println!(" table bytes: {}", tables_bytes);
println!(" hygiene bytes: {}", hygiene_bytes);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_mir/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::interpret::{
#[derive(Clone, Debug)]
pub enum ConstEvalErrKind {
NeedsRfc(String),
PtrToIntCast,
ConstAccessesStatic,
ModifiedGlobal,
AssertFailure(AssertKind<ConstInt>),
Expand All @@ -39,6 +40,12 @@ impl fmt::Display for ConstEvalErrKind {
NeedsRfc(ref msg) => {
write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
}
PtrToIntCast => {
write!(
f,
"cannot cast pointer to integer because it was not created by cast from integer"
)
}
ConstAccessesStatic => write!(f, "constant accesses static"),
ModifiedGlobal => {
write!(f, "modifying a static's initial value from another static's initializer")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
}

fn ptr_to_int(_mem: &Memory<'mir, 'tcx, Self>, _ptr: Pointer) -> InterpResult<'tcx, u64> {
Err(ConstEvalErrKind::NeedsRfc("pointer-to-integer cast".to_string()).into())
Err(ConstEvalErrKind::PtrToIntCast.into())
}

fn binary_ptr_op(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ fn find_skips_from_snippet(
str_style: Option<usize>,
) -> (Vec<usize>, bool) {
let snippet = match snippet {
Some(ref s) if s.starts_with('"') || s.starts_with("r#") => s,
Some(ref s) if s.starts_with('"') || s.starts_with("r\"") || s.starts_with("r#") => s,
_ => return (vec![], false),
};

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#![feature(nll)]
#![feature(min_specialization)]
#![feature(option_expect_none)]
#![feature(str_split_once)]

#[macro_use]
extern crate rustc_macros;
Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl SourceMap {

pub fn is_line_before_span_empty(&self, sp: Span) -> bool {
match self.span_to_prev_source(sp) {
Ok(s) => s.split('\n').last().map_or(false, |l| l.trim_start().is_empty()),
Ok(s) => s.rsplit_once('\n').unwrap_or(("", &s)).1.trim_start().is_empty(),
Err(_) => false,
}
}
Expand Down Expand Up @@ -632,10 +632,11 @@ impl SourceMap {
pub fn span_to_margin(&self, sp: Span) -> Option<usize> {
match self.span_to_prev_source(sp) {
Err(_) => None,
Ok(source) => source
.split('\n')
.last()
.map(|last_line| last_line.len() - last_line.trim_start().len()),
Ok(source) => {
let last_line = source.rsplit_once('\n').unwrap_or(("", &source)).1;

Some(last_line.len() - last_line.trim_start().len())
}
}
}

Expand All @@ -651,7 +652,7 @@ impl SourceMap {
pub fn span_extend_to_prev_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
if let Ok(prev_source) = self.span_to_prev_source(sp) {
let prev_source = prev_source.rsplit(c).next().unwrap_or("");
if !prev_source.is_empty() && (!prev_source.contains('\n') || accept_newlines) {
if !prev_source.is_empty() && (accept_newlines || !prev_source.contains('\n')) {
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
}
}
Expand All @@ -673,7 +674,7 @@ impl SourceMap {
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
if prev_source.is_empty() && sp.lo().0 != 0 {
return sp.with_lo(BytePos(sp.lo().0 - 1));
} else if !prev_source.contains('\n') || accept_newlines {
} else if accept_newlines || !prev_source.contains('\n') {
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
}
}
Expand All @@ -693,7 +694,7 @@ impl SourceMap {
pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
if let Ok(next_source) = self.span_to_next_source(sp) {
let next_source = next_source.split(c).next().unwrap_or("");
if !next_source.is_empty() && (!next_source.contains('\n') || accept_newlines) {
if !next_source.is_empty() && (accept_newlines || !next_source.contains('\n')) {
return sp.with_hi(BytePos(sp.hi().0 + next_source.len() as u32));
}
}
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.check_expr_eq_type(&e, ty);
ty
}
ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => self.check_then_else(
&cond,
then_expr,
opt_else_expr.as_ref().map(|e| &**e),
expr.span,
expected,
),
ExprKind::If(cond, then_expr, opt_else_expr) => {
self.check_then_else(cond, then_expr, opt_else_expr, expr.span, expected)
}
ExprKind::DropTemps(ref e) => self.check_expr_with_expectation(e, expected),
ExprKind::Array(ref args) => self.check_expr_array(args, expected, expr),
ExprKind::ConstBlock(ref anon_const) => self.to_const(anon_const).ty,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct Map<I, F> {
iter: I,
f: F,
}

impl<I, F> Map<I, F> {
pub(in crate::iter) fn new(iter: I, f: F) -> Map<I, F> {
Map { iter, f }
Expand Down
17 changes: 6 additions & 11 deletions library/test/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::time::TestTimeOptions;
#[derive(Debug)]
pub struct TestOpts {
pub list: bool,
pub filter: Option<String>,
pub filters: Vec<String>,
pub filter_exact: bool,
pub force_run_in_process: bool,
pub exclude_should_panic: bool,
Expand Down Expand Up @@ -148,12 +148,13 @@ fn optgroups() -> getopts::Options {
}

fn usage(binary: &str, options: &getopts::Options) {
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
let message = format!("Usage: {} [OPTIONS] [FILTERS...]", binary);
println!(
r#"{usage}
The FILTER string is tested against the name of all tests, and only those
tests whose names contain the filter are run.
tests whose names contain the filter are run. Multiple filter strings may
be passed, which will run all tests matching any of the filters.
By default, all tests are run in parallel. This can be altered with the
--test-threads flag or the RUST_TEST_THREADS environment variable when running
Expand Down Expand Up @@ -243,7 +244,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {

let logfile = get_log_file(&matches)?;
let run_ignored = get_run_ignored(&matches, include_ignored)?;
let filter = get_filter(&matches)?;
let filters = matches.free.clone();
let nocapture = get_nocapture(&matches)?;
let test_threads = get_test_threads(&matches)?;
let color = get_color_config(&matches)?;
Expand All @@ -253,7 +254,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {

let test_opts = TestOpts {
list,
filter,
filters,
filter_exact: exact,
force_run_in_process,
exclude_should_panic,
Expand Down Expand Up @@ -397,12 +398,6 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart
Ok(run_ignored)
}

fn get_filter(matches: &getopts::Matches) -> OptPartRes<Option<String>> {
let filter = if !matches.free.is_empty() { Some(matches.free[0].clone()) } else { None };

Ok(filter)
}

fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes<bool> {
let mut allow_unstable = false;

Expand Down
4 changes: 2 additions & 2 deletions library/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
};

// Remove tests that don't match the test filter
if let Some(ref filter) = opts.filter {
filtered.retain(|test| matches_filter(test, filter));
if !opts.filters.is_empty() {
filtered.retain(|test| opts.filters.iter().any(|filter| matches_filter(test, filter)));
}

// Skip tests that match any of the skip filters
Expand Down
35 changes: 26 additions & 9 deletions library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl TestOpts {
fn new() -> TestOpts {
TestOpts {
list: false,
filter: None,
filters: vec![],
filter_exact: false,
force_run_in_process: false,
exclude_should_panic: false,
Expand Down Expand Up @@ -473,43 +473,60 @@ pub fn exact_filter_match() {
}

let substr =
filter_tests(&TestOpts { filter: Some("base".into()), ..TestOpts::new() }, tests());
filter_tests(&TestOpts { filters: vec!["base".into()], ..TestOpts::new() }, tests());
assert_eq!(substr.len(), 4);

let substr = filter_tests(&TestOpts { filter: Some("bas".into()), ..TestOpts::new() }, tests());
let substr =
filter_tests(&TestOpts { filters: vec!["bas".into()], ..TestOpts::new() }, tests());
assert_eq!(substr.len(), 4);

let substr =
filter_tests(&TestOpts { filter: Some("::test".into()), ..TestOpts::new() }, tests());
filter_tests(&TestOpts { filters: vec!["::test".into()], ..TestOpts::new() }, tests());
assert_eq!(substr.len(), 3);

let substr =
filter_tests(&TestOpts { filter: Some("base::test".into()), ..TestOpts::new() }, tests());
filter_tests(&TestOpts { filters: vec!["base::test".into()], ..TestOpts::new() }, tests());
assert_eq!(substr.len(), 3);

let substr = filter_tests(
&TestOpts { filters: vec!["test1".into(), "test2".into()], ..TestOpts::new() },
tests(),
);
assert_eq!(substr.len(), 2);

let exact = filter_tests(
&TestOpts { filter: Some("base".into()), filter_exact: true, ..TestOpts::new() },
&TestOpts { filters: vec!["base".into()], filter_exact: true, ..TestOpts::new() },
tests(),
);
assert_eq!(exact.len(), 1);

let exact = filter_tests(
&TestOpts { filter: Some("bas".into()), filter_exact: true, ..TestOpts::new() },
&TestOpts { filters: vec!["bas".into()], filter_exact: true, ..TestOpts::new() },
tests(),
);
assert_eq!(exact.len(), 0);

let exact = filter_tests(
&TestOpts { filter: Some("::test".into()), filter_exact: true, ..TestOpts::new() },
&TestOpts { filters: vec!["::test".into()], filter_exact: true, ..TestOpts::new() },
tests(),
);
assert_eq!(exact.len(), 0);

let exact = filter_tests(
&TestOpts { filter: Some("base::test".into()), filter_exact: true, ..TestOpts::new() },
&TestOpts { filters: vec!["base::test".into()], filter_exact: true, ..TestOpts::new() },
tests(),
);
assert_eq!(exact.len(), 1);

let exact = filter_tests(
&TestOpts {
filters: vec!["base".into(), "base::test".into()],
filter_exact: true,
..TestOpts::new()
},
tests(),
);
assert_eq!(exact.len(), 2);
}

#[test]
Expand Down
7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/treat-err-as-bug/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/run-make-fulldeps/treat-err-as-bug/err.rs

This file was deleted.

13 changes: 13 additions & 0 deletions src/test/ui/const-ptr/ptr_to_usize_cast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(const_raw_ptr_to_usize_cast)]

fn main() {
const OK: usize = unsafe { 0 as *const i32 as usize };

const _ERROR: usize = unsafe { &0 as *const i32 as usize };
//~^ ERROR [const_err]
//~| NOTE cannot cast pointer to integer because it was not created by cast from integer
//~| NOTE
//~| NOTE `#[deny(const_err)]` on by default
//~| WARN this was previously accepted by the compiler but is being phased out
//~| NOTE see issue #71800
}
14 changes: 14 additions & 0 deletions src/test/ui/const-ptr/ptr_to_usize_cast.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: any use of this value will cause an error
--> $DIR/ptr_to_usize_cast.rs:6:36
|
LL | const _ERROR: usize = unsafe { &0 as *const i32 as usize };
| -------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| cannot cast pointer to integer because it was not created by cast from integer
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/const_raw_ptr_ops2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: any use of this value will cause an error
LL | const Y2: usize = unsafe { &1 as *const i32 as usize + 1 };
| ---------------------------^^^^^^^^^^^^^^^^^^^^^^^^^-------
| |
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
| cannot cast pointer to integer because it was not created by cast from integer
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/issue-51559.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: any use of this value will cause an error
LL | pub const FOO: usize = unsafe { BAR as usize };
| --------------------------------^^^^^^^^^^^^---
| |
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
| cannot cast pointer to integer because it was not created by cast from integer
|
= note: `#[deny(const_err)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/issue-52432.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
--> $DIR/issue-52432.rs:7:10
|
LL | [(); &(static || {}) as *const _ as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot cast pointer to integer because it was not created by cast from integer

error: aborting due to 4 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/miri_unleashed/ptr_arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static INT_PTR_ARITH: () = unsafe {
let x: usize = std::mem::transmute(&0);
let _v = x + 0;
//~^ ERROR could not evaluate static initializer
//~| NOTE pointer-to-integer cast
//~| NOTE cannot cast pointer to integer
};

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/consts/miri_unleashed/ptr_arith.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0080]: could not evaluate static initializer
--> $DIR/ptr_arith.rs:16:14
|
LL | let _v = x + 0;
| ^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
| ^^^^^ cannot cast pointer to integer because it was not created by cast from integer

warning: skipping const checks
|
Expand Down
Loading

0 comments on commit 0fc6756

Please sign in to comment.