Skip to content

Commit 5006fc8

Browse files
Align Term methods with GenericArg methods
1 parent debd22d commit 5006fc8

File tree

22 files changed

+45
-35
lines changed

22 files changed

+45
-35
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
@@ -2250,7 +2250,7 @@ fn try_report_async_mismatch<'tcx>(
22502250
&& let Some(proj) = proj.no_bound_vars()
22512251
&& infcx.can_eq(
22522252
error.root_obligation.param_env,
2253-
proj.term.ty().unwrap(),
2253+
proj.term.expect_type(),
22542254
impl_sig.output(),
22552255
)
22562256
{

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
@@ -436,7 +436,9 @@ fn fn_sig_suggestion<'tcx>(
436436
output = if let ty::Alias(_, alias_ty) = *output.kind() {
437437
tcx.explicit_item_super_predicates(alias_ty.def_id)
438438
.iter_instantiated_copied(tcx, alias_ty.args)
439-
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
439+
.find_map(|(bound, _)| {
440+
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()
441+
})
440442
.unwrap_or_else(|| {
441443
span_bug!(
442444
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
@@ -158,7 +158,7 @@ impl<'tcx> TypeckRootCtxt<'tcx> {
158158
{
159159
// If the projection predicate (Foo::Bar == X) has X as a non-TyVid,
160160
// we need to make it into one.
161-
if let Some(vid) = predicate.term.ty().and_then(|ty| ty.ty_vid()) {
161+
if let Some(vid) = predicate.term.as_type().and_then(|ty| ty.ty_vid()) {
162162
debug!("infer_var_info: {:?}.output = true", vid);
163163
infer_var_info.entry(vid).or_default().output = true;
164164
}

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
@@ -626,14 +626,22 @@ impl<'tcx> Term<'tcx> {
626626
}
627627
}
628628

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

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

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

0 commit comments

Comments
 (0)