diff options
| author | bors <bors@rust-lang.org> | 2021-07-09 15:34:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-09 15:34:16 +0000 |
| commit | 619c27a53959e2d79aadb01cba5b2c49756df771 (patch) | |
| tree | 23294d08e959d509fc5273b619367a00a25530d6 /compiler | |
| parent | e916b7cb7708e470be8d0134bdf39479051a5c44 (diff) | |
| parent | 2152c145d3a59a8a47bf370198b11410e329a71c (diff) | |
| download | rust-619c27a53959e2d79aadb01cba5b2c49756df771.tar.gz rust-619c27a53959e2d79aadb01cba5b2c49756df771.zip | |
Auto merge of #87003 - m-ou-se:rollup-x7mhv3v, r=m-ou-se
Rollup of 5 pull requests Successful merges: - #86855 (Fix comments about unique borrows) - #86881 (Inline implementation of lookup_line) - #86937 (Change linked tracking issue for more_qualified_paths) - #86994 (Update the comment on `lower_expr_try`) - #87000 (Use #[track_caller] in const panic diagnostics.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/closure.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/interpret/eval_context.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_span/src/tests.rs | 21 |
7 files changed, 38 insertions, 37 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index b9dcd083c0b..eb8e92f07ea 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1559,13 +1559,14 @@ impl<'hir> LoweringContext<'_, 'hir> { /// Desugar `ExprKind::Try` from: `<expr>?` into: /// ```rust - /// match Try::into_result(<expr>) { - /// Ok(val) => #[allow(unreachable_code)] val, - /// Err(err) => #[allow(unreachable_code)] - /// // If there is an enclosing `try {...}`: - /// break 'catch_target Try::from_error(From::from(err)), - /// // Otherwise: - /// return Try::from_error(From::from(err)), + /// match Try::branch(<expr>) { + /// ControlFlow::Continue(val) => #[allow(unreachable_code)] val,, + /// ControlFlow::Break(residual) => + /// #[allow(unreachable_code)] + /// // If there is an enclosing `try {...}`: + /// break 'catch_target Try::from_residual(residual), + /// // Otherwise: + /// return Try::from_residual(residual), /// } /// ``` fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind<'hir> { diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index f045a75cdc8..d01804aca88 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -685,7 +685,7 @@ declare_features! ( (incomplete, unnamed_fields, "1.53.0", Some(49804), None), /// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns. - (active, more_qualified_paths, "1.54.0", Some(80080), None), + (active, more_qualified_paths, "1.54.0", Some(86935), None), // ------------------------------------------------------------------------- // feature-group-end: actual feature gates diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 672686410f9..ed813c054c2 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -651,7 +651,7 @@ pub enum BorrowKind { /// in an aliasable location. To solve, you'd have to translate with /// an `&mut` borrow: /// - /// struct Env { x: & &mut isize } + /// struct Env { x: &mut &mut isize } /// let x: &mut isize = ...; /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x /// fn fn_ptr(env: &mut Env) { **env.x += 5; } diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 0706a057dd0..b0156daf17e 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -347,7 +347,7 @@ pub enum BorrowKind { /// an `&mut` borrow: /// /// ``` - /// struct Env { x: & &mut isize } + /// struct Env { x: &mut &mut isize } /// let x: &mut isize = ...; /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x /// fn fn_ptr(env: &mut Env) { **env.x += 5; } diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 227abeb7e7c..648a7abfdc7 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -398,7 +398,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { #[inline(always)] pub fn cur_span(&self) -> Span { - self.stack().last().map_or(self.tcx.span, |f| f.current_span()) + self.stack() + .iter() + .rev() + .find(|frame| !frame.instance.def.requires_caller_location(*self.tcx)) + .map_or(self.tcx.span, |f| f.current_span()) } #[inline(always)] @@ -927,7 +931,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { #[must_use] pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> { let mut frames = Vec::new(); - for frame in self.stack().iter().rev() { + for frame in self + .stack() + .iter() + .rev() + .skip_while(|frame| frame.instance.def.requires_caller_location(*self.tcx)) + { let lint_root = frame.current_source_info().and_then(|source_info| { match &frame.body.source_scopes[source_info.scope].local_data { mir::ClearCrossCrate::Set(data) => Some(data.lint_root), diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 3ddb10d2a06..6265470e625 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1552,13 +1552,11 @@ impl SourceFile { /// number. If the source_file is empty or the position is located before the /// first line, `None` is returned. pub fn lookup_line(&self, pos: BytePos) -> Option<usize> { - if self.lines.is_empty() { - return None; + match self.lines.binary_search(&pos) { + Ok(idx) => Some(idx), + Err(0) => None, + Err(idx) => Some(idx - 1), } - - let line_index = lookup_line(&self.lines[..], pos); - assert!(line_index < self.lines.len() as isize); - if line_index >= 0 { Some(line_index as usize) } else { None } } pub fn line_bounds(&self, line_index: usize) -> Range<BytePos> { @@ -1957,16 +1955,6 @@ impl InnerSpan { } } -// Given a slice of line start positions and a position, returns the index of -// the line the position is on. Returns -1 if the position is located before -// the first line. -fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize { - match lines.binary_search(&pos) { - Ok(line) => line as isize, - Err(line) => line as isize - 1, - } -} - /// Requirements for a `StableHashingContext` to be used in this crate. /// /// This is a hack to allow using the [`HashStable_Generic`] derive macro diff --git a/compiler/rustc_span/src/tests.rs b/compiler/rustc_span/src/tests.rs index 3c8eb8bcd31..11edcacc0d4 100644 --- a/compiler/rustc_span/src/tests.rs +++ b/compiler/rustc_span/src/tests.rs @@ -2,18 +2,21 @@ use super::*; #[test] fn test_lookup_line() { - let lines = &[BytePos(3), BytePos(17), BytePos(28)]; + let source = "abcdefghijklm\nabcdefghij\n...".to_owned(); + let sf = + SourceFile::new(FileName::Anon(0), source, BytePos(3), SourceFileHashAlgorithm::Sha256); + assert_eq!(sf.lines.as_slice(), &[BytePos(3), BytePos(17), BytePos(28)]); - assert_eq!(lookup_line(lines, BytePos(0)), -1); - assert_eq!(lookup_line(lines, BytePos(3)), 0); - assert_eq!(lookup_line(lines, BytePos(4)), 0); + assert_eq!(sf.lookup_line(BytePos(0)), None); + assert_eq!(sf.lookup_line(BytePos(3)), Some(0)); + assert_eq!(sf.lookup_line(BytePos(4)), Some(0)); - assert_eq!(lookup_line(lines, BytePos(16)), 0); - assert_eq!(lookup_line(lines, BytePos(17)), 1); - assert_eq!(lookup_line(lines, BytePos(18)), 1); + assert_eq!(sf.lookup_line(BytePos(16)), Some(0)); + assert_eq!(sf.lookup_line(BytePos(17)), Some(1)); + assert_eq!(sf.lookup_line(BytePos(18)), Some(1)); - assert_eq!(lookup_line(lines, BytePos(28)), 2); - assert_eq!(lookup_line(lines, BytePos(29)), 2); + assert_eq!(sf.lookup_line(BytePos(28)), Some(2)); + assert_eq!(sf.lookup_line(BytePos(29)), Some(2)); } #[test] |
