change const_param_default query to return EarlyBinder; remove bound_const_param_default query; add EarlyBinder to const_param_default in metadata

This commit is contained in:
Kyle Matsuda 2023-01-10 12:27:41 -07:00
parent bd6c63597b
commit ef58baf8b8
11 changed files with 12 additions and 22 deletions

View File

@ -511,9 +511,7 @@ fn inferred_kind(
return tcx.const_error(ty).into(); return tcx.const_error(ty).into();
} }
if !infer_args && has_default { if !infer_args && has_default {
tcx.bound_const_param_default(param.def_id) tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
.subst(tcx, substs.unwrap())
.into()
} else { } else {
if infer_args { if infer_args {
self.astconv.ct_infer(ty, Some(param), self.span).into() self.astconv.ct_infer(ty, Some(param), self.span).into()

View File

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

View File

@ -1224,9 +1224,7 @@ fn inferred_kind(
} }
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
if !infer_args && has_default { if !infer_args && has_default {
tcx.bound_const_param_default(param.def_id) tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
.subst(tcx, substs.unwrap())
.into()
} else { } else {
self.fcx.var_for_def(self.span, param) self.fcx.var_for_def(self.span, param)
} }

View File

@ -2070,7 +2070,7 @@ fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
hir::GenericParamKind::Const { ref default, .. } => { hir::GenericParamKind::Const { ref default, .. } => {
let def_id = param.def_id.to_def_id(); let def_id = param.def_id.to_def_id();
if default.is_some() { if default.is_some() {
record!(self.tables.const_param_default[def_id] <- self.tcx.bound_const_param_default(def_id).subst_identity()) record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id))
} }
} }
} }

View File

@ -360,7 +360,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>, fn_sig: Table<DefIndex, LazyValue<ty::PolyFnSig<'static>>>,
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>, codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
impl_trait_ref: Table<DefIndex, LazyValue<ty::TraitRef<'static>>>, impl_trait_ref: Table<DefIndex, LazyValue<ty::TraitRef<'static>>>,
const_param_default: Table<DefIndex, LazyValue<rustc_middle::ty::Const<'static>>>, const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>, object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>, optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>, mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,

View File

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

View File

@ -239,7 +239,7 @@ pub fn is_ct_infer(self) -> bool {
} }
} }
pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> { pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Const<'_>> {
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) { let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
hir::Node::GenericParam(hir::GenericParam { hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { default: Some(ac), .. }, kind: hir::GenericParamKind::Const { default: Some(ac), .. },
@ -250,5 +250,5 @@ pub fn const_param_default(tcx: TyCtxt<'_>, def_id: DefId) -> Const<'_> {
"`const_param_default` expected a generic parameter with a constant" "`const_param_default` expected a generic parameter with a constant"
), ),
}; };
Const::from_anon_const(tcx, default_def_id) ty::EarlyBinder(Const::from_anon_const(tcx, default_def_id))
} }

View File

@ -88,7 +88,7 @@ pub fn default_value<'tcx>(
Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into())) Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into()))
} }
GenericParamDefKind::Const { has_default } if has_default => { GenericParamDefKind::Const { has_default } if has_default => {
Some(tcx.bound_const_param_default(self.def_id).map_bound(|c| c.into())) Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into()))
} }
_ => None, _ => None,
} }

View File

@ -673,10 +673,6 @@ pub fn bound_item_bounds(
ty::EarlyBinder(self.item_bounds(def_id)) ty::EarlyBinder(self.item_bounds(def_id))
} }
pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
ty::EarlyBinder(self.const_param_default(def_id))
}
pub fn bound_predicates_of( pub fn bound_predicates_of(
self, self,
def_id: DefId, def_id: DefId,

View File

@ -838,9 +838,7 @@ fn generics(&mut self) -> &mut Self {
GenericParamDefKind::Const { has_default } => { GenericParamDefKind::Const { has_default } => {
self.visit(self.ev.tcx.type_of(param.def_id)); self.visit(self.ev.tcx.type_of(param.def_id));
if has_default { if has_default {
self.visit( self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity());
self.ev.tcx.bound_const_param_default(param.def_id).subst_identity(),
);
} }
} }
} }

View File

@ -507,7 +507,7 @@ fn clean_generic_param_def<'tcx>(
)), )),
default: match has_default { default: match has_default {
true => Some(Box::new( true => Some(Box::new(
cx.tcx.bound_const_param_default(def.def_id).subst_identity().to_string(), cx.tcx.const_param_default(def.def_id).subst_identity().to_string(),
)), )),
false => None, false => None,
}, },