diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-07-09 16:20:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-09 16:20:36 +0200 |
| commit | 2152c145d3a59a8a47bf370198b11410e329a71c (patch) | |
| tree | f323430d928a70862f2133445bf052030b3d886f /compiler | |
| parent | 98f35589f73e9f2a024928ed0ebe2151613630f8 (diff) | |
| parent | 0a4b53f57dc36e3f997a72161a0eb6426122e6bd (diff) | |
| download | rust-2152c145d3a59a8a47bf370198b11410e329a71c.tar.gz rust-2152c145d3a59a8a47bf370198b11410e329a71c.zip | |
Rollup merge of #87000 - m-ou-se:const-panic-track-caller, r=oli-obk
Use #[track_caller] in const panic diagnostics. This change stops const panic diagnostics from reporting inside #[track_caller] functions by skipping over them.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir/src/interpret/eval_context.rs | 13 |
1 files changed, 11 insertions, 2 deletions
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), |
