Typeck inline consts
This commit is contained in:
parent
fe922e567f
commit
85b5ce2643
@ -286,6 +286,7 @@ fn check_expr_kind(
|
||||
}
|
||||
ExprKind::DropTemps(ref e) => self.check_expr_with_expectation(e, expected),
|
||||
ExprKind::Array(ref args) => self.check_expr_array(args, expected, expr),
|
||||
ExprKind::ConstBlock(ref anon_const) => self.to_const(anon_const).ty,
|
||||
ExprKind::Repeat(ref element, ref count) => {
|
||||
self.check_expr_repeat(element, count, expected, expr)
|
||||
}
|
||||
|
@ -111,6 +111,7 @@
|
||||
use rustc_hir::{HirIdMap, Node};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
@ -528,7 +529,20 @@ fn typeck_with_fallback<'tcx>(
|
||||
hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(fallback);
|
||||
.unwrap_or_else(|| match tcx.hir().get(id) {
|
||||
Node::AnonConst(_) => match tcx.hir().get(tcx.hir().get_parent_node(id)) {
|
||||
Node::Expr(&hir::Expr {
|
||||
kind: hir::ExprKind::ConstBlock(ref anon_const),
|
||||
..
|
||||
}) if anon_const.hir_id == id => fcx.next_ty_var(TypeVariableOrigin {
|
||||
kind: TypeVariableOriginKind::TypeInference,
|
||||
span,
|
||||
}),
|
||||
_ => fallback(),
|
||||
},
|
||||
_ => fallback(),
|
||||
});
|
||||
|
||||
let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type);
|
||||
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
|
||||
|
||||
|
@ -309,6 +309,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
||||
tcx.types.usize
|
||||
}
|
||||
|
||||
Node::Expr(&Expr { kind: ExprKind::ConstBlock(ref anon_const), .. })
|
||||
if anon_const.hir_id == hir_id =>
|
||||
{
|
||||
tcx.typeck(def_id).node_type(anon_const.hir_id)
|
||||
}
|
||||
|
||||
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
|
||||
.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id())
|
||||
.repr
|
||||
|
@ -258,7 +258,10 @@ pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) {
|
||||
self.consume_exprs(&ia.inputs_exprs);
|
||||
}
|
||||
|
||||
hir::ExprKind::Continue(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Err => {}
|
||||
hir::ExprKind::Continue(..)
|
||||
| hir::ExprKind::Lit(..)
|
||||
| hir::ExprKind::ConstBlock(..)
|
||||
| hir::ExprKind::Err => {}
|
||||
|
||||
hir::ExprKind::Loop(ref blk, _, _) => {
|
||||
self.walk_block(blk);
|
||||
|
@ -370,6 +370,7 @@ fn cat_expr_adjusted_with<F>(
|
||||
| hir::ExprKind::Loop(..)
|
||||
| hir::ExprKind::Match(..)
|
||||
| hir::ExprKind::Lit(..)
|
||||
| hir::ExprKind::ConstBlock(..)
|
||||
| hir::ExprKind::Break(..)
|
||||
| hir::ExprKind::Continue(..)
|
||||
| hir::ExprKind::Struct(..)
|
||||
|
Loading…
Reference in New Issue
Block a user