diff options
| author | bors <bors@rust-lang.org> | 2021-02-08 20:52:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-08 20:52:54 +0000 |
| commit | 0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a (patch) | |
| tree | b772cfec476469c0839bdcc49ef177f0a5229ec5 /compiler | |
| parent | 921ec4b3fca17cc777766c240038d7d50ba98e0d (diff) | |
| parent | 9d1e8fe045d8512309fa3303d188ccbf06b9542f (diff) | |
| download | rust-0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a.tar.gz rust-0fc6756b42e0556cc2e18079f5fc6b4d58f4e81a.zip | |
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
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/error.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/const_eval/machine.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse_format/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/expr.rs | 10 |
7 files changed, 28 insertions, 18 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index dd6a6fe6248..14ca51008be 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -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; @@ -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); diff --git a/compiler/rustc_mir/src/const_eval/error.rs b/compiler/rustc_mir/src/const_eval/error.rs index 0e610e37552..88af9391cad 100644 --- a/compiler/rustc_mir/src/const_eval/error.rs +++ b/compiler/rustc_mir/src/const_eval/error.rs @@ -16,6 +16,7 @@ use crate::interpret::{ #[derive(Clone, Debug)] pub enum ConstEvalErrKind { NeedsRfc(String), + PtrToIntCast, ConstAccessesStatic, ModifiedGlobal, AssertFailure(AssertKind<ConstInt>), @@ -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") diff --git a/compiler/rustc_mir/src/const_eval/machine.rs b/compiler/rustc_mir/src/const_eval/machine.rs index 49126cfec6b..f6b950c08c7 100644 --- a/compiler/rustc_mir/src/const_eval/machine.rs +++ b/compiler/rustc_mir/src/const_eval/machine.rs @@ -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( diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index f150f7a41ae..92d974690b5 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -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), }; diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index f3d876a5770..79c5c7f110c 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -22,6 +22,7 @@ #![feature(nll)] #![feature(min_specialization)] #![feature(option_expect_none)] +#![feature(str_split_once)] #[macro_use] extern crate rustc_macros; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 2b429372dcf..298c995b166 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -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, } } @@ -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()) + } } } @@ -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)); } } @@ -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)); } } @@ -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)); } } diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 1a11aad1441..9692b0524e7 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -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, |
