Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 273b990

Browse files
Align Term methods with GenericArg methods
1 parent 7c52d2d commit 273b990

File tree

23 files changed

+46
-36
lines changed

23 files changed

+46
-36
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn push_debuginfo_type_name<'tcx>(
263263
let ExistentialProjection { def_id: item_def_id, term, .. } =
264264
tcx.instantiate_bound_regions_with_erased(bound);
265265
// FIXME(associated_const_equality): allow for consts here
266-
(item_def_id, term.ty().unwrap())
266+
(item_def_id, term.expect_type())
267267
})
268268
.collect();
269269

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ fn try_report_async_mismatch<'tcx>(
22812281
&& let Some(proj) = proj.no_bound_vars()
22822282
&& infcx.can_eq(
22832283
error.root_obligation.param_env,
2284-
proj.term.ty().unwrap(),
2284+
proj.term.expect_type(),
22852285
impl_sig.output(),
22862286
)
22872287
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
267267
.explicit_item_bounds(future_ty.def_id)
268268
.iter_instantiated_copied(tcx, future_ty.args)
269269
.find_map(|(clause, _)| match clause.kind().no_bound_vars()? {
270-
ty::ClauseKind::Projection(proj) => proj.term.ty(),
270+
ty::ClauseKind::Projection(proj) => proj.term.as_type(),
271271
_ => None,
272272
})
273273
else {

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ fn fn_sig_suggestion<'tcx>(
441441
output = if let ty::Alias(_, alias_ty) = *output.kind() {
442442
tcx.explicit_item_super_predicates(alias_ty.def_id)
443443
.iter_instantiated_copied(tcx, alias_ty.args)
444-
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
444+
.find_map(|(bound, _)| {
445+
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()
446+
})
445447
.unwrap_or_else(|| {
446448
span_bug!(
447449
ident.span,

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
485485
};
486486

487487
// Since this is a return parameter type it is safe to unwrap.
488-
let ret_param_ty = projection.skip_binder().term.ty().unwrap();
488+
let ret_param_ty = projection.skip_binder().term.expect_type();
489489
let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
490490
debug!(?ret_param_ty);
491491

@@ -956,7 +956,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
956956
let output_ty = self.resolve_vars_if_possible(predicate.term);
957957
debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty);
958958
// This is a projection on a Fn trait so will always be a type.
959-
Some(output_ty.ty().unwrap())
959+
Some(output_ty.expect_type())
960960
}
961961

962962
/// Converts the types that the user supplied, in case that doing

compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
160160
{
161161
// If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
162162
// we need to make it into one.
163-
if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
163+
if let Some(vid) = predicate.term.as_type().and_then(|ty| ty.ty_vid()) {
164164
debug!("infer_var_info: {:?}.output = true", vid);
165165
infer_var_info.entry(vid).or_default().output = true;
166166
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> InferCtxt<'tcx> {
425425
ty::ClauseKind::Projection(projection_predicate)
426426
if projection_predicate.projection_term.def_id == item_def_id =>
427427
{
428-
projection_predicate.term.ty()
428+
projection_predicate.term.as_type()
429429
}
430430
_ => None,
431431
})

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ pub enum ValuePairs<'tcx> {
424424
impl<'tcx> ValuePairs<'tcx> {
425425
pub fn ty(&self) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
426426
if let ValuePairs::Terms(ExpectedFound { expected, found }) = self
427-
&& let Some(expected) = expected.ty()
428-
&& let Some(found) = found.ty()
427+
&& let Some(expected) = expected.as_type()
428+
&& let Some(found) = found.as_type()
429429
{
430430
Some((expected, found))
431431
} else {

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
8383
};
8484
// Only check types, since those are the only things that may
8585
// have opaques in them anyways.
86-
let Some(proj_term) = proj.term.ty() else { return };
86+
let Some(proj_term) = proj.term.as_type() else { return };
8787

8888
// HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"...
8989
if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind()

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,14 +624,22 @@ impl<'tcx> Term<'tcx> {
624624
}
625625
}
626626

627-
pub fn ty(&self) -> Option<Ty<'tcx>> {
627+
pub fn as_type(&self) -> Option<Ty<'tcx>> {
628628
if let TermKind::Ty(ty) = self.unpack() { Some(ty) } else { None }
629629
}
630630

631-
pub fn ct(&self) -> Option<Const<'tcx>> {
631+
pub fn expect_type(&self) -> Ty<'tcx> {
632+
self.as_type().expect("expected a type, but found a const")
633+
}
634+
635+
pub fn as_const(&self) -> Option<Const<'tcx>> {
632636
if let TermKind::Const(c) = self.unpack() { Some(c) } else { None }
633637
}
634638

639+
pub fn expect_const(&self) -> Const<'tcx> {
640+
self.as_const().expect("expected a const, but found a type")
641+
}
642+
635643
pub fn into_arg(self) -> GenericArg<'tcx> {
636644
match self.unpack() {
637645
TermKind::Ty(ty) => ty.into(),

0 commit comments

Comments
 (0)