Skip to content

Commit

Permalink
changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
kylematsuda committed Feb 17, 2023
1 parent c183110 commit 8e92849
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 12 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
assert!(self.tcx.is_static(def_id));
assert!(!self.tcx.is_thread_local_static(def_id));
// Use size and align of the type.
let ty = self.tcx.type_of(def_id).subst_identity();
let ty = self
.tcx
.type_of(def_id)
.no_bound_vars()
.expect("statics should not have generic parameters");
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
assert!(layout.is_sized());
(layout.size, layout.align.abi, AllocKind::LiveData)
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.into()
}
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
let ty = tcx.at(self.span).type_of(param.def_id).subst_identity();
let ty = tcx
.at(self.span)
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic");
if self.astconv.allow_ty_infer() {
self.astconv.ct_infer(ty, Some(param), inf.span).into()
} else {
Expand Down Expand Up @@ -503,7 +507,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
GenericParamDefKind::Const { has_default } => {
let ty = tcx.at(self.span).type_of(param.def_id).subst_identity();
let ty = tcx
.at(self.span)
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic");
if ty.references_error() {
return tcx.const_error(ty).into();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
args: &[hir::Expr<'_>],
kind: CallableKind| {
let arg_idx = args.iter().position(|a| a.hir_id == expr.hir_id).unwrap();
let fn_ty = self.tcx.type_of(def_id).0;
let fn_ty = self.tcx.type_of(def_id).skip_binder();
if !fn_ty.is_fn() {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tcx = self.fcx.tcx();
self.fcx
.ct_infer(
tcx.type_of(param.def_id).subst_identity(),
tcx.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
Some(param),
inf.span,
)
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
let tcx = self.cfcx.tcx();
self.cfcx
.ct_infer(
tcx.type_of(param.def_id).subst_identity(),
tcx.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
Some(param),
inf.span,
)
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
kind: ConstVariableOriginKind::SubstitutionPlaceholder,
span,
};
self.next_const_var(self.tcx.type_of(param.def_id).subst_identity(), origin).into()
self.next_const_var(
self.tcx
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
origin,
)
.into()
}
})
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,13 @@ impl<'tcx> InferCtxt<'tcx> {
val: ConstVariableValue::Unknown { universe: self.universe() },
});
self.tcx
.mk_const(const_var_id, self.tcx.type_of(param.def_id).subst_identity())
.mk_const(
const_var_id,
self.tcx
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
)
.into()
}
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ impl<'tcx> Const<'tcx> {
let expr = &tcx.hir().body(body_id).value;
debug!(?expr);

let ty = tcx.type_of(def.def_id_for_type_of()).subst_identity();
let ty = tcx
.type_of(def.def_id_for_type_of())
.no_bound_vars()
.expect("const parameter types cannot be generic");

match Self::try_eval_lit_or_param(tcx, ty, expr) {
Some(v) => v,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,9 @@ impl<'tcx> TyCtxt<'tcx> {
GenericParamDefKind::Const { .. } => self
.mk_const(
ParamConst { index: param.index, name: param.name },
self.type_of(param.def_id).subst_identity(),
self.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
)
.into(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1),
),
tcx.type_of(param.def_id).subst_identity(),
tcx.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
)
.into()
}
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,12 @@ fn clean_generic_param_def<'tcx>(
GenericParamDefKind::Const {
did: def.def_id,
ty: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def.def_id).subst_identity()),
ty::Binder::dummy(
cx.tcx
.type_of(def.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
),
cx,
Some(def.def_id),
)),
Expand Down

0 comments on commit 8e92849

Please sign in to comment.