Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da19b9d

Browse files
committed
Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnr
Improve bound const handling A few changes to make const handling more similar to type handling. r? `@compiler-errors` -errors
2 parents 5b9564a + 64be8bb commit da19b9d

File tree

23 files changed

+123
-97
lines changed

23 files changed

+123
-97
lines changed

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
187187
types: &mut |_bound_ty: ty::BoundTy| {
188188
unreachable!("we only replace regions in nll_relate, not types")
189189
},
190-
consts: &mut |_bound_var: ty::BoundVar| {
190+
consts: &mut |_bound_const: ty::BoundConst| {
191191
unreachable!("we only replace regions in nll_relate, not consts")
192192
},
193193
};
@@ -226,7 +226,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
226226
types: &mut |_bound_ty: ty::BoundTy| {
227227
unreachable!("we only replace regions in nll_relate, not types")
228228
},
229-
consts: &mut |_bound_var: ty::BoundVar| {
229+
consts: &mut |_bound_const: ty::BoundConst| {
230230
unreachable!("we only replace regions in nll_relate, not consts")
231231
},
232232
};

‎compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ fn param_env_with_gat_bounds<'tcx>(
24982498
ty::Const::new_bound(
24992499
tcx,
25002500
ty::INNERMOST,
2501-
ty::BoundVar::from_usize(bound_vars.len() - 1),
2501+
ty::BoundConst{var: ty::BoundVar::from_usize(bound_vars.len() - 1)},
25022502
)
25032503
.into()
25042504
}

‎compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>(
189189
}
190190
ty::GenericArgKind::Const(ct) => {
191191
if let ty::ConstKind::Bound(ty::INNERMOST, bv) = ct.kind() {
192-
mapping.insert(bv, tcx.mk_param_from_def(param))
192+
mapping.insert(bv.var, tcx.mk_param_from_def(param))
193193
} else {
194194
return None;
195195
}
@@ -307,16 +307,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MapAndCompressBoundVars<'tcx> {
307307
return ct;
308308
}
309309

310-
if let ty::ConstKind::Bound(binder, old_var) = ct.kind()
310+
if let ty::ConstKind::Bound(binder, old_bound) = ct.kind()
311311
&& self.binder == binder
312312
{
313-
let mapped = if let Some(mapped) = self.mapping.get(&old_var) {
313+
let mapped = if let Some(mapped) = self.mapping.get(&old_bound.var) {
314314
mapped.expect_const()
315315
} else {
316316
let var = ty::BoundVar::from_usize(self.still_bound_vars.len());
317317
self.still_bound_vars.push(ty::BoundVariableKind::Const);
318-
let mapped = ty::Const::new_bound(self.tcx, ty::INNERMOST, var);
319-
self.mapping.insert(old_var, mapped.into());
318+
let mapped = ty::Const::new_bound(self.tcx, ty::INNERMOST, ty::BoundConst{var});
319+
self.mapping.insert(old_bound.var, mapped.into());
320320
mapped
321321
};
322322

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10771077
ty::ConstKind::Param(param) => {
10781078
self.params.insert(param.index);
10791079
}
1080-
ty::ConstKind::Bound(db, ty::BoundVar{ .. }) if db >= self.depth => {
1080+
ty::ConstKind::Bound(db, _) if db >= self.depth => {
10811081
let guar = self.cx.dcx().delayed_bug("unexpected escaping late-bound const var");
10821082
return ControlFlow::Break(guar);
10831083
}

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,9 +2107,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21072107
let name = tcx.item_name(param_def_id);
21082108
ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
21092109
}
2110-
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {
2111-
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index))
2112-
}
2110+
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => ty::Const::new_bound(
2111+
tcx,
2112+
debruijn,
2113+
ty::BoundConst { var: ty::BoundVar::from_u32(index) },
2114+
),
21132115
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
21142116
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", path_hir_id),
21152117
}

