mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
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.)
This commit is contained in:
parent
8b049ec393
commit
b26a472ccb
2 changed files with 45 additions and 1 deletions
|
@ -805,7 +805,7 @@ impl<'a> InferenceContext<'a> {
|
||||||
None => self.table.new_float_var(),
|
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
|
// use a new type variable if we got unknown here
|
||||||
let ty = self.insert_type_vars_shallow(ty);
|
let ty = self.insert_type_vars_shallow(ty);
|
||||||
|
|
|
@ -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") }': ()
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue