Skip to content

Commit 0fc6756

Browse files
committed
Auto merge of #81889 - m-ou-se:rollup-k63log3, r=m-ou-se
Rollup of 9 pull requests Successful merges: - #71531 (Move treat err as bug tests to ui) - #81356 (libtest: allow multiple filters) - #81735 (faster few span methods) - #81779 (improve error message for disallowed ptr-to-int casts in const eval) - #81817 (Add option to emit compiler stderr per bitwidth.) - #81828 (parse_format: treat r" as a literal) - #81840 (fix formatting of std::iter::Map) - #81861 (Show MIR bytes separately in -Zmeta-stats output) - #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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 11 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)