Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,15 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
search_stack.push((ty, hir_ty));
}

(GenericArgKind::Const(_ct), hir::GenericArg::Const(_hir_ct)) => {
(GenericArgKind::Const(_ct, _), hir::GenericArg::Const(_hir_ct)) => {
// Lifetimes cannot be found in consts, so we don't need
// to search anything here.
}

(
GenericArgKind::Lifetime(_)
| GenericArgKind::Type(_)
| GenericArgKind::Const(_),
| GenericArgKind::Const(_, _),
_,
) => {
// HIR lowering sometimes doesn't catch this in erroneous
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ fn check_opaque_type_parameter_valid(
// see that issue for more. We will also have to ignore unused lifetime
// params for RPIT, but that's comparatively trivial ✨
GenericArgKind::Lifetime(_) => continue,
GenericArgKind::Const(ct) => matches!(ct.kind(), ty::ConstKind::Param(_)),
GenericArgKind::Const(ct, _) => matches!(ct.kind(), ty::ConstKind::Param(_)),
};

if arg_is_param {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
.type_must_outlive(origin, t1, r2, constraint_category);
}

GenericArgKind::Const(_) => unreachable!(),
GenericArgKind::Const(_, _) => unreachable!(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ fn push_generic_params_internal<'tcx>(
GenericArgKind::Type(type_parameter) => {
push_debuginfo_type_name(tcx, type_parameter, true, output, visited);
}
GenericArgKind::Const(ct) => {
GenericArgKind::Const(ct, false) => {
push_const_param(tcx, ct, output);
}
other => bug!("Unexpected non-erasable generic: {:?}", other),
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_hir_analysis/src/astconv/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
)
.into()
}
ty::GenericParamDefKind::Const { .. } => {
ty::GenericParamDefKind::Const { is_host_effect, .. } => {
if !emitted_bad_param_err {
tcx.sess.emit_err(
crate::errors::ReturnTypeNotationIllegalParam::Const {
Expand All @@ -375,13 +375,16 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
.type_of(param.def_id)
.no_bound_vars()
.expect("ct params cannot have early bound vars");
ty::Const::new_bound(
tcx,
ty::INNERMOST,
ty::BoundVar::from_usize(num_bound_vars),
ty,
// FIXME(fee1-dead) this seems like something that's very commonly written
ty::GenericArg::new_const(
ty::Const::new_bound(
tcx,
ty::INNERMOST,
ty::BoundVar::from_usize(num_bound_vars),
ty,
),
is_host_effect,
)
.into()
}
};
num_bound_vars += 1;
Expand Down
61 changes: 36 additions & 25 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,33 +449,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
};

match (&param.kind, arg) {
match (param.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
self.astconv.ast_region_to_region(lt, Some(param)).into()
}
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
(GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
handle_ty_args(has_default, ty)
}
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
(GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
handle_ty_args(has_default, &inf.to_ty())
}
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
(GenericParamDefKind::Const { is_host_effect, .. }, GenericArg::Const(ct)) => {
let did = ct.value.def_id;
tcx.feed_anon_const_type(did, tcx.type_of(param.def_id));
ty::Const::from_anon_const(tcx, did).into()
ty::GenericArg::new_const(
ty::Const::from_anon_const(tcx, did),
is_host_effect,
)
}
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
(
GenericParamDefKind::Const { is_host_effect, .. },
hir::GenericArg::Infer(inf),
) => {
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()
let ct = if self.astconv.allow_ty_infer() {
self.astconv.ct_infer(ty, Some(param), inf.span)
} else {
self.inferred_params.push(inf.span);
ty::Const::new_misc_error(tcx, ty).into()
}
ty::Const::new_misc_error(tcx, ty)
};
ty::GenericArg::new_const(ct, is_host_effect)
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -522,28 +529,31 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Ty::new_misc_error(tcx).into()
}
}
GenericParamDefKind::Const { has_default, .. } => {
GenericParamDefKind::Const { has_default, is_host_effect } => {
let ty = tcx
.at(self.span)
.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic");
if let Err(guar) = ty.error_reported() {
return ty::Const::new_error(tcx, guar, ty).into();
return ty::GenericArg::new_const(
ty::Const::new_error(tcx, guar, ty),
is_host_effect,
);
}
// FIXME(effects) see if we should special case effect params here
if !infer_args && has_default {
tcx.const_param_default(param.def_id)
.instantiate(tcx, args.unwrap())
.into()
let ct = if !infer_args && has_default {
tcx.const_param_default(param.def_id).instantiate(tcx, args.unwrap())
} else {
if infer_args {
self.astconv.ct_infer(ty, Some(param), self.span).into()
self.astconv.ct_infer(ty, Some(param), self.span)
} else {
// We've already errored above about the mismatch.
ty::Const::new_misc_error(tcx, ty).into()
ty::Const::new_misc_error(tcx, ty)
}
}
};

ty::GenericArg::new_const(ct, is_host_effect)
}
}
}
Expand Down Expand Up @@ -1131,12 +1141,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
(bound, bound2) = (bound2, bound);
}

let unconsted_args = bound
.skip_binder()
.args
.iter()
.enumerate()
.map(|(n, arg)| if host_index == n { tcx.consts.true_.into() } else { arg });
let unconsted_args = bound.skip_binder().args.iter().enumerate().map(|(n, arg)| {
if host_index == n {
ty::GenericArg::effect_const_arg(tcx.consts.true_)
} else {
arg
}
});

if unconsted_args.eq(bound2.skip_binder().args.iter()) {
next_cand = matching_candidates.next();
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ impl<'tcx> Bounds<'tcx> {
let trait_ref = trait_ref.map_bound(|mut trait_ref| {
trait_ref.args =
tcx.mk_args_from_iter(trait_ref.args.iter().enumerate().map(|(n, arg)| {
if host_index == n { tcx.consts.true_.into() } else { arg }
if host_index == n {
ty::GenericArg::effect_const_arg(tcx.consts.true_)
} else {
arg
}
}));
trait_ref
});
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,18 +2357,20 @@ fn param_env_with_gat_bounds<'tcx>(
)
.into()
}
GenericParamDefKind::Const { .. } => {
GenericParamDefKind::Const { is_host_effect, .. } => {
let bound_var = ty::BoundVariableKind::Const;
bound_vars.push(bound_var);
ty::Const::new_bound(
tcx,
ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1),
tcx.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
ty::GenericArg::new_const(
ty::Const::new_bound(
tcx,
ty::INNERMOST,
ty::BoundVar::from_usize(bound_vars.len() - 1),
tcx.type_of(param.def_id)
.no_bound_vars()
.expect("const parameter types cannot be generic"),
),
is_host_effect,
)
.into()
}
});
// When checking something like
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
}
}
}
GenericParamDefKind::Const { .. } => {
GenericParamDefKind::Const { is_host_effect, .. } => {
if is_our_default(param) {
// FIXME(const_generics_defaults): This
// is incorrect when dealing with unused args, for example
Expand All @@ -1339,7 +1339,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
wfcx.register_wf_obligation(
tcx.def_span(param.def_id),
None,
default_ct.into(),
ty::GenericArg::new_const(default_ct, is_host_effect),
);
}
}
Expand Down Expand Up @@ -1377,14 +1377,14 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id

tcx.mk_param_from_def(param)
}
GenericParamDefKind::Const { .. } => {
GenericParamDefKind::Const { is_host_effect, .. } => {
// If the param has a default, ...
if is_our_default(param) {
let default_ct = tcx.const_param_default(param.def_id).instantiate_identity();
// ... and it's not a dependent default, ...
if !default_ct.has_param() {
// ... then substitute it with the default.
return default_ct.into();
return ty::GenericArg::new_const(default_ct, is_host_effect);
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
def_id,
ty::GenericArgs::for_item(tcx, def_id, |param, _| {
if param.is_host_effect() {
tcx.consts.true_.into()
ty::GenericArg::effect_const_arg(tcx.consts.true_)
} else {
tcx.mk_param_from_def(param)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(

// No predicates from lifetimes or constants, except potentially
// constants' types, but `walk` will get to them as well.
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_, _) => continue,
};

match *ty.kind() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> {
.to_predicate(tcx),
span,
)),
GenericArgKind::Const(_) => {
GenericArgKind::Const(_, _) => {
// Generic consts don't impose any constraints.
None
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)).or_insert(span);
}

GenericArgKind::Const(_) => {
GenericArgKind::Const(_, _) => {
// Generic consts don't impose any constraints.
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_region(current, lt, variance_i)
}
GenericArgKind::Type(ty) => self.add_constraints_from_ty(current, ty, variance_i),
GenericArgKind::Const(val) => {
GenericArgKind::Const(val, _) => {
self.add_constraints_from_const(current, val, variance_i)
}
}
Expand Down Expand Up @@ -364,7 +364,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_region(current, lt, variance_i)
}
GenericArgKind::Type(ty) => self.add_constraints_from_ty(current, ty, variance_i),
GenericArgKind::Const(val) => {
GenericArgKind::Const(val, _) => {
self.add_constraints_from_const(current, val, variance)
}
}
Expand Down
Loading