From b26a472ccb32a520eb809505a7dc465f8050268f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 25 May 2021 11:15:02 +0200 Subject: Fix type mismatch caused by macros MacroStmts should be completely transparent, but it prevented coercion. (I should maybe give `infer_expr` and `infer_expr_inner` better names.) --- crates/hir_ty/src/tests/coercion.rs | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index bb568ea37..7e9fc8735 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -912,3 +912,47 @@ fn test() -> i32 { "#, ) } + +#[test] +fn panic_macro() { + check_infer_with_mismatches( + r#" +mod panic { + #[macro_export] + pub macro panic_2015 { + () => ( + $crate::panicking::panic("explicit panic") + ), + } +} + +mod panicking { + pub fn panic() -> ! { loop {} } +} + +#[rustc_builtin_macro = "core_panic"] +macro_rules! panic { + // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021` + // depending on the edition of the caller. + ($($arg:tt)*) => { + /* compiler built-in */ + }; +} + +fn main() { + panic!("internal error: entered unreachable code") +} + "#, + expect![[r#" + 190..201 '{ loop {} }': ! + 192..199 'loop {}': ! + 197..199 '{}': () + !0..24 '$crate...:panic': fn panic() -> ! + !0..42 '$crate...anic")': ! + !0..42 '$crate...anic")': ! + !0..70 '$crate...code")': ! + !25..41 '"expli...panic"': &str + 470..528 '{ ...de") }': () + "#]], + ); +} -- cgit v1.2.3