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 <flodiebold@gmail.com>
This commit is contained in:
bors[bot] 2021-05-25 09:21:46 +00:00 committed by GitHub
commit 4afc1b8c34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View file

@ -805,7 +805,7 @@ impl<'a> InferenceContext<'a> {
None => self.table.new_float_var(),
},
},
Expr::MacroStmts { tail } => self.infer_expr(*tail, expected),
Expr::MacroStmts { tail } => self.infer_expr_inner(*tail, expected),
};
// use a new type variable if we got unknown here
let ty = self.insert_type_vars_shallow(ty);

View file

@ -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") }': ()
"#]],
);
}