diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2021-10-07 20:26:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-07 20:26:15 -0700 |
| commit | 30e068f58b46d42b0e71b5112ceb2193f376ecc2 (patch) | |
| tree | 87a0b8e620cbce6d2a0880a6b84c6bac22cfcb41 /compiler/rustc_builtin_macros/src/panic.rs | |
| parent | aed18018410ea09de7924938e15f877bc3df4a71 (diff) | |
| parent | fcd9fa9099569beba9c85c594ecbb9b07a1a7501 (diff) | |
| download | rust-30e068f58b46d42b0e71b5112ceb2193f376ecc2.tar.gz rust-30e068f58b46d42b0e71b5112ceb2193f376ecc2.zip | |
Rollup merge of #89622 - m-ou-se:debug-assert-2021, r=estebank
Use correct edition for panic in [debug_]assert!(). See https://github.com/rust-lang/rust/issues/88638#issuecomment-915472783
Diffstat (limited to 'compiler/rustc_builtin_macros/src/panic.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/panic.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_builtin_macros/src/panic.rs b/compiler/rustc_builtin_macros/src/panic.rs index 6f5962d435c..54ab596bf3e 100644 --- a/compiler/rustc_builtin_macros/src/panic.rs +++ b/compiler/rustc_builtin_macros/src/panic.rs @@ -2,6 +2,7 @@ use rustc_ast::ptr::P; use rustc_ast::tokenstream::{DelimSpan, TokenStream}; use rustc_ast::*; use rustc_expand::base::*; +use rustc_span::edition::Edition; use rustc_span::symbol::sym; use rustc_span::Span; @@ -19,7 +20,7 @@ pub fn expand_panic<'cx>( sp: Span, tts: TokenStream, ) -> Box<dyn MacResult + 'cx> { - let panic = if sp.rust_2021() { sym::panic_2021 } else { sym::panic_2015 }; + let panic = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 }; let sp = cx.with_call_site_ctxt(sp); @@ -46,3 +47,19 @@ pub fn expand_panic<'cx>( ), ) } + +pub fn use_panic_2021(mut span: Span) -> bool { + // To determine the editon, we check the first span up the expansion + // stack that does not have #[allow_internal_unstable(edition_panic)]. + // (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.) + loop { + let expn = span.ctxt().outer_expn_data(); + if let Some(features) = expn.allow_internal_unstable { + if features.iter().any(|&f| f == sym::edition_panic) { + span = expn.call_site; + continue; + } + } + break expn.edition >= Edition::Edition2021; + } +} |
