Skip to content

Commit 0fc6756

Browse files
committed
Auto merge of rust-lang#81889 - m-ou-se:rollup-k63log3, r=m-ou-se
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
2 parents 921ec4b + 9d1e8fe commit 0fc6756

File tree

35 files changed

+203
-71
lines changed

35 files changed

+203
-71
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
572572

573573
let tcx = self.tcx;
574574

575+
// Encode MIR.
576+
i = self.position();
577+
self.encode_mir();
578+
let mir_bytes = self.position() - i;
579+
575580
// Encode the items.
576581
i = self.position();
577582
self.encode_def_ids();
578-
self.encode_mir();
579583
self.encode_info_for_items();
580584
let item_bytes = self.position() - i;
581585

@@ -700,6 +704,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
700704
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
701705
println!(" def-path table bytes: {}", def_path_table_bytes);
702706
println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
707+
println!(" mir bytes: {}", mir_bytes);
703708
println!(" item bytes: {}", item_bytes);
704709
println!(" table bytes: {}", tables_bytes);
705710
println!(" hygiene bytes: {}", hygiene_bytes);

compiler/rustc_mir/src/const_eval/error.rs

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::interpret::{
1616
#[derive(Clone, Debug)]
1717
pub enum ConstEvalErrKind {
1818
NeedsRfc(String),
19+
PtrToIntCast,
1920
ConstAccessesStatic,
2021
ModifiedGlobal,
2122
AssertFailure(AssertKind<ConstInt>),
@@ -39,6 +40,12 @@ impl fmt::Display for ConstEvalErrKind {
3940
NeedsRfc(ref msg) => {
4041
write!(f, "\"{}\" needs an rfc before being allowed inside constants", msg)
4142
}
43+
PtrToIntCast => {
44+
write!(
45+
f,
46+
"cannot cast pointer to integer because it was not created by cast from integer"
47+
)
48+
}
4249
ConstAccessesStatic => write!(f, "constant accesses static"),
4350
ModifiedGlobal => {
4451
write!(f, "modifying a static's initial value from another static's initializer")

compiler/rustc_mir/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
352352
}
353353

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

358358
fn binary_ptr_op(

compiler/rustc_parse_format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ fn find_skips_from_snippet(
730730
str_style: Option<usize>,
731731
) -> (Vec<usize>, bool) {
732732
let snippet = match snippet {
733-
Some(ref s) if s.starts_with('"') || s.starts_with("r#") => s,
733+
Some(ref s) if s.starts_with('"') || s.starts_with("r\"") || s.starts_with("r#") => s,
734734
_ => return (vec![], false),
735735
};
736736

compiler/rustc_span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(nll)]
2323
#![feature(min_specialization)]
2424
#![feature(option_expect_none)]
25+
#![feature(str_split_once)]
2526

2627
#[macro_use]
2728
extern crate rustc_macros;

compiler/rustc_span/src/source_map.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl SourceMap {
539539

540540
pub fn is_line_before_span_empty(&self, sp: Span) -> bool {
541541
match self.span_to_prev_source(sp) {
542-
Ok(s) => s.split('\n').last().map_or(false, |l| l.trim_start().is_empty()),
542+
Ok(s) => s.rsplit_once('\n').unwrap_or(("", &s)).1.trim_start().is_empty(),
543543
Err(_) => false,
544544
}
545545
}
@@ -632,10 +632,11 @@ impl SourceMap {
632632
pub fn span_to_margin(&self, sp: Span) -> Option<usize> {
633633
match self.span_to_prev_source(sp) {
634634
Err(_) => None,
635-
Ok(source) => source
636-
.split('\n')
637-
.last()
638-
.map(|last_line| last_line.len() - last_line.trim_start().len()),
635+
Ok(source) => {
636+
let last_line = source.rsplit_once('\n').unwrap_or(("", &source)).1;
637+
638+
Some(last_line.len() - last_line.trim_start().len())
639+
}
639640
}
640641
}
641642

@@ -651,7 +652,7 @@ impl SourceMap {
651652
pub fn span_extend_to_prev_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
652653
if let Ok(prev_source) = self.span_to_prev_source(sp) {
653654
let prev_source = prev_source.rsplit(c).next().unwrap_or("");
654-
if !prev_source.is_empty() && (!prev_source.contains('\n') || accept_newlines) {
655+
if !prev_source.is_empty() && (accept_newlines || !prev_source.contains('\n')) {
655656
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
656657
}
657658
}
@@ -673,7 +674,7 @@ impl SourceMap {
673674
let prev_source = prev_source.rsplit(&pat).next().unwrap_or("").trim_start();
674675
if prev_source.is_empty() && sp.lo().0 != 0 {
675676
return sp.with_lo(BytePos(sp.lo().0 - 1));
676-
} else if !prev_source.contains('\n') || accept_newlines {
677+
} else if accept_newlines || !prev_source.contains('\n') {
677678
return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32));
678679
}
679680
}
@@ -693,7 +694,7 @@ impl SourceMap {
693694
pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
694695
if let Ok(next_source) = self.span_to_next_source(sp) {
695696
let next_source = next_source.split(c).next().unwrap_or("");
696-
if !next_source.is_empty() && (!next_source.contains('\n') || accept_newlines) {
697+
if !next_source.is_empty() && (accept_newlines || !next_source.contains('\n')) {
697698
return sp.with_hi(BytePos(sp.hi().0 + next_source.len() as u32));
698699
}
699700
}

compiler/rustc_typeck/src/check/expr.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
285285
self.check_expr_eq_type(&e, ty);
286286
ty
287287
}
288-
ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => self.check_then_else(
289-
&cond,
290-
then_expr,
291-
opt_else_expr.as_ref().map(|e| &**e),
292-
expr.span,
293-
expected,
294-
),
288+
ExprKind::If(cond, then_expr, opt_else_expr) => {
289+
self.check_then_else(cond, then_expr, opt_else_expr, expr.span, expected)
290+
}
295291
ExprKind::DropTemps(ref e) => self.check_expr_with_expectation(e, expected),
296292
ExprKind::Array(ref args) => self.check_expr_array(args, expected, expr),
297293
ExprKind::ConstBlock(ref anon_const) => self.to_const(anon_const).ty,

library/core/src/iter/adapters/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub struct Map<I, F> {
6060
iter: I,
6161
f: F,
6262
}
63+
6364
impl<I, F> Map<I, F> {
6465
pub(in crate::iter) fn new(iter: I, f: F) -> Map<I, F> {
6566
Map { iter, f }

library/test/src/cli.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::time::TestTimeOptions;
1010
#[derive(Debug)]
1111
pub struct TestOpts {
1212
pub list: bool,
13-
pub filter: Option<String>,
13+
pub filters: Vec<String>,
1414
pub filter_exact: bool,
1515
pub force_run_in_process: bool,
1616
pub exclude_should_panic: bool,
@@ -148,12 +148,13 @@ fn optgroups() -> getopts::Options {
148148
}
149149

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

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

254255
let test_opts = TestOpts {
255256
list,
256-
filter,
257+
filters,
257258
filter_exact: exact,
258259
force_run_in_process,
259260
exclude_should_panic,
@@ -397,12 +398,6 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart
397398
Ok(run_ignored)
398399
}
399400

400-
fn get_filter(matches: &getopts::Matches) -> OptPartRes<Option<String>> {
401-
let filter = if !matches.free.is_empty() { Some(matches.free[0].clone()) } else { None };
402-
403-
Ok(filter)
404-
}
405-
406401
fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes<bool> {
407402
let mut allow_unstable = false;
408403

library/test/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
396396
};
397397

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

403403
// Skip tests that match any of the skip filters

library/test/src/tests.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl TestOpts {
3434
fn new() -> TestOpts {
3535
TestOpts {
3636
list: false,
37-
filter: None,
37+
filters: vec![],
3838
filter_exact: false,
3939
force_run_in_process: false,
4040
exclude_should_panic: false,
@@ -473,43 +473,60 @@ pub fn exact_filter_match() {
473473
}
474474

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

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

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

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

491+
let substr = filter_tests(
492+
&TestOpts { filters: vec!["test1".into(), "test2".into()], ..TestOpts::new() },
493+
tests(),
494+
);
495+
assert_eq!(substr.len(), 2);
496+
490497
let exact = filter_tests(
491-
&TestOpts { filter: Some("base".into()), filter_exact: true, ..TestOpts::new() },
498+
&TestOpts { filters: vec!["base".into()], filter_exact: true, ..TestOpts::new() },
492499
tests(),
493500
);
494501
assert_eq!(exact.len(), 1);
495502

496503
let exact = filter_tests(
497-
&TestOpts { filter: Some("bas".into()), filter_exact: true, ..TestOpts::new() },
504+
&TestOpts { filters: vec!["bas".into()], filter_exact: true, ..TestOpts::new() },
498505
tests(),
499506
);
500507
assert_eq!(exact.len(), 0);
501508

502509
let exact = filter_tests(
503-
&TestOpts { filter: Some("::test".into()), filter_exact: true, ..TestOpts::new() },
510+
&TestOpts { filters: vec!["::test".into()], filter_exact: true, ..TestOpts::new() },
504511
tests(),
505512
);
506513
assert_eq!(exact.len(), 0);
507514

508515
let exact = filter_tests(
509-
&TestOpts { filter: Some("base::test".into()), filter_exact: true, ..TestOpts::new() },
516+
&TestOpts { filters: vec!["base::test".into()], filter_exact: true, ..TestOpts::new() },
510517
tests(),
511518
);
512519
assert_eq!(exact.len(), 1);
520+
521+
let exact = filter_tests(
522+
&TestOpts {
523+
filters: vec!["base".into(), "base::test".into()],
524+
filter_exact: true,
525+
..TestOpts::new()
526+
},
527+
tests(),
528+
);
529+
assert_eq!(exact.len(), 2);
513530
}
514531

515532
#[test]

src/test/run-make-fulldeps/treat-err-as-bug/Makefile

-7
This file was deleted.

src/test/run-make-fulldeps/treat-err-as-bug/delay_span_bug.rs

-4
This file was deleted.

src/test/run-make-fulldeps/treat-err-as-bug/err.rs

-3
This file was deleted.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(const_raw_ptr_to_usize_cast)]
2+
3+
fn main() {
4+
const OK: usize = unsafe { 0 as *const i32 as usize };
5+
6+
const _ERROR: usize = unsafe { &0 as *const i32 as usize };
7+
//~^ ERROR [const_err]
8+
//~| NOTE cannot cast pointer to integer because it was not created by cast from integer
9+
//~| NOTE
10+
//~| NOTE `#[deny(const_err)]` on by default
11+
//~| WARN this was previously accepted by the compiler but is being phased out
12+
//~| NOTE see issue #71800
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: any use of this value will cause an error
2+
--> $DIR/ptr_to_usize_cast.rs:6:36
3+
|
4+
LL | const _ERROR: usize = unsafe { &0 as *const i32 as usize };
5+
| -------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^---
6+
| |
7+
| cannot cast pointer to integer because it was not created by cast from integer
8+
|
9+
= note: `#[deny(const_err)]` on by default
10+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
12+
13+
error: aborting due to previous error
14+

src/test/ui/consts/const-eval/const_raw_ptr_ops2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
44
LL | const Y2: usize = unsafe { &1 as *const i32 as usize + 1 };
55
| ---------------------------^^^^^^^^^^^^^^^^^^^^^^^^^-------
66
| |
7-
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
7+
| cannot cast pointer to integer because it was not created by cast from integer
88
|
99
= note: `#[deny(const_err)]` on by default
1010
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

src/test/ui/consts/issue-51559.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: any use of this value will cause an error
44
LL | pub const FOO: usize = unsafe { BAR as usize };
55
| --------------------------------^^^^^^^^^^^^---
66
| |
7-
| "pointer-to-integer cast" needs an rfc before being allowed inside constants
7+
| cannot cast pointer to integer because it was not created by cast from integer
88
|
99
= note: `#[deny(const_err)]` on by default
1010
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

src/test/ui/consts/issue-52432.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
2020
--> $DIR/issue-52432.rs:7:10
2121
|
2222
LL | [(); &(static || {}) as *const _ as usize];
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot cast pointer to integer because it was not created by cast from integer
2424

2525
error: aborting due to 4 previous errors
2626

src/test/ui/consts/miri_unleashed/ptr_arith.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static INT_PTR_ARITH: () = unsafe {
1515
let x: usize = std::mem::transmute(&0);
1616
let _v = x + 0;
1717
//~^ ERROR could not evaluate static initializer
18-
//~| NOTE pointer-to-integer cast
18+
//~| NOTE cannot cast pointer to integer
1919
};
2020

2121
fn main() {}

src/test/ui/consts/miri_unleashed/ptr_arith.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0080]: could not evaluate static initializer
88
--> $DIR/ptr_arith.rs:16:14
99
|
1010
LL | let _v = x + 0;
11-
| ^^^^^ "pointer-to-integer cast" needs an rfc before being allowed inside constants
11+
| ^^^^^ cannot cast pointer to integer because it was not created by cast from integer
1212

1313
warning: skipping const checks
1414
|

0 commit comments

Comments
 (0)