mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Implement the new built-in unreachable!
macro
This commit is contained in:
parent
e1541bda94
commit
aec4bcf3f2
2 changed files with 21 additions and 0 deletions
|
@ -114,6 +114,7 @@ register_builtin! {
|
||||||
(cfg, Cfg) => cfg_expand,
|
(cfg, Cfg) => cfg_expand,
|
||||||
(core_panic, CorePanic) => panic_expand,
|
(core_panic, CorePanic) => panic_expand,
|
||||||
(std_panic, StdPanic) => panic_expand,
|
(std_panic, StdPanic) => panic_expand,
|
||||||
|
(unreachable, Unreachable) => unreachable_expand,
|
||||||
(log_syntax, LogSyntax) => log_syntax_expand,
|
(log_syntax, LogSyntax) => log_syntax_expand,
|
||||||
(trace_macros, TraceMacros) => trace_macros_expand,
|
(trace_macros, TraceMacros) => trace_macros_expand,
|
||||||
|
|
||||||
|
@ -354,6 +355,25 @@ fn panic_expand(
|
||||||
ExpandResult::ok(call)
|
ExpandResult::ok(call)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unreachable_expand(
|
||||||
|
db: &dyn AstDatabase,
|
||||||
|
id: MacroCallId,
|
||||||
|
tt: &tt::Subtree,
|
||||||
|
) -> ExpandResult<tt::Subtree> {
|
||||||
|
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
|
||||||
|
// Expand to a macro call `$crate::panic::unreachable_{edition}`
|
||||||
|
let krate = tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() };
|
||||||
|
let mut call = if db.crate_graph()[loc.krate].edition == Edition::Edition2021 {
|
||||||
|
quote!(#krate::panic::unreachable_2021!)
|
||||||
|
} else {
|
||||||
|
quote!(#krate::panic::unreachable_2015!)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pass the original arguments
|
||||||
|
call.token_trees.push(tt::TokenTree::Subtree(tt.clone()));
|
||||||
|
ExpandResult::ok(call)
|
||||||
|
}
|
||||||
|
|
||||||
fn unquote_str(lit: &tt::Literal) -> Option<String> {
|
fn unquote_str(lit: &tt::Literal) -> Option<String> {
|
||||||
let lit = ast::make::tokens::literal(&lit.to_string());
|
let lit = ast::make::tokens::literal(&lit.to_string());
|
||||||
let token = ast::String::cast(lit)?;
|
let token = ast::String::cast(lit)?;
|
||||||
|
|
|
@ -253,6 +253,7 @@ pub mod known {
|
||||||
std_panic,
|
std_panic,
|
||||||
stringify,
|
stringify,
|
||||||
trace_macros,
|
trace_macros,
|
||||||
|
unreachable,
|
||||||
// Builtin derives
|
// Builtin derives
|
||||||
Copy,
|
Copy,
|
||||||
Clone,
|
Clone,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue