Skip to content

Commit f396888

Browse files
committed
Update w/ comments
Removes uses of ty() where a method is implemented on TypeFoldable, and also directly formats a Term.
1 parent e7529d6 commit f396888

File tree

10 files changed

+21
-32
lines changed

10 files changed

+21
-32
lines changed

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,13 @@ pub trait PrettyPrinter<'tcx>:
905905
}
906906

907907
for (assoc_item_def_id, term) in assoc_items {
908-
let ty = if let Term::Ty(ty) = term.skip_binder() { ty } else { continue };
908+
let ty = match term.skip_binder() {
909+
Term::Ty(ty) => ty,
910+
Term::Const(c) => {
911+
p!(print(c));
912+
continue;
913+
}
914+
};
909915
if !first {
910916
p!(", ");
911917
}

Diff for: compiler/rustc_middle/src/ty/sty.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,9 @@ impl<'tcx> ExistentialProjection<'tcx> {
15801580
) -> Self {
15811581
// Assert there is a Self.
15821582
projection_predicate.projection_ty.substs.type_at(0);
1583-
let ty = if let Term::Ty(ty) = projection_predicate.term {
1584-
ty
1585-
} else {
1586-
panic!("Only types are permitted here");
1583+
let ty = match projection_predicate.term {
1584+
Term::Ty(ty) => ty,
1585+
Term::Const(_c) => unimplemented!(),
15871586
};
15881587

15891588
Self {

Diff for: compiler/rustc_privacy/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ where
128128
polarity: _,
129129
}) => self.visit_trait(trait_ref),
130130
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
131-
match term {
132-
ty::Term::Ty(ty) => ty.visit_with(self)?,
133-
ty::Term::Const(ct) => ct.visit_with(self)?,
134-
}
131+
term.visit_with(self)?;
135132
self.visit_projection_ty(projection_ty)
136133
}
137134
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
@@ -1189,10 +1186,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
11891186

11901187
for (poly_predicate, _) in bounds.projection_bounds {
11911188
let pred = poly_predicate.skip_binder();
1192-
let poly_pred_term = match pred.term {
1193-
ty::Term::Ty(ty) => self.visit(ty),
1194-
ty::Term::Const(ct) => self.visit(ct),
1195-
};
1189+
let poly_pred_term = self.visit(pred.term);
11961190
if poly_pred_term.is_break()
11971191
|| self.visit_projection_ty(pred.projection_ty).is_break()
11981192
{

Diff for: compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
779779
// However, we should always make progress (either by generating
780780
// subobligations or getting an error) when we started off with
781781
// inference variables
782-
if p.term().skip_binder().ty().map_or(false, |ty| ty.has_infer_types())
783-
{
782+
if p.term().skip_binder().ty().has_infer_types() {
784783
panic!("Unexpected result when selecting {:?} {:?}", ty, obligation)
785784
}
786785
}

Diff for: compiler/rustc_typeck/src/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
709709
// does not have any regions in it.
710710
let output_ty = self.resolve_vars_if_possible(predicate.term);
711711
debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty);
712-
// FIXME(...): How to handle consts here? Will this always be a const?
712+
// This is a projection on a Fn trait so will always be a type.
713713
Some(output_ty.ty().unwrap())
714714
}
715715

Diff for: compiler/rustc_typeck/src/check/method/suggest.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
789789
item_def_id: projection_ty.item_def_id,
790790
};
791791

792-
let fmt = match pred.skip_binder().term {
793-
ty::Term::Ty(ty) => format!("{}", ty),
794-
ty::Term::Const(c) => format!("{}", c),
795-
};
792+
let term = pred.skip_binder().term;
796793

797-
let obligation = format!("{} = {}", projection_ty, fmt);
798-
let quiet = format!("{} = {}", quiet_projection_ty, fmt);
794+
let obligation = format!("{} = {}", projection_ty, term);
795+
let quiet = format!("{} = {}", quiet_projection_ty, term);
799796

800797
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
801798
Some((obligation, projection_ty.self_ty()))

Diff for: compiler/rustc_typeck/src/check/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,7 @@ fn bounds_from_generic_predicates<'tcx>(
694694
where_clauses.push(format!(
695695
"{} = {}",
696696
tcx.def_path_str(p.projection_ty.item_def_id),
697-
match p.term {
698-
ty::Term::Ty(ty) => format!("{}", ty),
699-
ty::Term::Const(c) => format!("{}", c),
700-
}
697+
p.term,
701698
));
702699
}
703700
let where_clauses = if where_clauses.is_empty() {

Diff for: compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ fn unconstrained_parent_impl_substs<'tcx>(
199199
for (predicate, _) in impl_generic_predicates.predicates.iter() {
200200
if let ty::PredicateKind::Projection(proj) = predicate.kind().skip_binder() {
201201
let projection_ty = proj.projection_ty;
202-
let projected_ty = proj.term.ty();
202+
let projected_ty = proj.term;
203203

204204
let unbound_trait_ref = projection_ty.trait_ref(tcx);
205205
if Some(unbound_trait_ref) == impl_trait_ref {

Diff for: src/librustdoc/clean/types.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1309,10 +1309,7 @@ impl FnDecl {
13091309
GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => {
13101310
let bindings = trait_.bindings().unwrap();
13111311
let ret_ty = bindings[0].term();
1312-
let ty = match ret_ty {
1313-
Term::Type(ty) => ty,
1314-
Term::Constant(_c) => unreachable!(),
1315-
};
1312+
let ty = ret_ty.ty().expect("Unexpected constant return term");
13161313
FnRetTy::Return(ty.clone())
13171314
}
13181315
_ => panic!("unexpected desugaring of async function"),

Diff for: src/tools/clippy/clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21432143
if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() {
21442144
let assoc_ty = match projection_predicate.term {
21452145
ty::Term::Ty(ty) => ty,
2146-
ty::Term::Const(c) => c.ty,
2146+
ty::Term::Const(_c) => continue,
21472147
};
21482148
// walk the associated type and check for Self
21492149
if let Some(self_adt) = self_ty.ty_adt_def() {

0 commit comments

Comments
 (0)