diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-25 10:21:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-25 10:21:46 +0100 |
commit | 4afc1b8c34aab2a0a32e549ab977d756a7066b28 (patch) | |
tree | a74c14f9e99375a75ecfa2efb4c2ea0a6544fb46 /crates | |
parent | 8b049ec393230e4b9fea3022a3ebf34e2af5395d (diff) | |
parent | b26a472ccb32a520eb809505a7dc465f8050268f (diff) |
Merge #8983
8983: Fix type mismatch caused by macros r=flodiebold a=flodiebold
MacroStmts should be completely transparent, but it prevented
coercion. (I should maybe give `infer_expr` and `infer_expr_inner`
better names.)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/coercion.rs | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index eab8fac91..79a732106 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -805,7 +805,7 @@ impl<'a> InferenceContext<'a> { | |||
805 | None => self.table.new_float_var(), | 805 | None => self.table.new_float_var(), |
806 | }, | 806 | }, |
807 | }, | 807 | }, |
808 | Expr::MacroStmts { tail } => self.infer_expr(*tail, expected), | 808 | Expr::MacroStmts { tail } => self.infer_expr_inner(*tail, expected), |
809 | }; | 809 | }; |
810 | // use a new type variable if we got unknown here | 810 | // use a new type variable if we got unknown here |
811 | let ty = self.insert_type_vars_shallow(ty); | 811 | let ty = self.insert_type_vars_shallow(ty); |
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 { | |||
912 | "#, | 912 | "#, |
913 | ) | 913 | ) |
914 | } | 914 | } |
915 | |||
916 | #[test] | ||
917 | fn panic_macro() { | ||
918 | check_infer_with_mismatches( | ||
919 | r#" | ||
920 | mod panic { | ||
921 | #[macro_export] | ||
922 | pub macro panic_2015 { | ||
923 | () => ( | ||
924 | $crate::panicking::panic("explicit panic") | ||
925 | ), | ||
926 | } | ||
927 | } | ||
928 | |||
929 | mod panicking { | ||
930 | pub fn panic() -> ! { loop {} } | ||
931 | } | ||
932 | |||
933 | #[rustc_builtin_macro = "core_panic"] | ||
934 | macro_rules! panic { | ||
935 | // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021` | ||
936 | // depending on the edition of the caller. | ||
937 | ($($arg:tt)*) => { | ||
938 | /* compiler built-in */ | ||
939 | }; | ||
940 | } | ||
941 | |||
942 | fn main() { | ||
943 | panic!("internal error: entered unreachable code") | ||
944 | } | ||
945 | "#, | ||
946 | expect![[r#" | ||
947 | 190..201 '{ loop {} }': ! | ||
948 | 192..199 'loop {}': ! | ||
949 | 197..199 '{}': () | ||
950 | !0..24 '$crate...:panic': fn panic() -> ! | ||
951 | !0..42 '$crate...anic")': ! | ||
952 | !0..42 '$crate...anic")': ! | ||
953 | !0..70 '$crate...code")': ! | ||
954 | !25..41 '"expli...panic"': &str | ||
955 | 470..528 '{ ...de") }': () | ||
956 | "#]], | ||
957 | ); | ||
958 | } | ||