Skip to content

Commit 0ff2fe8

Browse files
committed
add AliasTermTy::with_args to simplify a common-ish pattern
1 parent c32020d commit 0ff2fe8

4 files changed

Lines changed: 11 additions & 27 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ where
965965
// Alternatively we could modify `Equate` for this case by adding another
966966
// variant to `StructurallyRelateAliases`.
967967
let identity_args = self.fresh_args_for_item(alias.def_id());
968-
let rigid_ctor = ty::AliasTerm::new_from_args(cx, alias.kind, identity_args);
968+
let rigid_ctor = alias.with_args(cx, identity_args);
969969
let ctor_term = rigid_ctor.to_term(cx);
970970
let obligations = self.delegate.eq_structurally_relating_aliases(
971971
param_env,

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
13401340
};
13411341

13421342
let predicate = ty::ProjectionPredicate {
1343-
projection_term: ty::AliasTerm::new_from_args(
1344-
tcx,
1345-
obligation.predicate.kind,
1346-
trait_ref.args,
1347-
),
1343+
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
13481344
term: ty.into(),
13491345
};
13501346

@@ -1388,11 +1384,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
13881384
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Output);
13891385

13901386
let predicate = ty::ProjectionPredicate {
1391-
projection_term: ty::AliasTerm::new_from_args(
1392-
tcx,
1393-
obligation.predicate.kind,
1394-
trait_ref.args,
1395-
),
1387+
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
13961388
term: return_ty.into(),
13971389
};
13981390

@@ -1434,11 +1426,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
14341426
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id()).name(), sym::Item);
14351427

14361428
let predicate = ty::ProjectionPredicate {
1437-
projection_term: ty::AliasTerm::new_from_args(
1438-
tcx,
1439-
obligation.predicate.kind,
1440-
trait_ref.args,
1441-
),
1429+
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
14421430
term: yield_ty.into(),
14431431
};
14441432

@@ -1488,11 +1476,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
14881476
let item_ty = args.type_at(0);
14891477

14901478
let predicate = ty::ProjectionPredicate {
1491-
projection_term: ty::AliasTerm::new_from_args(
1492-
tcx,
1493-
obligation.predicate.kind,
1494-
trait_ref.args,
1495-
),
1479+
projection_term: obligation.predicate.with_args(tcx, trait_ref.args),
14961480
term: item_ty.into(),
14971481
};
14981482

@@ -1898,11 +1882,7 @@ fn confirm_async_fn_kind_helper_candidate<'cx, 'tcx>(
18981882
};
18991883

19001884
let predicate = ty::ProjectionPredicate {
1901-
projection_term: ty::AliasTerm::new_from_args(
1902-
selcx.tcx(),
1903-
obligation.predicate.kind,
1904-
obligation.predicate.args,
1905-
),
1885+
projection_term: obligation.predicate.with_args(selcx.tcx(), obligation.predicate.args),
19061886
term: ty::CoroutineClosureSignature::tupled_upvars_by_closure_kind(
19071887
selcx.tcx(),
19081888
goal_kind_ty.expect_ty().to_opt_closure_kind().unwrap(),

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,10 @@ impl<I: Interner> AliasTerm<I> {
769769
Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args))
770770
.into()
771771
}
772+
773+
pub fn with_args(self, interner: I, args: I::GenericArgs) -> Self {
774+
Self::new_from_args(interner, self.kind, args)
775+
}
772776
}
773777

774778
/// The following methods work only with (trait) associated term projections.

compiler/rustc_type_ir/src/relate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<I: Interner> Relate<I> for ty::AliasTerm<I> {
256256
relate_args_invariantly(relation, a.args, b.args)?
257257
}
258258
};
259-
Ok(ty::AliasTerm::new_from_args(relation.cx(), a.kind, args))
259+
Ok(a.with_args(relation.cx(), args))
260260
}
261261
}
262262
}

0 commit comments

Comments
 (0)