Implement const block inference

This commit is contained in:
Lukas Wirth 2020-12-23 12:24:24 +01:00
parent 0a780c0ab3
commit a142beaf01
5 changed files with 25 additions and 6 deletions

View file

@ -155,7 +155,7 @@ impl<'a> InferenceContext<'a> {
}
None => self.infer_block(statements, *tail, expected),
},
Expr::Unsafe { body } => self.infer_expr(*body, expected),
Expr::Unsafe { body } | Expr::Const { body } => self.infer_expr(*body, expected),
Expr::TryBlock { body } => {
let _inner = self.infer_expr(*body, expected);
// FIXME should be std::result::Result<{inner}, _>

View file

@ -1894,6 +1894,7 @@ fn effects_smoke_test() {
let x = unsafe { 92 };
let y = async { async { () }.await };
let z = try { () };
let w = const { 92 };
let t = 'a: { 92 };
}
@ -1905,7 +1906,7 @@ fn effects_smoke_test() {
}
"#,
expect![[r#"
16..136 '{ ...2 }; }': ()
16..162 '{ ...2 }; }': ()
26..27 'x': i32
30..43 'unsafe { 92 }': i32
37..43 '{ 92 }': i32
@ -1921,9 +1922,13 @@ fn effects_smoke_test() {
99..109 'try { () }': {unknown}
103..109 '{ () }': ()
105..107 '()': ()
119..120 't': i32
127..133 '{ 92 }': i32
129..131 '92': i32
119..120 'w': i32
123..135 'const { 92 }': i32
129..135 '{ 92 }': i32
131..133 '92': i32
145..146 't': i32
153..159 '{ 92 }': i32
155..157 '92': i32
"#]],
)
}