‎compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
752752
) -> Ty<'tcx> {
753753
debug_assert!(!self.infcx.is_some_and(|infcx| ty_var != infcx.shallow_resolve(ty_var)));
754754
let var = self.canonical_var(var_kind, ty_var.into());
755-
Ty::new_bound(self.tcx, self.binder_index, var.into())
755+
let bt = ty::BoundTy { var, kind: ty::BoundTyKind::Anon };
756+
Ty::new_bound(self.tcx, self.binder_index, bt)
756757
}
757758

758759
/// Given a type variable `const_var` of the given kind, first check
@@ -768,6 +769,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
768769
!self.infcx.is_some_and(|infcx| ct_var != infcx.shallow_resolve_const(ct_var))
769770
);
770771
let var = self.canonical_var(var_kind, ct_var.into());
771-
ty::Const::new_bound(self.tcx, self.binder_index, var)
772+
let bc = ty::BoundConst { var };
773+
ty::Const::new_bound(self.tcx, self.binder_index, bc)
772774
}
773775
}

‎compiler/rustc_infer/src/infer/canonical/instantiate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CanonicalInstantiator<'tcx> {
133133
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
134134
match ct.kind() {
135135
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
136-
self.var_values[bound_const.as_usize()].expect_const()
136+
self.var_values[bound_const.var.as_usize()].expect_const()
137137
}
138138
_ => ct.super_fold_with(self),
139139
}
@@ -217,7 +217,7 @@ fn highest_var_in_clauses<'tcx>(c: ty::Clauses<'tcx>) -> usize {
217217
if let ty::ConstKind::Bound(debruijn, bound_const) = ct.kind()
218218
&& debruijn == self.current_index
219219
{
220-
self.max_var = self.max_var.max(bound_const.as_usize());
220+
self.max_var = self.max_var.max(bound_const.var.as_usize());
221221
} else if ct.has_vars_bound_at_or_above(self.current_index) {
222222
ct.super_visit_with(self);
223223
}

‎compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ impl<'tcx> InferCtxt<'tcx> {
430430
}
431431
GenericArgKind::Lifetime(result_value) => {
432432
// e.g., here `result_value` might be `'?1` in the example above...
433-
if let ty::ReBound(debruijn, br) = result_value.kind() {
433+
if let ty::ReBound(debruijn, b) = result_value.kind() {
434434
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
435435

436436
// We only allow a `ty::INNERMOST` index in generic parameters.
437437
assert_eq!(debruijn, ty::INNERMOST);
438-
opt_values[br.var] = Some(*original_value);
438+
opt_values[b.var] = Some(*original_value);
439439
}
440440
}
441441
GenericArgKind::Const(result_value) => {
@@ -444,7 +444,7 @@ impl<'tcx> InferCtxt<'tcx> {
444444

445445
// We only allow a `ty::INNERMOST` index in generic parameters.
446446
assert_eq!(debruijn, ty::INNERMOST);
447-
opt_values[b] = Some(*original_value);
447+
opt_values[b.var] = Some(*original_value);
448448
}
449449
}
450450
}

‎compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,8 @@ impl<'tcx> InferCtxt<'tcx> {
12651265
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
12661266
self.args[bt.var.index()].expect_ty()
12671267
}
1268-
fn replace_const(&mut self, bv: ty::BoundVar) -> ty::Const<'tcx> {
1269-
self.args[bv.index()].expect_const()
1268+
fn replace_const(&mut self, bc: ty::BoundConst) -> ty::Const<'tcx> {
1269+
self.args[bc.var.index()].expect_const()
12701270
}
12711271
}
12721272
let delegate = ToFreshVars { args };

‎compiler/rustc_infer/src/infer/relate/higher_ranked.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ impl<'tcx> InferCtxt<'tcx> {
4545
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
4646
)
4747
},
48-
consts: &mut |bound_var: ty::BoundVar| {
48+
consts: &mut |bound_const: ty::BoundConst| {
4949
ty::Const::new_placeholder(
5050
self.tcx,
51-
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
51+
ty::PlaceholderConst { universe: next_universe, bound: bound_const },
5252
)
5353
},
5454
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /