Skip to content

Commit 8132a61

Browse files
Rollup merge of rust-lang#157287 - khyperia:const-generics-nits, r=BoxyUwU
Const generics: remove AliasTerm::kind(), and small fixes When implementing rust-lang#157094 there were a few things I stumbled upon that I fixed, that were technically unrelated, and because that PR was already getting so big, I split the silly nitpick fixups into another PR (this PR). - first commit: `cx.alias_term_kind_from_def_id(goal.predicate.def_id())` can be written as just `goal.predicate.alias.kind`, without a query. doh. - second commit: remove `AliasTerm::kind()` (instead accessing the field `AliasTerm::kind` directly) - this also removes the interner parameter from `AliasTerm::expect_ct`/`AliasTerm::expect_ty`, yippee r? @BoxyUwU
2 parents 6672c68 + 09bb5bb commit 8132a61

21 files changed

Lines changed: 47 additions & 60 deletions

File tree

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
636636
| PredicateFilter::SelfAndAssociatedTypeBounds
637637
| PredicateFilter::ConstIfConst => {
638638
let projection_ty = projection_term
639-
.map_bound(|projection_term| projection_term.expect_ty(self.tcx()));
639+
.map_bound(|projection_term| projection_term.expect_ty());
640640
// Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty`
641641
// parameter to have a skipped binder.
642642
let param_ty = Ty::new_alias(tcx, projection_ty.skip_binder());

compiler/rustc_infer/src/infer/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<'tcx> InferCtxt<'tcx> {
2323
debug_assert!(!self.next_trait_solver());
2424

2525
let span = self.tcx.def_span(alias_term.def_id());
26-
let infer_var = if alias_term.kind(self.tcx).is_type() {
26+
let infer_var = if alias_term.kind.is_type() {
2727
self.next_ty_var(span).into()
2828
} else {
2929
self.next_const_var(span).into()

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> InferCtxt<'tcx> {
187187
let Some(source_alias) = source_term.to_alias_term() else {
188188
bug!("generalized `{source_term:?} to infer, not an alias");
189189
};
190-
match source_alias.kind(self.tcx) {
190+
match source_alias.kind {
191191
ty::AliasTermKind::ProjectionTy { .. }
192192
| ty::AliasTermKind::ProjectionConst { .. } => {
193193
// FIXME: This does not handle subtyping correctly, we could
@@ -426,7 +426,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
426426
/// Create a new type variable in the universe of the target when
427427
/// generalizing an alias.
428428
fn next_var_for_alias_of_kind(&self, alias: ty::AliasTerm<'tcx>) -> ty::Term<'tcx> {
429-
if alias.kind(self.cx()).is_type() {
429+
if alias.kind.is_type() {
430430
self.infcx.next_ty_var_in_universe(self.span, self.for_universe).into()
431431
} else {
432432
self.infcx.next_const_var_in_universe(self.span, self.for_universe).into()

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ define_print! {
31563156
}
31573157

31583158
ty::AliasTerm<'tcx> {
3159-
match self.kind(p.tcx()) {
3159+
match self.kind {
31603160
ty::AliasTermKind::InherentTy {..} | ty::AliasTermKind::InherentConst {..} => p.pretty_print_inherent_projection(*self)?,
31613161
ty::AliasTermKind::ProjectionTy { def_id } => {
31623162
if !(p.should_print_verbose() || with_reduced_queries())

compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where
1616
goal: Goal<I, ty::NormalizesTo<I>>,
1717
def_id: I::UnevaluatedConstId,
1818
) -> QueryResultOrRerunNonErased<I> {
19-
let uv = goal.predicate.alias.expect_ct(self.cx());
19+
let uv = goal.predicate.alias.expect_ct();
2020
self.evaluate_const_and_instantiate_normalizes_to_term(goal, uv)
2121
}
2222
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/free_alias.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
.map(|pred| goal.with(cx, pred)),
3232
);
3333

34-
let actual = match free_alias.kind(cx) {
34+
let actual = match free_alias.kind {
3535
ty::AliasTermKind::FreeTy { def_id } => {
3636
cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into()
3737
}
@@ -43,7 +43,7 @@ where
4343
ty::AliasTermKind::FreeConst { .. } => {
4444
return self.evaluate_const_and_instantiate_normalizes_to_term(
4545
goal,
46-
free_alias.expect_ct(cx),
46+
free_alias.expect_ct(),
4747
);
4848
}
4949
kind => panic!("expected free alias, found {kind:?}"),

compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ where
5454
.map(|pred| goal.with(cx, pred)),
5555
);
5656

57-
let normalized = match inherent.kind(cx) {
57+
let normalized = match inherent.kind {
5858
ty::AliasTermKind::InherentTy { def_id } => {
5959
cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
6060
}

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ where
287287
);
288288

289289
let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| {
290-
let error_term = match goal.predicate.alias.kind(cx) {
290+
let error_term = match goal.predicate.alias.kind {
291291
ty::AliasTermKind::ProjectionTy { .. } => Ty::new_error(cx, guar).into(),
292292
ty::AliasTermKind::ProjectionConst { .. } => Const::new_error(cx, guar).into(),
293293
kind => panic!("expected projection, found {kind:?}"),
@@ -400,7 +400,7 @@ where
400400
}
401401

402402
// Finally we construct the actual value of the associated type.
403-
let term = match goal.predicate.alias.kind(cx) {
403+
let term = match goal.predicate.alias.kind {
404404
ty::AliasTermKind::ProjectionTy { .. } => cx
405405
.type_of(target_item_def_id.into())
406406
.instantiate(cx, target_args)
@@ -417,7 +417,9 @@ where
417417
ty::AliasTermKind::ProjectionConst { .. } => {
418418
let uv = ty::UnevaluatedConst::new(
419419
cx,
420-
ty::UnevaluatedConstKind::new_from_def_id(cx, target_item_def_id.into()),
420+
ty::UnevaluatedConstKind::Projection {
421+
def_id: target_item_def_id.into().try_into().unwrap(),
422+
},
421423
target_args,
422424
);
423425
return ecx.evaluate_const_and_instantiate_normalizes_to_term(goal, uv);
@@ -501,7 +503,7 @@ where
501503
let pred = ty::ProjectionPredicate {
502504
projection_term: ty::AliasTerm::new(
503505
cx,
504-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
506+
goal.predicate.alias.kind,
505507
[goal.predicate.self_ty(), inputs],
506508
),
507509
term: output.into(),
@@ -558,7 +560,7 @@ where
558560
(
559561
ty::AliasTerm::new(
560562
cx,
561-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
563+
goal.predicate.alias.kind,
562564
[goal.predicate.self_ty(), tupled_inputs_ty],
563565
),
564566
output_coroutine_ty.into(),
@@ -567,7 +569,7 @@ where
567569
(
568570
ty::AliasTerm::new(
569571
cx,
570-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
572+
goal.predicate.alias.kind,
571573
[
572574
I::GenericArg::from(goal.predicate.self_ty()),
573575
tupled_inputs_ty.into(),
@@ -580,7 +582,7 @@ where
580582
(
581583
ty::AliasTerm::new(
582584
cx,
583-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
585+
goal.predicate.alias.kind,
584586
[goal.predicate.self_ty(), tupled_inputs_ty],
585587
),
586588
coroutine_return_ty.into(),
@@ -784,11 +786,7 @@ where
784786
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
785787
goal,
786788
ty::ProjectionPredicate {
787-
projection_term: ty::AliasTerm::new(
788-
ecx.cx(),
789-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
790-
[self_ty],
791-
),
789+
projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.alias.kind, [self_ty]),
792790
term,
793791
}
794792
.upcast(cx),
@@ -820,11 +818,7 @@ where
820818
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
821819
goal,
822820
ty::ProjectionPredicate {
823-
projection_term: ty::AliasTerm::new(
824-
ecx.cx(),
825-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
826-
[self_ty],
827-
),
821+
projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.alias.kind, [self_ty]),
828822
term,
829823
}
830824
.upcast(cx),
@@ -912,7 +906,7 @@ where
912906
ty::ProjectionPredicate {
913907
projection_term: ty::AliasTerm::new(
914908
ecx.cx(),
915-
cx.alias_term_kind_from_def_id(goal.predicate.def_id()),
909+
goal.predicate.alias.kind,
916910
[self_ty, coroutine.resume_ty()],
917911
),
918912
term,

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16661666

16671667
if let Some(lhs) = lhs.to_alias_term()
16681668
&& let ty::AliasTermKind::ProjectionTy { .. }
1669-
| ty::AliasTermKind::ProjectionConst { .. } = lhs.kind(self.tcx)
1669+
| ty::AliasTermKind::ProjectionConst { .. } = lhs.kind
16701670
&& let Some((better_type_err, expected_term)) =
16711671
derive_better_type_error(lhs, rhs)
16721672
{
@@ -1676,7 +1676,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16761676
)
16771677
} else if let Some(rhs) = rhs.to_alias_term()
16781678
&& let ty::AliasTermKind::ProjectionTy { .. }
1679-
| ty::AliasTermKind::ProjectionConst { .. } = rhs.kind(self.tcx)
1679+
| ty::AliasTermKind::ProjectionConst { .. } = rhs.kind
16801680
&& let Some((better_type_err, expected_term)) =
16811681
derive_better_type_error(rhs, lhs)
16821682
{

compiler/rustc_trait_selection/src/error_reporting/traits/overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
7878
let mut err = match cause {
7979
OverflowCause::DeeplyNormalize(alias_term) => {
8080
let alias_term = self.resolve_vars_if_possible(alias_term);
81-
let kind = alias_term.kind(self.tcx).descr();
81+
let kind = alias_term.kind.descr();
8282
let alias_str = with_short_path(self.tcx, alias_term);
8383
struct_span_code_err!(
8484
self.dcx(),

0 commit comments

Comments
 (0)