Skip to content

Commit 7096a0a

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
Merge #11554
11554: fix: fix type mismatches with `unreachable!` macro in Rust 1.59 r=jonas-schievink a=jonas-schievink should fix #11551 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents e1541bd + aec4bcf commit 7096a0a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

crates/hir_expand/src/builtin_fn_macro.rs

+20
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ register_builtin! {
114114
(cfg, Cfg) => cfg_expand,
115115
(core_panic, CorePanic) => panic_expand,
116116
(std_panic, StdPanic) => panic_expand,
117+
(unreachable, Unreachable) => unreachable_expand,
117118
(log_syntax, LogSyntax) => log_syntax_expand,
118119
(trace_macros, TraceMacros) => trace_macros_expand,
119120

@@ -354,6 +355,25 @@ fn panic_expand(
354355
ExpandResult::ok(call)
355356
}
356357

358+
fn unreachable_expand(
359+
db: &dyn AstDatabase,
360+
id: MacroCallId,
361+
tt: &tt::Subtree,
362+
) -> ExpandResult<tt::Subtree> {
363+
let loc: MacroCallLoc = db.lookup_intern_macro_call(id);
364+
// Expand to a macro call `$crate::panic::unreachable_{edition}`
365+
let krate = tt::Ident { text: "$crate".into(), id: tt::TokenId::unspecified() };
366+
let mut call = if db.crate_graph()[loc.krate].edition == Edition::Edition2021 {
367+
quote!(#krate::panic::unreachable_2021!)
368+
} else {
369+
quote!(#krate::panic::unreachable_2015!)
370+
};
371+
372+
// Pass the original arguments
373+
call.token_trees.push(tt::TokenTree::Subtree(tt.clone()));
374+
ExpandResult::ok(call)
375+
}
376+
357377
fn unquote_str(lit: &tt::Literal) -> Option<String> {
358378
let lit = ast::make::tokens::literal(&lit.to_string());
359379
let token = ast::String::cast(lit)?;

crates/hir_expand/src/name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ pub mod known {
253253
std_panic,
254254
stringify,
255255
trace_macros,
256+
unreachable,
256257
// Builtin derives
257258
Copy,
258259
Clone,

0 commit comments

Comments
 (0)