File tree 4 files changed +23
-4
lines changed
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;
3
2
use rustc_ast:: ptr:: P ;
4
3
use rustc_ast:: token;
5
4
use rustc_ast:: tokenstream:: { DelimSpan , TokenStream } ;
6
5
use rustc_ast:: { self as ast, * } ;
7
6
use rustc_ast_pretty:: pprust;
7
+ use rustc_errors:: { Applicability , DiagnosticBuilder } ;
8
8
use rustc_expand:: base:: * ;
9
9
use rustc_parse:: parser:: Parser ;
10
10
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
@@ -28,7 +28,7 @@ pub fn expand_assert<'cx>(
28
28
let sp = cx. with_call_site_ctxt ( span) ;
29
29
30
30
let panic_call = if let Some ( tokens) = custom_message {
31
- let path = if span . rust_2021 ( ) {
31
+ let path = if use_panic_2021 ( span ) {
32
32
// On edition 2021, we always call `$crate::panic::panic_2021!()`.
33
33
Path {
34
34
span : sp,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use rustc_ast::ptr::P;
2
2
use rustc_ast:: tokenstream:: { DelimSpan , TokenStream } ;
3
3
use rustc_ast:: * ;
4
4
use rustc_expand:: base:: * ;
5
+ use rustc_span:: edition:: Edition ;
5
6
use rustc_span:: symbol:: sym;
6
7
use rustc_span:: Span ;
7
8
@@ -19,7 +20,7 @@ pub fn expand_panic<'cx>(
19
20
sp : Span ,
20
21
tts : TokenStream ,
21
22
) -> 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 } ;
23
24
24
25
let sp = cx. with_call_site_ctxt ( sp) ;
25
26
@@ -46,3 +47,19 @@ pub fn expand_panic<'cx>(
46
47
) ,
47
48
)
48
49
}
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 @@ -568,6 +568,7 @@ symbols! {
568
568
dyn_metadata,
569
569
dyn_trait,
570
570
edition_macro_pats,
571
+ edition_panic,
571
572
eh_catch_typeinfo,
572
573
eh_personality,
573
574
emit_enum,
Original file line number Diff line number Diff line change @@ -210,6 +210,7 @@ pub macro assert_matches {
210
210
#[ macro_export]
211
211
#[ stable ( feature = "rust1" , since = "1.0.0" ) ]
212
212
#[ rustc_diagnostic_item = "debug_assert_macro" ]
213
+ #[ allow_internal_unstable ( edition_panic) ]
213
214
macro_rules! debug_assert {
214
215
( $( $arg: tt) * ) => ( if $crate:: cfg!( debug_assertions) { $crate:: assert!( $( $arg) * ) ; } )
215
216
}
You can’t perform that action at this time.
0 commit comments