From f396888c4d816f7d0980aba041014169dd71a2a7 Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 11 Jan 2022 19:18:18 +0000 Subject: [PATCH] Update w/ comments Removes uses of ty() where a method is implemented on TypeFoldable, and also directly formats a Term. --- compiler/rustc_middle/src/ty/print/pretty.rs | 8 +++++++- compiler/rustc_middle/src/ty/sty.rs | 7 +++---- compiler/rustc_privacy/src/lib.rs | 10 ++-------- .../rustc_trait_selection/src/traits/auto_trait.rs | 3 +-- compiler/rustc_typeck/src/check/closure.rs | 2 +- compiler/rustc_typeck/src/check/method/suggest.rs | 9 +++------ compiler/rustc_typeck/src/check/mod.rs | 5 +---- .../src/impl_wf_check/min_specialization.rs | 2 +- src/librustdoc/clean/types.rs | 5 +---- src/tools/clippy/clippy_lints/src/methods/mod.rs | 2 +- 10 files changed, 21 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 6fcb6ac5f4c..c6b03739927 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -905,7 +905,13 @@ pub trait PrettyPrinter<'tcx>: } for (assoc_item_def_id, term) in assoc_items { - let ty = if let Term::Ty(ty) = term.skip_binder() { ty } else { continue }; + let ty = match term.skip_binder() { + Term::Ty(ty) => ty, + Term::Const(c) => { + p!(print(c)); + continue; + } + }; if !first { p!(", "); } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 453e380f6e3..ffc339f3588 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1580,10 +1580,9 @@ impl<'tcx> ExistentialProjection<'tcx> { ) -> Self { // Assert there is a Self. projection_predicate.projection_ty.substs.type_at(0); - let ty = if let Term::Ty(ty) = projection_predicate.term { - ty - } else { - panic!("Only types are permitted here"); + let ty = match projection_predicate.term { + Term::Ty(ty) => ty, + Term::Const(_c) => unimplemented!(), }; Self { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 73873c8cf0d..66767e2b81f 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -128,10 +128,7 @@ where polarity: _, }) => self.visit_trait(trait_ref), ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => { - match term { - ty::Term::Ty(ty) => ty.visit_with(self)?, - ty::Term::Const(ct) => ct.visit_with(self)?, - } + term.visit_with(self)?; self.visit_projection_ty(projection_ty) } ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => { @@ -1189,10 +1186,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { for (poly_predicate, _) in bounds.projection_bounds { let pred = poly_predicate.skip_binder(); - let poly_pred_term = match pred.term { - ty::Term::Ty(ty) => self.visit(ty), - ty::Term::Const(ct) => self.visit(ct), - }; + let poly_pred_term = self.visit(pred.term); if poly_pred_term.is_break() || self.visit_projection_ty(pred.projection_ty).is_break() { diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index cc20c117945..8a33d26fa86 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -779,8 +779,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { // However, we should always make progress (either by generating // subobligations or getting an error) when we started off with // inference variables - if p.term().skip_binder().ty().map_or(false, |ty| ty.has_infer_types()) - { + if p.term().skip_binder().ty().has_infer_types() { panic!("Unexpected result when selecting {:?} {:?}", ty, obligation) } } diff --git a/compiler/rustc_typeck/src/check/closure.rs b/compiler/rustc_typeck/src/check/closure.rs index 504807e87b6..e88099afa03 100644 --- a/compiler/rustc_typeck/src/check/closure.rs +++ b/compiler/rustc_typeck/src/check/closure.rs @@ -709,7 +709,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // does not have any regions in it. let output_ty = self.resolve_vars_if_possible(predicate.term); debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty); - // FIXME(...): How to handle consts here? Will this always be a const? + // This is a projection on a Fn trait so will always be a type. Some(output_ty.ty().unwrap()) } diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index bf362357ed0..56f4d5afe40 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -789,13 +789,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { item_def_id: projection_ty.item_def_id, }; - let fmt = match pred.skip_binder().term { - ty::Term::Ty(ty) => format!("{}", ty), - ty::Term::Const(c) => format!("{}", c), - }; + let term = pred.skip_binder().term; - let obligation = format!("{} = {}", projection_ty, fmt); - let quiet = format!("{} = {}", quiet_projection_ty, fmt); + let obligation = format!("{} = {}", projection_ty, term); + let quiet = format!("{} = {}", quiet_projection_ty, term); bound_span_label(projection_ty.self_ty(), &obligation, &quiet); Some((obligation, projection_ty.self_ty())) diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 9f67713d585..f748b88d90c 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -694,10 +694,7 @@ fn bounds_from_generic_predicates<'tcx>( where_clauses.push(format!( "{} = {}", tcx.def_path_str(p.projection_ty.item_def_id), - match p.term { - ty::Term::Ty(ty) => format!("{}", ty), - ty::Term::Const(c) => format!("{}", c), - } + p.term, )); } let where_clauses = if where_clauses.is_empty() { diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 5e6704c9864..d87e670a8fb 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -199,7 +199,7 @@ fn unconstrained_parent_impl_substs<'tcx>( for (predicate, _) in impl_generic_predicates.predicates.iter() { if let ty::PredicateKind::Projection(proj) = predicate.kind().skip_binder() { let projection_ty = proj.projection_ty; - let projected_ty = proj.term.ty(); + let projected_ty = proj.term; let unbound_trait_ref = projection_ty.trait_ref(tcx); if Some(unbound_trait_ref) == impl_trait_ref { diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index ba771c0c1a1..fac1a0817e0 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1309,10 +1309,7 @@ impl FnDecl { GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => { let bindings = trait_.bindings().unwrap(); let ret_ty = bindings[0].term(); - let ty = match ret_ty { - Term::Type(ty) => ty, - Term::Constant(_c) => unreachable!(), - }; + let ty = ret_ty.ty().expect("Unexpected constant return term"); FnRetTy::Return(ty.clone()) } _ => panic!("unexpected desugaring of async function"), diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index ca8bbbd8f91..d5b928de4a8 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -2143,7 +2143,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods { if let ty::PredicateKind::Projection(projection_predicate) = predicate.kind().skip_binder() { let assoc_ty = match projection_predicate.term { ty::Term::Ty(ty) => ty, - ty::Term::Const(c) => c.ty, + ty::Term::Const(_c) => continue, }; // walk the associated type and check for Self if let Some(self_adt) = self_ty.ty_adt_def() {