mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #3114
3114: Don't let unknown match arms fall back to ! r=kjeremy a=flodiebold Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
6f685df681
2 changed files with 22 additions and 1 deletions
|
@ -165,7 +165,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
Expr::Match { expr, arms } => {
|
Expr::Match { expr, arms } => {
|
||||||
let input_ty = self.infer_expr(*expr, &Expectation::none());
|
let input_ty = self.infer_expr(*expr, &Expectation::none());
|
||||||
|
|
||||||
let mut result_ty = self.table.new_maybe_never_type_var();
|
let mut result_ty = if arms.len() == 0 {
|
||||||
|
Ty::simple(TypeCtor::Never)
|
||||||
|
} else {
|
||||||
|
self.table.new_type_var()
|
||||||
|
};
|
||||||
|
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default());
|
let _pat_ty = self.infer_pat(arm.pat, &input_ty, BindingMode::default());
|
||||||
|
|
|
@ -101,6 +101,7 @@ fn test() {
|
||||||
);
|
);
|
||||||
assert_eq!(t, "Option<i32>");
|
assert_eq!(t, "Option<i32>");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn never_type_can_be_reinferred3() {
|
fn never_type_can_be_reinferred3() {
|
||||||
let t = type_at(
|
let t = type_at(
|
||||||
|
@ -137,6 +138,22 @@ fn test(a: Void) {
|
||||||
assert_eq!(t, "!");
|
assert_eq!(t, "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn match_unknown_arm() {
|
||||||
|
let t = type_at(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
fn test(a: Option) {
|
||||||
|
let t = match 0 {
|
||||||
|
_ => unknown,
|
||||||
|
};
|
||||||
|
t<|>;
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
assert_eq!(t, "{unknown}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn if_never() {
|
fn if_never() {
|
||||||
let t = type_at(
|
let t = type_at(
|
||||||
|
|
Loading…
Reference in a new issue