Skip to content

Commit 85b5ce2

Browse files
committed
Typeck inline consts
1 parent fe922e5 commit 85b5ce2

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

compiler/rustc_typeck/src/check/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286286
}
287287
ExprKind::DropTemps(ref e) => self.check_expr_with_expectation(e, expected),
288288
ExprKind::Array(ref args) => self.check_expr_array(args, expected, expr),
289+
ExprKind::ConstBlock(ref anon_const) => self.to_const(anon_const).ty,
289290
ExprKind::Repeat(ref element, ref count) => {
290291
self.check_expr_repeat(element, count, expected, expr)
291292
}

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ use rustc_hir::itemlikevisit::ItemLikeVisitor;
111111
use rustc_hir::{HirIdMap, Node};
112112
use rustc_index::bit_set::BitSet;
113113
use rustc_index::vec::Idx;
114+
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
114115
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
115116
use rustc_middle::ty::query::Providers;
116117
use rustc_middle::ty::subst::GenericArgKind;
@@ -528,7 +529,20 @@ fn typeck_with_fallback<'tcx>(
528529
hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)),
529530
_ => None,
530531
})
531-
.unwrap_or_else(fallback);
532+
.unwrap_or_else(|| match tcx.hir().get(id) {
533+
Node::AnonConst(_) => match tcx.hir().get(tcx.hir().get_parent_node(id)) {
534+
Node::Expr(&hir::Expr {
535+
kind: hir::ExprKind::ConstBlock(ref anon_const),
536+
..
537+
}) if anon_const.hir_id == id => fcx.next_ty_var(TypeVariableOrigin {
538+
kind: TypeVariableOriginKind::TypeInference,
539+
span,
540+
}),
541+
_ => fallback(),
542+
},
543+
_ => fallback(),
544+
});
545+
532546
let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type);
533547
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
534548

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
309309
tcx.types.usize
310310
}
311311

312+
Node::Expr(&Expr { kind: ExprKind::ConstBlock(ref anon_const), .. })
313+
if anon_const.hir_id == hir_id =>
314+
{
315+
tcx.typeck(def_id).node_type(anon_const.hir_id)
316+
}
317+
312318
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => tcx
313319
.adt_def(tcx.hir().get_parent_did(hir_id).to_def_id())
314320
.repr

compiler/rustc_typeck/src/expr_use_visitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
258258
self.consume_exprs(&ia.inputs_exprs);
259259
}
260260

261-
hir::ExprKind::Continue(..) | hir::ExprKind::Lit(..) | hir::ExprKind::Err => {}
261+
hir::ExprKind::Continue(..)
262+
| hir::ExprKind::Lit(..)
263+
| hir::ExprKind::ConstBlock(..)
264+
| hir::ExprKind::Err => {}
262265

263266
hir::ExprKind::Loop(ref blk, _, _) => {
264267
self.walk_block(blk);

compiler/rustc_typeck/src/mem_categorization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
370370
| hir::ExprKind::Loop(..)
371371
| hir::ExprKind::Match(..)
372372
| hir::ExprKind::Lit(..)
373+
| hir::ExprKind::ConstBlock(..)
373374
| hir::ExprKind::Break(..)
374375
| hir::ExprKind::Continue(..)
375376
| hir::ExprKind::Struct(..)

0 commit comments

Comments
 (0)