-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkov
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See #80162 and rust-lang/rfcs#3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: c5273bd That change is blocked on figuring out what to do with #80846 first.
- Loading branch information
Showing
26 changed files
with
592 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use rustc_ast::ptr::P; | ||
use rustc_ast::tokenstream::{DelimSpan, TokenStream}; | ||
use rustc_ast::*; | ||
use rustc_expand::base::*; | ||
use rustc_span::symbol::sym; | ||
use rustc_span::Span; | ||
|
||
// This expands to either | ||
// - `$crate::panic::panic_2015!(...)` or | ||
// - `$crate::panic::panic_2021!(...)` | ||
// depending on the edition. | ||
// | ||
// This is used for both std::panic!() and core::panic!(). | ||
// | ||
// `$crate` will refer to either the `std` or `core` crate depending on which | ||
// one we're expanding from. | ||
pub fn expand_panic<'cx>( | ||
cx: &'cx mut ExtCtxt<'_>, | ||
sp: Span, | ||
tts: TokenStream, | ||
) -> Box<dyn MacResult + 'cx> { | ||
let panic = if sp.rust_2021() { sym::panic_2021 } else { sym::panic_2015 }; | ||
|
||
let sp = cx.with_call_site_ctxt(sp); | ||
|
||
MacEager::expr( | ||
cx.expr( | ||
sp, | ||
ExprKind::MacCall(MacCall { | ||
path: Path { | ||
span: sp, | ||
segments: cx | ||
.std_path(&[sym::panic, panic]) | ||
.into_iter() | ||
.map(|ident| PathSegment::from_ident(ident)) | ||
.collect(), | ||
tokens: None, | ||
}, | ||
args: P(MacArgs::Delimited( | ||
DelimSpan::from_single(sp), | ||
MacDelimiter::Parenthesis, | ||
tts, | ||
)), | ||
prior_type_ascription: None, | ||
}), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.