Skip to content

Commit ef58baf

Browse files
committed
change const_param_default query to return EarlyBinder; remove bound_const_param_default query; add EarlyBinder to const_param_default in metadata
1 parent bd6c635 commit ef58baf

File tree

11 files changed

+12
-22
lines changed

11 files changed

+12
-22
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
511511
return tcx.const_error(ty).into();
512512
}
513513
if !infer_args && has_default {
514-
tcx.bound_const_param_default(param.def_id)
515-
.subst(tcx, substs.unwrap())
516-
.into()
514+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
517515
} else {
518516
if infer_args {
519517
self.astconv.ct_infer(ty, Some(param), self.span).into()

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13501350
// is incorrect when dealing with unused substs, for example
13511351
// for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>`
13521352
// we should eagerly error.
1353-
let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity();
1353+
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
13541354
if !default_ct.needs_subst() {
13551355
wfcx.register_wf_obligation(
13561356
tcx.def_span(param.def_id),
@@ -1396,7 +1396,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13961396
GenericParamDefKind::Const { .. } => {
13971397
// If the param has a default, ...
13981398
if is_our_default(param) {
1399-
let default_ct = tcx.bound_const_param_default(param.def_id).subst_identity();
1399+
let default_ct = tcx.const_param_default(param.def_id).subst_identity();
14001400
// ... and it's not a dependent default, ...
14011401
if !default_ct.needs_subst() {
14021402
// ... then substitute it with the default.

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1224,9 +1224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12241224
}
12251225
GenericParamDefKind::Const { has_default } => {
12261226
if !infer_args && has_default {
1227-
tcx.bound_const_param_default(param.def_id)
1228-
.subst(tcx, substs.unwrap())
1229-
.into()
1227+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
12301228
} else {
12311229
self.fcx.var_for_def(self.span, param)
12321230
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
20702070
hir::GenericParamKind::Const { ref default, .. } => {
20712071
let def_id = param.def_id.to_def_id();
20722072
if default.is_some() {
2073-
record!(self.tables.const_param_default[def_id] <- self.tcx.bound_const_param_default(def_id).subst_identity())
2073+
record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id))
20742074
}
20752075
}
20762076
}

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ define_tables! {
360360
fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>,
361361
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
362362
impl_trait_ref: Table<DefIndex, LazyValue<ty::TraitRef<'static>>>,
363-
const_param_default: Table<DefIndex, LazyValue<rustc_middle::ty::Const<'static>>>,
363+
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
364364
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
365365
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
366366
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ rustc_queries! {
142142

143143
/// Given the def_id of a const-generic parameter, computes the associated default const
144144
/// parameter. e.g. `fn example<const N: usize=3>` called on `N` would return `3`.
145-
query const_param_default(param: DefId) -> ty::Const<'tcx> {
145+
query const_param_default(param: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
146146
desc { |tcx| "computing const default for a given parameter `{}`", tcx.def_path_str(param) }
147147
cache_on_disk_if { param.is_local() }
148148
separate_provide_extern

compiler/rustc_middle/src/ty/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<'tcx> Const<'tcx> {
239239
}
240240
}
241241

242-
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> {
242+
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Const<'_>> {
243243
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
244244
hir::Node::GenericParam(hir::GenericParam {
245245
kind: hir::GenericParamKind::Const { default: Some(ac), .. },
@@ -250,5 +250,5 @@ pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> {
250250
"`const_param_default` expected a generic parameter with a constant"
251251
),
252252
};
253-
Const::from_anon_const(tcx, default_def_id)
253+
ty::EarlyBinder(Const::from_anon_const(tcx, default_def_id))
254254
}

compiler/rustc_middle/src/ty/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl GenericParamDef {
8888
Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into()))
8989
}
9090
GenericParamDefKind::Const { has_default } if has_default => {
91-
Some(tcx.bound_const_param_default(self.def_id).map_bound(|c| c.into()))
91+
Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
9292
}
9393
_ => None,
9494
}

compiler/rustc_middle/src/ty/util.rs

-4
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,6 @@ impl<'tcx> TyCtxt<'tcx> {
673673
ty::EarlyBinder(self.item_bounds(def_id))
674674
}
675675

676-
pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
677-
ty::EarlyBinder(self.const_param_default(def_id))
678-
}
679-
680676
pub fn bound_predicates_of(
681677
self,
682678
def_id: DefId,

compiler/rustc_privacy/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
838838
GenericParamDefKind::Const { has_default } => {
839839
self.visit(self.ev.tcx.type_of(param.def_id));
840840
if has_default {
841-
self.visit(
842-
self.ev.tcx.bound_const_param_default(param.def_id).subst_identity(),
843-
);
841+
self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity());
844842
}
845843
}
846844
}

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fn clean_generic_param_def<'tcx>(
507507
)),
508508
default: match has_default {
509509
true => Some(Box::new(
510-
cx.tcx.bound_const_param_default(def.def_id).subst_identity().to_string(),
510+
cx.tcx.const_param_default(def.def_id).subst_identity().to_string(),
511511
)),
512512
false => None,
513513
},

0 commit comments

Comments
 (0)