File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 1- use rustc_errors:: { Applicability , DiagnosticBuilder } ;
2-
1+ use crate :: panic:: use_panic_2021;
32use rustc_ast:: ptr:: P ;
43use rustc_ast:: token;
54use rustc_ast:: tokenstream:: { DelimSpan , TokenStream } ;
65use rustc_ast:: { self as ast, * } ;
76use rustc_ast_pretty:: pprust;
7+ use rustc_errors:: { Applicability , DiagnosticBuilder } ;
88use rustc_expand:: base:: * ;
99use rustc_parse:: parser:: Parser ;
1010use rustc_span:: symbol:: { sym, Ident , Symbol } ;
@@ -28,7 +28,7 @@ pub fn expand_assert<'cx>(
2828 let sp = cx. with_call_site_ctxt ( span) ;
2929
3030 let panic_call = if let Some ( tokens) = custom_message {
31- let path = if span . rust_2021 ( ) {
31+ let path = if use_panic_2021 ( span ) {
3232 // On edition 2021, we always call `$crate::panic::panic_2021!()`.
3333 Path {
3434 span : sp,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use rustc_ast::ptr::P;
22use rustc_ast:: tokenstream:: { DelimSpan , TokenStream } ;
33use rustc_ast:: * ;
44use rustc_expand:: base:: * ;
5+ use rustc_span:: edition:: Edition ;
56use rustc_span:: symbol:: sym;
67use rustc_span:: Span ;
78
@@ -19,7 +20,7 @@ pub fn expand_panic<'cx>(
1920 sp : Span ,
2021 tts : TokenStream ,
2122) -> Box < dyn MacResult + ' cx > {
22- let panic = if sp . rust_2021 ( ) { sym:: panic_2021 } else { sym:: panic_2015 } ;
23+ let panic = if use_panic_2021 ( sp ) { sym:: panic_2021 } else { sym:: panic_2015 } ;
2324
2425 let sp = cx. with_call_site_ctxt ( sp) ;
2526
@@ -46,3 +47,19 @@ pub fn expand_panic<'cx>(
4647 ) ,
4748 )
4849}
50+
51+ pub fn use_panic_2021 ( mut span : Span ) -> bool {
52+ // To determine the editon, we check the first span up the expansion
53+ // stack that does not have #[allow_internal_unstable(edition_panic)].
54+ // (To avoid using the edition of e.g. the assert!() or debug_assert!() definition.)
55+ loop {
56+ let expn = span. ctxt ( ) . outer_expn_data ( ) ;
57+ if let Some ( features) = expn. allow_internal_unstable {
58+ if features. iter ( ) . any ( |& f| f == sym:: edition_panic) {
59+ span = expn. call_site ;
60+ continue ;
61+ }
62+ }
63+ break expn. edition >= Edition :: Edition2021 ;
64+ }
65+ }
Original file line number Diff line number Diff line change @@ -558,6 +558,7 @@ symbols! {
558558 dyn_metadata,
559559 dyn_trait,
560560 edition_macro_pats,
561+ edition_panic,
561562 eh_catch_typeinfo,
562563 eh_personality,
563564 emit_enum,
Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ pub macro assert_matches {
210210 #[ macro_export]
211211#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
212212#[ rustc_diagnostic_item = "debug_assert_macro" ]
213+ #[ allow_internal_unstable ( edition_panic) ]
213214macro_rules! debug_assert {
214215 ( $( $arg: tt) * ) => ( if $crate:: cfg!( debug_assertions) { $crate:: assert!( $( $arg) * ) ; } )
215216}
You can’t perform that action at this time.
0 commit comments