diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-03-15 03:21:55 +0100 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2024-03-22 06:31:40 +0100 |
| commit | 05d48b936f3733ff1d64de91a47465682603b133 (patch) | |
| tree | 3711627febd3ecf04737257c318d3f6643495f21 | |
| parent | b57a10c39d2a2da7389d029595d7fff6ac9cbf5a (diff) | |
Rename AstConv to HIR ty lowering
This includes updating astconv-related items and a few local variables.
35 files changed, 371 insertions, 402 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs index 7a5cb6e9d6f..dd11f58ca19 100644 --- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs +++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs @@ -12,13 +12,13 @@ use rustc_trait_selection::traits; use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; use smallvec::SmallVec; -use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter}; +use crate::astconv::{HirTyLowerer, OnlySelfBounds, PredicateFilter}; use crate::bounds::Bounds; use crate::errors; -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// Sets `implicitly_sized` to true on `Bounds` if necessary - pub(crate) fn add_implicitly_sized( + pub(crate) fn add_sized_bound( &self, bounds: &mut Bounds<'tcx>, self_ty: Ty<'tcx>, @@ -117,7 +117,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref` /// for more details. #[instrument(level = "debug", skip(self, ast_bounds, bounds))] - pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>( + pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>( &self, param_ty: Ty<'tcx>, ast_bounds: I, @@ -145,7 +145,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } hir::TraitBoundModifier::Maybe => continue, }; - let _ = self.instantiate_poly_trait_ref( + let _ = self.lower_poly_trait_ref( &poly_trait_ref.trait_ref, poly_trait_ref.span, constness, @@ -156,7 +156,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ); } hir::GenericBound::Outlives(lifetime) => { - let region = self.ast_region_to_region(lifetime, None); + let region = self.lower_lifetime(lifetime, None); bounds.push_region_bound( self.tcx(), ty::Binder::bind_with_vars( @@ -186,7 +186,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`. /// /// `span` should be the declaration size of the parameter. - pub(crate) fn compute_bounds( + pub(crate) fn lower_mono_bounds( &self, param_ty: Ty<'tcx>, ast_bounds: &[hir::GenericBound<'tcx>], @@ -201,7 +201,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => OnlySelfBounds(true), }; - self.add_bounds( + self.lower_poly_bounds( param_ty, ast_bounds.iter().filter(|bound| match filter { PredicateFilter::All @@ -234,7 +234,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside* /// the binder (e.g., `&'a u32`) and hence may reference bound regions. #[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))] - pub(super) fn add_predicates_for_ast_type_binding( + pub(super) fn lower_assoc_item_binding( &self, hir_ref_id: hir::HirId, trait_ref: ty::PolyTraitRef<'tcx>, @@ -272,7 +272,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ty::AssocKind::Type }; - let candidate = if self.trait_defines_associated_item_named( + let candidate = if self.probe_trait_that_defines_assoc_item( trait_ref.def_id(), assoc_kind, binding.ident, @@ -282,7 +282,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } else { // Otherwise, we have to walk through the supertraits to find // one that does define it. - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || traits::supertraits(tcx, trait_ref), trait_ref.skip_binder().print_only_trait_name(), None, @@ -417,7 +417,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { infer_args: false, }; - let alias_args = self.create_args_for_associated_item( + let alias_args = self.lower_generic_args_of_assoc_item( path_span, assoc_item.def_id, &item_segment, @@ -451,7 +451,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } hir::TypeBindingKind::Equality { term } => { let term = match term { - hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(), + hir::Term::Ty(ty) => self.lower_ty(ty).into(), hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(), }; @@ -514,7 +514,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // for the `Self` type. if !only_self_bounds.0 { let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder()); - self.add_bounds( + self.lower_poly_bounds( param_ty, ast_bounds.iter(), bounds, diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 68896768e8d..bae427a8c84 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -1,4 +1,4 @@ -use crate::astconv::AstConv; +use crate::astconv::HirTyLowerer; use crate::errors::{ self, AssocTypeBindingNotAllowed, ManualImplementation, MissingTypeParams, ParenthesizedFnTraitExpansion, @@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Ident}; use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_trait_selection::traits::object_safety_violations_for_assoc_item; -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// On missing type parameters, emit an E0393 error and provide a structured suggestion using /// the type parameter's name as a placeholder. pub(crate) fn complain_about_missing_type_params( @@ -311,7 +311,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // FIXME(associated_const_equality): This has quite a few false positives and negatives. let wrap_in_braces_sugg = if let Some(binding) = binding && let hir::TypeBindingKind::Equality { term: hir::Term::Ty(hir_ty) } = binding.kind - && let ty = self.ast_ty_to_ty(hir_ty) + && let ty = self.lower_ty(hir_ty) && (ty.is_enum() || ty.references_error()) && tcx.features().associated_const_equality { @@ -349,7 +349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }) } - pub(super) fn report_ambiguous_associated_type( + pub(super) fn report_ambiguous_assoc_ty( &self, span: Span, types: &[String], @@ -458,7 +458,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { reported } - pub(crate) fn complain_about_ambiguous_inherent_assoc_type( + pub(crate) fn complain_about_ambiguous_inherent_assoc_ty( &self, name: Ident, candidates: Vec<DefId>, @@ -471,14 +471,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { "multiple applicable items in scope" ); err.span_label(name.span, format!("multiple `{name}` found")); - self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span); + self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span); let reported = err.emit(); self.set_tainted_by_errors(reported); reported } // FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate. - fn note_ambiguous_inherent_assoc_type( + fn note_ambiguous_inherent_assoc_ty( &self, err: &mut Diag<'_>, candidates: Vec<DefId>, @@ -521,7 +521,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } // FIXME(inherent_associated_types): Find similarly named associated types and suggest them. - pub(crate) fn complain_about_inherent_assoc_type_not_found( + pub(crate) fn complain_about_inherent_assoc_ty_not_found( &self, name: Ident, self_ty: Ty<'tcx>, @@ -697,7 +697,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// reasonable suggestion on how to write it. For the case of multiple associated types in the /// same trait bound have the same name (as they come from different supertraits), we instead /// emit a generic note suggesting using a `where` clause to constraint instead. - pub(crate) fn complain_about_missing_associated_types( + pub(crate) fn complain_about_missing_assoc_tys( &self, associated_types: FxIndexMap<Span, FxIndexSet<DefId>>, potential_assoc_types: Vec<Span>, @@ -1027,7 +1027,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } /// Emits an error regarding forbidden type binding associations -pub fn prohibit_assoc_ty_binding( +pub fn prohibit_assoc_item_binding( tcx: TyCtxt<'_>, span: Span, segment: Option<(&hir::PathSegment<'_>, Span)>, diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index 42e303c10ea..9ad6fec22ac 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -1,7 +1,7 @@ use super::IsMethodCall; use crate::astconv::{ - errors::prohibit_assoc_ty_binding, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, - GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition, + errors::prohibit_assoc_item_binding, ExplicitLateBound, GenericArgCountMismatch, + GenericArgCountResult, GenericArgPosition, GenericArgsLowerer, }; use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs}; use rustc_ast::ast::ParamKindOrd; @@ -172,14 +172,14 @@ fn generic_arg_mismatch_err( /// instantiate a `GenericArg`. /// - `inferred_kind`: if no parameter was provided, and inference is enabled, then /// creates a suitable inference variable. -pub fn create_args_for_parent_generic_args<'tcx: 'a, 'a>( +pub fn lower_generic_args<'tcx: 'a, 'a>( tcx: TyCtxt<'tcx>, def_id: DefId, parent_args: &[ty::GenericArg<'tcx>], has_self: bool, self_ty: Option<Ty<'tcx>>, arg_count: &GenericArgCountResult, - ctx: &mut impl CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>, + ctx: &mut impl GenericArgsLowerer<'a, 'tcx>, ) -> GenericArgsRef<'tcx> { // Collect the segments of the path; we need to instantiate arguments // for parameters throughout the entire path (wherever there are @@ -456,7 +456,7 @@ pub(crate) fn check_generic_arg_count( if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() { - prohibit_assoc_ty_binding(tcx, b.span, None); + prohibit_assoc_item_binding(tcx, b.span, None); } let explicit_late_bound = diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/astconv/lint.rs index b421a33ba29..80be563686a 100644 --- a/compiler/rustc_hir_analysis/src/astconv/lint.rs +++ b/compiler/rustc_hir_analysis/src/astconv/lint.rs @@ -6,9 +6,9 @@ use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName; -use super::AstConv; +use super::HirTyLowerer; -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// Make sure that we are in the condition to suggest the blanket implementation. pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>( &self, diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index a912d7f578d..14864da1e39 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -8,8 +8,8 @@ pub mod generics; mod lint; mod object_safety; -use crate::astconv::errors::prohibit_assoc_ty_binding; -use crate::astconv::generics::{check_generic_arg_count, create_args_for_parent_generic_args}; +use crate::astconv::errors::prohibit_assoc_item_binding; +use crate::astconv::generics::{check_generic_arg_count, lower_generic_args}; use crate::bounds::Bounds; use crate::collect::HirPlaceholderCollector; use crate::errors::AmbiguousLifetimeBound; @@ -44,7 +44,7 @@ use std::fmt::Display; use std::slice; #[derive(Debug)] -pub struct PathSeg(pub DefId, pub usize); +pub struct GenericPathSegment(pub DefId, pub usize); #[derive(Copy, Clone, Debug)] pub struct OnlySelfBounds(pub bool); @@ -67,7 +67,7 @@ pub enum PredicateFilter { SelfAndAssociatedTypeBounds, } -pub trait AstConv<'tcx> { +pub trait HirTyLowerer<'tcx> { fn tcx(&self) -> TyCtxt<'tcx>; fn item_def_id(&self) -> DefId; @@ -84,7 +84,7 @@ pub trait AstConv<'tcx> { /// but this can lead to cycle errors. The problem is that we have /// to do this resolution *in order to create the predicates in /// the first place*. Hence, we have this "special pass". - fn get_type_parameter_bounds( + fn probe_ty_param_bounds( &self, span: Span, def_id: LocalDefId, @@ -99,7 +99,7 @@ pub trait AstConv<'tcx> { fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>; /// Returns `true` if `_` is allowed in type signatures in the current context. - fn allow_ty_infer(&self) -> bool; + fn allow_infer(&self) -> bool; /// Returns the const to use when a const is omitted. fn ct_infer( @@ -116,7 +116,7 @@ pub trait AstConv<'tcx> { /// signatures for that reason. In a function body, we can always /// handle it because we can use inference variables to remove the /// late-bound regions. - fn projected_ty_from_poly_trait_ref( + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -139,7 +139,7 @@ pub trait AstConv<'tcx> { fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span); - fn astconv(&self) -> &dyn AstConv<'tcx> + fn lowerer(&self) -> &dyn HirTyLowerer<'tcx> where Self: Sized, { @@ -197,7 +197,7 @@ pub struct GenericArgCountResult { pub correct: Result<(), GenericArgCountMismatch>, } -pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> { +pub trait GenericArgsLowerer<'a, 'tcx> { fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool); fn provided_kind( @@ -214,9 +214,9 @@ pub trait CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> { ) -> ty::GenericArg<'tcx>; } -impl<'tcx> dyn AstConv<'tcx> + '_ { +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { #[instrument(level = "debug", skip(self), ret)] - pub fn ast_region_to_region( + pub fn lower_lifetime( &self, lifetime: &hir::Lifetime, def: Option<&ty::GenericParamDef>, @@ -273,13 +273,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// Given a path `path` that refers to an item `I` with the declared generics `decl_generics`, /// returns an appropriate set of generic arguments for this particular reference to `I`. - pub fn ast_path_args_for_ty( + pub fn lower_generic_args_of_path_segment( &self, span: Span, def_id: DefId, item_segment: &hir::PathSegment<'tcx>, ) -> GenericArgsRef<'tcx> { - let (args, _) = self.create_args_for_ast_path( + let (args, _) = self.lower_generic_args_of_path( span, def_id, &[], @@ -288,9 +288,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ty::BoundConstness::NotConst, ); if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); } - args } @@ -328,7 +327,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// type itself: `['a]`. The returned `GenericArgsRef` concatenates these two /// lists: `[Vec<u8>, u8, 'a]`. #[instrument(level = "debug", skip(self, span), ret)] - fn create_args_for_ast_path( + fn lower_generic_args_of_path( &self, span: Span, def_id: DefId, @@ -381,8 +380,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { return (tcx.mk_args(parent_args), arg_count); } - struct InstantiationsForAstPathCtxt<'a, 'tcx> { - astconv: &'a dyn AstConv<'tcx>, + struct GenericArgsCtxt<'a, 'tcx> { + lowerer: &'a dyn HirTyLowerer<'tcx>, def_id: DefId, generic_args: &'a GenericArgs<'tcx>, span: Span, @@ -390,9 +389,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { infer_args: bool, } - impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for InstantiationsForAstPathCtxt<'a, 'tcx> - { + impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> { fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool) { if did == self.def_id { (Some(self.generic_args), self.infer_args) @@ -407,7 +404,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { param: &ty::GenericParamDef, arg: &GenericArg<'tcx>, ) -> ty::GenericArg<'tcx> { - let tcx = self.astconv.tcx(); + let tcx = self.lowerer.tcx(); let mut handle_ty_args = |has_default, ty: &hir::Ty<'tcx>| { if has_default { @@ -426,17 +423,17 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }, ); } - if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) { + if let (hir::TyKind::Infer, false) = (&ty.kind, self.lowerer.allow_infer()) { self.inferred_params.push(ty.span); Ty::new_misc_error(tcx).into() } else { - self.astconv.ast_ty_to_ty(ty).into() + self.lowerer.lower_ty(ty).into() } }; match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.astconv.ast_region_to_region(lt, Some(param)).into() + self.lowerer.lower_lifetime(lt, Some(param)).into() } (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => { handle_ty_args(has_default, ty) @@ -455,8 +452,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .type_of(param.def_id) .no_bound_vars() .expect("const parameter types cannot be generic"); - if self.astconv.allow_ty_infer() { - self.astconv.ct_infer(ty, Some(param), inf.span).into() + if self.lowerer.allow_infer() { + self.lowerer.ct_infer(ty, Some(param), inf.span).into() } else { self.inferred_params.push(inf.span); ty::Const::new_misc_error(tcx, ty).into() @@ -475,10 +472,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { param: &ty::GenericParamDef, infer_args: bool, ) -> ty::GenericArg<'tcx> { - let tcx = self.astconv.tcx(); + let tcx = self.lowerer.tcx(); match param.kind { GenericParamDefKind::Lifetime => self - .astconv + .lowerer .re_infer(Some(param), self.span) .unwrap_or_else(|| { debug!(?param, "unelided lifetime in signature"); @@ -504,7 +501,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } tcx.at(self.span).type_of(param.def_id).instantiate(tcx, args).into() } else if infer_args { - self.astconv.ty_infer(Some(param), self.span).into() + self.lowerer.ty_infer(Some(param), self.span).into() } else { // We've already errored above about the mismatch. Ty::new_misc_error(tcx).into() @@ -526,7 +523,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .into() } else { if infer_args { - self.astconv.ct_infer(ty, Some(param), self.span).into() + self.lowerer.ct_infer(ty, Some(param), self.span).into() } else { // We've already errored above about the mismatch. ty::Const::new_misc_error(tcx, ty).into() @@ -537,8 +534,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - let mut args_ctx = InstantiationsForAstPathCtxt { - astconv: self, + let mut args_ctx = GenericArgsCtxt { + lowerer: self, def_id, span, generic_args: segment.args(), @@ -557,7 +554,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { arg_count.correct = Err(GenericArgCountMismatch { reported: Some(e), invalid_args: vec![] }); } - let args = create_args_for_parent_generic_args( + let args = lower_generic_args( tcx, def_id, parent_args, @@ -570,7 +567,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { (args, arg_count) } - pub fn create_args_for_associated_item( + pub fn lower_generic_args_of_assoc_item( &self, span: Span, item_def_id: DefId, @@ -581,7 +578,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { "create_args_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}", span, item_def_id, item_segment ); - let (args, _) = self.create_args_for_ast_path( + let (args, _) = self.lower_generic_args_of_path( span, item_def_id, parent_args, @@ -589,9 +586,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { None, ty::BoundConstness::NotConst, ); - if let Some(b) = item_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((item_segment, span))); } args @@ -603,14 +599,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// /// If the `projections` argument is `None`, then assoc type bindings like `Foo<T = X>` /// are disallowed. Otherwise, they are pushed onto the vector given. - pub fn instantiate_mono_trait_ref( + pub fn lower_impl_trait_ref( &self, trait_ref: &hir::TraitRef<'tcx>, self_ty: Ty<'tcx>, ) -> ty::TraitRef<'tcx> { - self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); + self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); - self.ast_path_to_mono_trait_ref( + self.lower_mono_trait_ref( trait_ref.path.span, trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()), self_ty, @@ -640,7 +636,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly, /// however. #[instrument(level = "debug", skip(self, span, constness, bounds))] - pub(crate) fn instantiate_poly_trait_ref( + pub(crate) fn lower_poly_trait_ref( &self, trait_ref: &hir::TraitRef<'tcx>, span: Span, @@ -653,10 +649,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()); let trait_segment = trait_ref.path.segments.last().unwrap(); - self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); + self.prohibit_generic_args(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {}); self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, false); - let (generic_args, arg_count) = self.create_args_for_ast_path( + let (generic_args, arg_count) = self.lower_generic_args_of_path( trait_ref.path.span, trait_def_id, &[], @@ -691,7 +687,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } // Specify type to assert that error was already reported in `Err` case. - let _: Result<_, ErrorGuaranteed> = self.add_predicates_for_ast_type_binding( + let _: Result<_, ErrorGuaranteed> = self.lower_assoc_item_binding( trait_ref.hir_ref_id, poly_trait_ref, binding, @@ -706,7 +702,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { arg_count } - fn ast_path_to_mono_trait_ref( + fn lower_mono_trait_ref( &self, span: Span, trait_def_id: DefId, @@ -718,7 +714,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ) -> ty::TraitRef<'tcx> { self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl); - let (generic_args, _) = self.create_args_for_ast_path( + let (generic_args, _) = self.lower_generic_args_of_path( span, trait_def_id, &[], @@ -727,12 +723,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { constness, ); if let Some(b) = trait_segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, Some((trait_segment, span))); + prohibit_assoc_item_binding(self.tcx(), b.span, Some((trait_segment, span))); } ty::TraitRef::new(self.tcx(), trait_def_id, generic_args) } - fn trait_defines_associated_item_named( + fn probe_trait_that_defines_assoc_item( &self, trait_def_id: DefId, assoc_kind: ty::AssocKind, @@ -744,14 +740,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .is_some() } - fn ast_path_to_ty( + fn lower_path_segment( &self, span: Span, did: DefId, item_segment: &hir::PathSegment<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx(); - let args = self.ast_path_args_for_ty(span, did, item_segment); + let args = self.lower_generic_args_of_path_segment(span, did, item_segment); if let DefKind::TyAlias = tcx.def_kind(did) && tcx.type_alias_is_lazy(did) @@ -770,7 +766,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // given by `assoc_name`. `ty_param_def_id` is the `DefId` of the type parameter // This function will fail if there are no suitable bounds or there is // any ambiguity. - fn find_bound_for_assoc_item( + fn probe_single_ty_param_bound_for_assoc_ty( &self, ty_param_def_id: LocalDefId, assoc_name: Ident, @@ -783,13 +779,12 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ty_param_def_id, assoc_name, span, ); - let predicates = - &self.get_type_parameter_bounds(span, ty_param_def_id, assoc_name).predicates; + let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name).predicates; debug!("find_bound_for_assoc_item: predicates={:#?}", predicates); let param_name = tcx.hir().ty_param_name(ty_param_def_id); - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || { traits::transitive_bounds_that_define_assoc_item( tcx, @@ -811,7 +806,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Checks that `bounds` contains exactly one element and reports appropriate // errors otherwise. #[instrument(level = "debug", skip(self, all_candidates, ty_param_name, binding), ret)] - fn one_bound_for_assoc_item<I>( + fn probe_single_bound_for_assoc_item<I>( &self, all_candidates: impl Fn() -> I, ty_param_name: impl Display, @@ -827,7 +822,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let tcx = self.tcx(); let mut matching_candidates = all_candidates().filter(|r| { - self.trait_defines_associated_item_named(r.def_id(), assoc_kind, assoc_name) + self.probe_trait_that_defines_assoc_item(r.def_id(), assoc_kind, assoc_name) }); let Some(bound) = matching_candidates.next() else { @@ -886,7 +881,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { match binding.kind { hir::TypeBindingKind::Equality { term } => { let term: ty::Term<'_> = match term { - hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(), + hir::Term::Ty(ty) => self.lower_ty(ty).into(), hir::Term::Const(ct) => { ty::Const::from_anon_const(tcx, ct.def_id).into() } @@ -941,7 +936,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // NOTE: When this function starts resolving `Trait::AssocTy` successfully // it should also start reporting the `BARE_TRAIT_OBJECTS` lint. #[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)] - pub fn associated_path_to_ty( + pub fn lower_assoc_path( &self, hir_ref_id: hir::HirId, span: Span, @@ -969,7 +964,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { if let Some(variant_def) = variant_def { if permit_variants { tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None); - self.prohibit_generics(slice::from_ref(assoc_segment).iter(), |err| { + self.prohibit_generic_args(slice::from_ref(assoc_segment).iter(), |err| { err.note("enum variants can't have type parameters"); let type_name = tcx.item_name(adt_def.did()); let msg = format!( @@ -1069,7 +1064,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - if let Some((ty, did)) = self.lookup_inherent_assoc_ty( + if let Some((ty, did)) = self.probe_inherent_assoc_ty( assoc_ident, assoc_segment, adt_def.did(), @@ -1092,7 +1087,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { tcx.dcx().span_bug(span, "expected cycle error"); }; - self.one_bound_for_assoc_item( + self.probe_single_bound_for_assoc_item( || { traits::supertraits( tcx, @@ -1110,7 +1105,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { ( &ty::Param(_), Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did), - ) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?, + ) => self.probe_single_ty_param_bound_for_assoc_ty( + param_did.expect_local(), + assoc_ident, + span, + )?, _ => { let reported = if variant_resolution.is_some() { // Variant in type position @@ -1172,7 +1171,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { self.probe_traits_that_match_assoc_ty(qself_ty, assoc_ident); // Don't print `ty::Error` to the user. - self.report_ambiguous_associated_type( + self.report_ambiguous_assoc_ty( span, &[qself_ty.to_string()], &traits, @@ -1185,8 +1184,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }; let trait_did = bound.def_id(); - let assoc_ty_did = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap(); - let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound); + let assoc_ty_did = self.probe_assoc_ty(assoc_ident, hir_ref_id, span, trait_did).unwrap(); + let ty = self.lower_assoc_ty(span, assoc_ty_did, assoc_segment, bound); if let Some(variant_def_id) = variant_resolution { tcx.node_span_lint( @@ -1220,7 +1219,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ok((ty, DefKind::AssocTy, assoc_ty_did)) } - fn lookup_inherent_assoc_ty( + fn probe_inherent_assoc_ty( &self, name: Ident, segment: &hir::PathSegment<'tcx>, @@ -1243,7 +1242,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let candidates: Vec<_> = tcx .inherent_impls(adt_did)? .iter() - .filter_map(|&impl_| Some((impl_, self.lookup_assoc_ty_unchecked(name, block, impl_)?))) + .filter_map(|&impl_| Some((impl_, self.probe_assoc_ty_unchecked(name, block, impl_)?))) .collect(); if candidates.is_empty() { @@ -1293,7 +1292,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // `create_args_for_associated_item`. Modify the latter instead (or sth. similar) to // not require the parent args logic. let parent_args = ty::GenericArgs::identity_for_item(tcx, impl_); - let args = self.create_args_for_associated_item(span, assoc_item, segment, parent_args); + let args = self.lower_generic_args_of_assoc_item(span, assoc_item, segment, parent_args); let args = tcx.mk_args_from_iter( std::iter::once(ty::GenericArg::from(self_ty)) .chain(args.into_iter().skip(parent_args.len())), @@ -1356,7 +1355,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .collect(); match &applicable_candidates[..] { - &[] => Err(self.complain_about_inherent_assoc_type_not_found( + &[] => Err(self.complain_about_inherent_assoc_ty_not_found( name, self_ty, candidates, @@ -1366,7 +1365,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { &[applicable_candidate] => Ok(applicable_candidate), - &[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_type( + &[_, ..] => Err(self.complain_about_ambiguous_inherent_assoc_ty( name, applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(), span, @@ -1374,19 +1373,19 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - fn lookup_assoc_ty( + fn probe_assoc_ty( &self, name: Ident, block: hir::HirId, span: Span, scope: DefId, ) -> Option<DefId> { - let (item, def_scope) = self.lookup_assoc_ty_unchecked(name, block, scope)?; + let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?; self.check_assoc_ty(item, name, def_scope, block, span); Some(item) } - fn lookup_assoc_ty_unchecked( + fn probe_assoc_ty_unchecked( &self, name: Ident, block: hir::HirId, @@ -1491,7 +1490,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .collect() } - fn qpath_to_ty( + fn lower_qpath( &self, span: Span, opt_self_ty: Option<Ty<'tcx>>, @@ -1545,7 +1544,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // FIXME: also look at `tcx.generics_of(self.item_def_id()).params` any that // references the trait. Relevant for the first case in // `src/test/ui/associated-types/associated-types-in-ambiguous-context.rs` - let reported = self.report_ambiguous_associated_type( + let reported = self.report_ambiguous_assoc_ty( span, &type_names, &[path_str], @@ -1556,24 +1555,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { debug!("qpath_to_ty: self_type={:?}", self_ty); - let trait_ref = self.ast_path_to_mono_trait_ref( - span, - trait_def_id, - self_ty, - trait_segment, - false, - constness, - ); + let trait_ref = + self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false, constness); let item_args = - self.create_args_for_associated_item(span, item_def_id, item_segment, trait_ref.args); + self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, trait_ref.args); debug!("qpath_to_ty: trait_ref={:?}", trait_ref); Ty::new_projection(tcx, item_def_id, item_args) } - pub fn prohibit_generics<'a>( + pub fn prohibit_generic_args<'a>( &self, segments: impl Iterator<Item = &'a hir::PathSegment<'a>> + Clone, extend: impl Fn(&mut Diag<'_>), @@ -1676,7 +1669,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { for segment in segments { // Only emit the first error to avoid overloading the user with error messages. if let Some(b) = segment.args().bindings.first() { - prohibit_assoc_ty_binding(self.tcx(), b.span, None); + prohibit_assoc_item_binding(self.tcx(), b.span, None); return true; } } @@ -1684,14 +1677,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } // FIXME(eddyb, varkor) handle type paths here too, not just value ones. - pub fn def_ids_for_value_path_segments( + pub fn probe_generic_path_segments( &self, segments: &[hir::PathSegment<'_>], self_ty: Option<Ty<'tcx>>, kind: DefKind, def_id: DefId, span: Span, - ) -> Vec<PathSeg> { + ) -> Vec<GenericPathSegment> { // We need to extract the type parameters supplied by the user in // the path `path`. Due to the current setup, this is a bit of a // tricky-process; the problem is that resolve only tells us the @@ -1742,7 +1735,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { assert!(!segments.is_empty()); let last = segments.len() - 1; - let mut path_segs = vec![]; + let mut generic_segments = vec![]; match kind { // Case 1. Reference to a struct constructor. @@ -1753,7 +1746,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Variant and struct constructors use the // generics of their parent type definition. let generics_def_id = generics.parent.unwrap_or(def_id); - path_segs.push(PathSeg(generics_def_id, last)); + generic_segments.push(GenericPathSegment(generics_def_id, last)); } // Case 2. Reference to a variant constructor. @@ -1786,33 +1779,33 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // generics of their parent type definition. (generics.parent.unwrap_or(def_id), last) }; - path_segs.push(PathSeg(generics_def_id, index)); + generic_segments.push(GenericPathSegment(generics_def_id, index)); } // Case 3. Reference to a top-level value. DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => { - path_segs.push(PathSeg(def_id, last)); + generic_segments.push(GenericPathSegment(def_id, last)); } // Case 4. Reference to a method or associated const. DefKind::AssocFn | DefKind::AssocConst => { if segments.len() >= 2 { let generics = tcx.generics_of(def_id); - path_segs.push(PathSeg(generics.parent.unwrap(), last - 1)); + generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1)); } - path_segs.push(PathSeg(def_id, last)); + generic_segments.push(GenericPathSegment(def_id, last)); } kind => bug!("unexpected definition kind {:?} for {:?}", kind, def_id), } - debug!("path_segs = {:?}", path_segs); + debug!("path_segs = {:?}", generic_segments); - path_segs + generic_segments } /// Check a type `Path` and convert it to a `Ty`. - pub fn res_to_ty( + pub fn lower_path( &self, opt_self_ty: Option<Ty<'tcx>>, path: &hir::Path<'tcx>, @@ -1832,10 +1825,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Check for desugared `impl Trait`. assert!(tcx.is_type_alias_impl_trait(did)); let item_segment = path.segments.split_last().unwrap(); - self.prohibit_generics(item_segment.1.iter(), |err| { + self.prohibit_generic_args(item_segment.1.iter(), |err| { err.note("`impl Trait` types can't have type parameters"); }); - let args = self.ast_path_args_for_ty(span, did, item_segment.0); + let args = self.lower_generic_args_of_path_segment(span, did, item_segment.0); Ty::new_opaque(tcx, did, args) } Res::Def( @@ -1847,44 +1840,44 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { did, ) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.split_last().unwrap().1.iter(), |_| {}); - self.ast_path_to_ty(span, did, path.segments.last().unwrap()) + self.prohibit_generic_args(path.segments.split_last().unwrap().1.iter(), |_| {}); + self.lower_path_segment(span, did, path.segments.last().unwrap()) } Res::Def(kind @ DefKind::Variant, def_id) if permit_variants => { // Convert "variant type" as if it were a real type. // The resulting `Ty` is type of the variant's enum for now. assert_eq!(opt_self_ty, None); - let path_segs = - self.def_ids_for_value_path_segments(path.segments, None, kind, def_id, span); - let generic_segs: FxHashSet<_> = - path_segs.iter().map(|PathSeg(_, index)| index).collect(); - self.prohibit_generics( + let generic_segments = + self.probe_generic_path_segments(path.segments, None, kind, def_id, span); + let indices: FxHashSet<_> = + generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect(); + self.prohibit_generic_args( path.segments.iter().enumerate().filter_map(|(index, seg)| { - if !generic_segs.contains(&index) { Some(seg) } else { None } + if !indices.contains(&index) { Some(seg) } else { None } }), |err| { err.note("enum variants can't have type parameters"); }, ); - let PathSeg(def_id, index) = path_segs.last().unwrap(); - self.ast_path_to_ty(span, *def_id, &path.segments[*index]) + let GenericPathSegment(def_id, index) = generic_segments.last().unwrap(); + self.lower_path_segment(span, *def_id, &path.segments[*index]) } Res::Def(DefKind::TyParam, def_id) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { if let Some(span) = tcx.def_ident_span(def_id) { let name = tcx.item_name(def_id); err.span_note(span, format!("type parameter `{name}` defined here")); } }); - self.hir_id_to_bound_ty(hir_id) + self.lower_ty_param(hir_id) } Res::SelfTyParam { .. } => { // `Self` in trait or type alias. assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { if let [hir::PathSegment { args: Some(args), ident, .. }] = &path.segments { err.span_suggestion_verbose( ident.span.shrink_to_hi().to(args.span_ext), @@ -1902,7 +1895,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Try to evaluate any array length constants. let ty = tcx.at(span).type_of(def_id).instantiate_identity(); let span_of_impl = tcx.span_of_impl(def_id); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { let def_id = match *ty.kind() { ty::Adt(self_def, _) => self_def.did(), _ => return, @@ -2000,14 +1993,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } Res::Def(DefKind::AssocTy, def_id) => { debug_assert!(path.segments.len() >= 2); - self.prohibit_generics(path.segments[..path.segments.len() - 2].iter(), |_| {}); + self.prohibit_generic_args(path.segments[..path.segments.len() - 2].iter(), |_| {}); // HACK: until we support `<Type as ~const Trait>`, assume all of them are. let constness = if tcx.has_attr(tcx.parent(def_id), sym::const_trait) { ty::BoundConstness::ConstIfConst } else { ty::BoundConstness::NotConst }; - self.qpath_to_ty( + self.lower_qpath( span, opt_self_ty, def_id, @@ -2018,7 +2011,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } Res::PrimTy(prim_ty) => { assert_eq!(opt_self_ty, None); - self.prohibit_generics(path.segments.iter(), |err| { + self.prohibit_generic_args(path.segments.iter(), |err| { let name = prim_ty.name_str(); for segment in path.segments { if let Some(args) = segment.args { @@ -2054,7 +2047,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Converts a hir id corresponding to a type parameter to // a early-bound `ty::Param` or late-bound `ty::Bound`. - pub(crate) fn hir_id_to_bound_ty(&self, hir_id: hir::HirId) -> Ty<'tcx> { + pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => { @@ -2079,11 +2072,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Converts a hir id corresponding to a const parameter to // a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`. - pub(crate) fn hir_id_to_bound_const( - &self, - hir_id: hir::HirId, - param_ty: Ty<'tcx>, - ) -> Const<'tcx> { + pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::EarlyBound(def_id)) => { @@ -2105,14 +2094,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// Parses the programmer's textual representation of a type into our /// internal notion of a type. - pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.ast_ty_to_ty_inner(ast_ty, false, false) + pub fn lower_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lower_ty_common(ast_ty, false, false) } /// Parses the programmer's textual representation of a type into our /// internal notion of a type. This is meant to be used within a path. - pub fn ast_ty_to_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.ast_ty_to_ty_inner(ast_ty, false, true) + pub fn lower_ty_in_path(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lower_ty_common(ast_ty, false, true) } fn check_delegation_constraints(&self, sig_id: DefId, span: Span, emit: bool) -> bool { @@ -2179,7 +2168,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { error_occured } - fn ty_from_delegation( + fn lower_delegation_ty( &self, sig_id: DefId, idx: hir::InferDelegationKind, @@ -2226,31 +2215,26 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { /// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait /// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors. #[instrument(level = "debug", skip(self), ret)] - fn ast_ty_to_ty_inner( - &self, - ast_ty: &hir::Ty<'tcx>, - borrowed: bool, - in_path: bool, - ) -> Ty<'tcx> { + fn lower_ty_common(&self, ast_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> { let tcx = self.tcx(); let result_ty = match &ast_ty.kind { hir::TyKind::InferDelegation(sig_id, idx) => { - self.ty_from_delegation(*sig_id, *idx, ast_ty.span) + self.lower_delegation_ty(*sig_id, *idx, ast_ty.span) } - hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.ast_ty_to_ty(ty)), + hir::TyKind::Slice(ty) => Ty::new_slice(tcx, self.lower_ty(ty)), hir::TyKind::Ptr(mt) => { - Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) + Ty::new_ptr(tcx, ty::TypeAndMut { ty: self.lower_ty(mt.ty), mutbl: mt.mutbl }) } hir::TyKind::Ref(region, mt) => { - let r = self.ast_region_to_region(region, None); + let r = self.lower_lifetime(region, None); debug!(?r); - let t = self.ast_ty_to_ty_inner(mt.ty, true, false); + let t = self.lower_ty_common(mt.ty, true, false); Ty::new_ref(tcx, r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) } hir::TyKind::Never => tcx.types.never, hir::TyKind::Tup(fields) => { - Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.ast_ty_to_ty(t))) + Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t))) } hir::TyKind::AnonAdt(item_id) => { let did = item_id.owner_id.def_id; @@ -2270,7 +2254,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ty::new_fn_ptr( tcx, - self.ty_of_fn(ast_ty.hir_id, bf.unsafety, bf.abi, bf.decl, None, Some(ast_ty)), + self.lower_fn_ty( + ast_ty.hir_id, + bf.unsafety, + bf.abi, + bf.decl, + None, + Some(ast_ty), + ), ) } hir::TyKind::TraitObject(bounds, lifetime, repr) => { @@ -2280,7 +2271,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { TraitObjectSyntax::DynStar => ty::DynStar, }; - self.conv_object_ty_poly_trait_ref( + self.lower_trait_object_ty( ast_ty.span, ast_ty.hir_id, bounds, @@ -2291,8 +2282,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => { debug!(?maybe_qself, ?path); - let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself)); - self.res_to_ty(opt_self_ty, path, ast_ty.hir_id, false) + let opt_self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself)); + self.lower_path(opt_self_ty, path, ast_ty.hir_id, false) } &hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => { let opaque_ty = tcx.hir().item(item_id); @@ -2308,21 +2299,21 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } else { local_def_id.to_def_id() }; - self.impl_trait_ty_to_ty(def_id, lifetimes, in_trait) + self.lower_opaque_ty(def_id, lifetimes, in_trait) } ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i), } } hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => { debug!(?qself, ?segment); - let ty = self.ast_ty_to_ty_inner(qself, false, true); - self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false) + let ty = self.lower_ty_common(qself, false, true); + self.lower_assoc_path(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false) .map(|(ty, _, _)| ty) .unwrap_or_else(|guar| Ty::new_error(tcx, guar)) } &hir::TyKind::Path(hir::QPath::LangItem(lang_item, span)) => { let def_id = tcx.require_lang_item(lang_item, Some(span)); - let (args, _) = self.create_args_for_ast_path( + let (args, _) = self.lower_generic_args_of_path( span, def_id, &[], @@ -2340,7 +2331,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } }; - Ty::new_array_with_const_len(tcx, self.ast_ty_to_ty(ty), length) + Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length) } hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(), hir::TyKind::Infer => { @@ -2358,7 +2349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } #[instrument(level = "debug", skip(self), ret)] - fn impl_trait_ty_to_ty( + fn lower_opaque_ty( &self, def_id: DefId, lifetimes: &[hir::GenericArg<'_>], @@ -2390,7 +2381,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { &lifetimes[i] ) }; - self.ast_region_to_region(lifetime, None).into() + self.lower_lifetime(lifetime, None).into() } else { tcx.mk_param_from_def(param) } @@ -2404,18 +2395,18 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { } } - pub fn ty_of_arg(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> { + pub fn lower_arg_ty(&self, ty: &hir::Ty<'tcx>, expected_ty: Option<Ty<'tcx>>) -> Ty<'tcx> { match ty.kind { hir::TyKind::Infer if let Some(expected_ty) = expected_ty => { self.record_ty(ty.hir_id, expected_ty, ty.span); expected_ty } - _ => self.ast_ty_to_ty(ty), + _ => self.lower_ty(ty), } } #[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)] - pub fn ty_of_fn( + pub fn lower_fn_ty( &self, hir_id: hir::HirId, unsafety: hir::Unsafety, @@ -2448,7 +2439,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { .enumerate() .map(|(i, a)| { if let hir::TyKind::Infer = a.kind - && !self.allow_ty_infer() + && !self.allow_infer() { if let Some(suggested_ty) = self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i)) @@ -2464,14 +2455,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Only visit the type looking for `_` if we didn't fix the type above visitor.visit_ty(a); - self.ty_of_arg(a, None) + self.lower_arg_ty(a, None) }) .collect(); let output_ty = match decl.output { hir::FnRetTy::Return(output) => { if let hir::TyKind::Infer = output.kind - && !self.allow_ty_infer() + && !self.allow_infer() && let Some(suggested_ty) = self.suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None) { @@ -2479,7 +2470,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { Ty::new_error_with_message(self.tcx(), output.span, suggested_ty.to_string()) } else { visitor.visit_ty(output); - self.ast_ty_to_ty(output) + self.lower_ty(output) } } hir::FnRetTy::DefaultReturn(..) => Ty::new_unit(tcx), @@ -2490,7 +2481,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi); let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars); - if !self.allow_ty_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) { + if !self.allow_infer() && !(visitor.0.is_empty() && infer_replacements.is_empty()) { // We always collect the spans for placeholder types when evaluating `fn`s, but we // only want to emit an error complaining about them if infer types (`_`) are not // allowed. `allow_ty_infer` gates this behavior. We check for the presence of @@ -2562,8 +2553,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { }; let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl(); - let trait_ref = - self.instantiate_mono_trait_ref(i.of_trait.as_ref()?, self.ast_ty_to_ty(i.self_ty)); + let trait_ref = self.lower_impl_trait_ref(i.of_trait.as_ref()?, self.lower_ty(i.self_ty)); let assoc = tcx.associated_items(trait_ref.def_id).find_by_name_and_kind( tcx, diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index 70c60e39941..140055cf764 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -11,14 +11,14 @@ use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{DynKind, ToPredicate}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::report_object_safety_error; -use rustc_trait_selection::traits::{self, astconv_object_safety_violations}; +use rustc_trait_selection::traits::{self, hir_ty_lowering_object_safety_violations}; use smallvec::{smallvec, SmallVec}; -use super::AstConv; +use super::HirTyLowerer; -impl<'tcx> dyn AstConv<'tcx> + '_ { - pub(super) fn conv_object_ty_poly_trait_ref( +impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { + pub(super) fn lower_trait_object_ty( &self, span: Span, hir_id: hir::HirId, @@ -37,7 +37,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { correct: Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }), .. - } = self.instantiate_poly_trait_ref( + } = self.lower_poly_trait_ref( &trait_bound.trait_ref, trait_bound.span, ty::BoundConstness::NotConst, @@ -133,7 +133,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // to avoid ICEs. for item in ®ular_traits { let object_safety_violations = - astconv_object_safety_violations(tcx, item.trait_ref().def_id()); + hir_ty_lowering_object_safety_violations(tcx, item.trait_ref().def_id()); if !object_safety_violations.is_empty() { let reported = report_object_safety_error( tcx, @@ -231,7 +231,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { def_ids.retain(|def_id| !tcx.generics_require_sized_self(def_id)); } - self.complain_about_missing_associated_types( + self.complain_about_missing_assoc_tys( associated_types, potential_assoc_types, hir_trait_bounds, @@ -362,11 +362,11 @@ impl<'tcx> dyn AstConv<'tcx> + '_ { // Use explicitly-specified region bound. let region_bound = if !lifetime.is_elided() { - self.ast_region_to_region(lifetime, None) + self.lower_lifetime(lifetime, None) } else { self.compute_object_lifetime_bound(span, existential_predicates).unwrap_or_else(|| { if tcx.named_bound_var(lifetime.hir_id).is_some() { - self.ast_region_to_region(lifetime, None) + self.lower_lifetime(lifetime, None) } else { self.re_infer(None, span).unwrap_or_else(|| { let err = struct_span_code_err!( diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index b5377e40bfd..e466fc5e44e 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1866,7 +1866,7 @@ fn check_variances_for_type_defn<'tcx>( .iter() .filter_map(|predicate| match predicate { hir::WherePredicate::BoundPredicate(predicate) => { - match icx.to_ty(predicate.bounded_ty).kind() { + match icx.lower_ty(predicate.bounded_ty).kind() { ty::Param(data) => Some(Parameter(data.index)), _ => None, } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 6c3f99ccc12..06e7576e897 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -40,7 +40,7 @@ use std::cell::Cell; use std::iter; use std::ops::Bound; -use crate::astconv::AstConv; +use crate::astconv::HirTyLowerer; use crate::check::intrinsic::intrinsic_operation_unsafety; use crate::errors; pub use type_of::test_opaque_hidden_types; @@ -277,7 +277,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { } fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { - convert_item(self.tcx, item.item_id()); + lower_item(self.tcx, item.item_id()); reject_placeholder_type_signatures_in_item(self.tcx, item); intravisit::walk_item(self, item); } @@ -315,12 +315,12 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { - convert_trait_item(self.tcx, trait_item.trait_item_id()); + lower_trait_item(self.tcx, trait_item.trait_item_id()); intravisit::walk_trait_item(self, trait_item); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { - convert_impl_item(self.tcx, impl_item.impl_item_id()); + lower_impl_item(self.tcx, impl_item.impl_item_id()); intravisit::walk_impl_item(self, impl_item); } } @@ -344,8 +344,8 @@ impl<'tcx> ItemCtxt<'tcx> { ItemCtxt { tcx, item_def_id, tainted_by_errors: Cell::new(None) } } - pub fn to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - self.astconv().ast_ty_to_ty(ast_ty) + pub fn lower_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + self.lowerer().lower_ty(ast_ty) } pub fn hir_id(&self) -> hir::HirId { @@ -364,7 +364,7 @@ impl<'tcx> ItemCtxt<'tcx> { } } -impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { +impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } @@ -373,7 +373,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { self.item_def_id.to_def_id() } - fn get_type_parameter_bounds( + fn probe_ty_param_bounds( &self, span: Span, def_id: LocalDefId, @@ -386,7 +386,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { None } - fn allow_ty_infer(&self) -> bool { + fn allow_infer(&self) -> bool { false } @@ -404,7 +404,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant") } - fn projected_ty_from_poly_trait_ref( + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -412,7 +412,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { poly_trait_ref: ty::PolyTraitRef<'tcx>, ) -> Ty<'tcx> { if let Some(trait_ref) = poly_trait_ref.no_bound_vars() { - let item_args = self.astconv().create_args_for_associated_item( + let item_args = self.lowerer().lower_generic_args_of_assoc_item( span, item_def_id, item_segment, @@ -547,7 +547,7 @@ fn get_new_lifetime_name<'tcx>( (1..).flat_map(a_to_z_repeat_n).find(|lt| !existing_lifetimes.contains(lt.as_str())).unwrap() } -fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { +fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { let it = tcx.hir().item(item_id); debug!("convert: item {} with id {}", it.ident, it.hir_id()); let def_id = item_id.owner_id.def_id; @@ -591,7 +591,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(def_id); - convert_enum_variant_types(tcx, def_id.to_def_id()); + lower_enum_variant_types(tcx, def_id.to_def_id()); } hir::ItemKind::Impl { .. } => { tcx.ensure().generics_of(def_id); @@ -625,7 +625,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } if let Some(ctor_def_id) = struct_def.ctor_def_id() { - convert_variant_ctor(tcx, ctor_def_id); + lower_variant_ctor(tcx, ctor_def_id); } } @@ -668,7 +668,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } } -fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { +fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { let trait_item = tcx.hir().trait_item(trait_item_id); let def_id = trait_item_id.owner_id; tcx.ensure().generics_of(def_id); @@ -717,7 +717,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { tcx.ensure().predicates_of(def_id); } -fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { +fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { let def_id = impl_item_id.owner_id; tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); @@ -746,13 +746,13 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { } } -fn convert_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { +fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(def_id); } -fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { +fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { let def = tcx.adt_def(def_id); let repr_type = def.repr().discr_type(); let initial = repr_type.initial_discriminant(tcx); @@ -788,7 +788,7 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { // Convert the ctor, if any. This also registers the variant as // an item. if let Some(ctor_def_id) = variant.ctor_def_id() { - convert_variant_ctor(tcx, ctor_def_id.expect_local()); + lower_variant_ctor(tcx, ctor_def_id.expect_local()); } } } @@ -975,7 +975,7 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> { } } -fn convert_variant( +fn lower_variant( tcx: TyCtxt<'_>, variant_did: Option<LocalDefId>, ident: Ident, @@ -1060,7 +1060,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { }; distance_from_explicit += 1; - convert_variant( + lower_variant( tcx, Some(v.def_id), v.ident, @@ -1080,7 +1080,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { ItemKind::Struct(..) => AdtKind::Struct, _ => AdtKind::Union, }; - let variants = std::iter::once(convert_variant( + let variants = std::iter::once(lower_variant( tcx, None, item.ident, @@ -1284,7 +1284,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig< if let Item(hir::Item { kind: ItemKind::Impl(i), .. }) = tcx.parent_hir_node(hir_id) && i.of_trait.is_some() { - icx.astconv().ty_of_fn( + icx.lowerer().lower_fn_ty( hir_id, sig.header.unsafety, sig.header.abi, @@ -1301,9 +1301,14 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<ty::PolyFnSig< kind: TraitItemKind::Fn(FnSig { header, decl, span: _ }, _), generics, .. - }) => { - icx.astconv().ty_of_fn(hir_id, header.unsafety, header.abi, decl, Some(generics), None) - } + }) => icx.lowerer().lower_fn_ty( + hir_id, + header.unsafety, + header.abi, + decl, + Some(generics), + None, + ), ForeignItem(&hir::ForeignItem { kind: ForeignItemKind::Fn(fn_decl, _, _), .. }) => { let abi = tcx.hir().get_foreign_abi(hir_id); @@ -1411,7 +1416,7 @@ fn infer_return_ty_for_fn_sig<'tcx>( )) } } - None => icx.astconv().ty_of_fn( + None => icx.lowerer().lower_fn_ty( hir_id, sig.header.unsafety, sig.header.abi, @@ -1554,9 +1559,9 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai segments: tcx.hir_arena.alloc_slice(&path_segments), }; let trait_ref = tcx.hir_arena.alloc(hir::TraitRef { path: tcx.hir_arena.alloc(path), hir_ref_id: ast_trait_ref.hir_ref_id }); - icx.astconv().instantiate_mono_trait_ref(trait_ref, selfty) + icx.lowerer().lower_impl_trait_ref(trait_ref, selfty) } else { - icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty) + icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty) }; ty::ImplTraitHeader { trait_ref: ty::EarlyBinder::bind(trait_ref), @@ -1678,7 +1683,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( }; let hir_id = tcx.local_def_id_to_hir_id(def_id); let fty = - ItemCtxt::new(tcx, def_id).astconv().ty_of_fn(hir_id, unsafety, abi, decl, None, None); + ItemCtxt::new(tcx, def_id).lowerer().lower_fn_ty(hir_id, unsafety, abi, decl, None, None); // Feature gate SIMD types in FFI, since I am not sure that the // ABIs are handled at all correctly. -huonw diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index f914f1f9b17..b4e113d47ed 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -1,5 +1,5 @@ use super::ItemCtxt; -use crate::astconv::{AstConv, PredicateFilter}; +use crate::astconv::{HirTyLowerer, PredicateFilter}; use rustc_data_structures::fx::FxIndexSet; use rustc_hir as hir; use rustc_infer::traits::util; @@ -29,9 +29,9 @@ fn associated_type_bounds<'tcx>( ); let icx = ItemCtxt::new(tcx, assoc_item_def_id); - let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, filter); + let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, ast_bounds, filter); // Associated types are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span); + icx.lowerer().add_sized_bound(&mut bounds, item_ty, ast_bounds, None, span); let trait_def_id = tcx.local_parent(assoc_item_def_id); let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id); @@ -69,9 +69,9 @@ fn opaque_type_bounds<'tcx>( ) -> &'tcx [(ty::Clause<'tcx>, Span)] { ty::print::with_reduced_queries!({ let icx = ItemCtxt::new(tcx, opaque_def_id); - let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, filter); + let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, ast_bounds, filter); // Opaque types are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized(&mut bounds, item_ty, ast_bounds, None, span); + icx.lowerer().add_sized_bound(&mut bounds, item_ty, ast_bounds, None, span); debug!(?bounds); tcx.arena.alloc_from_iter(bounds.clauses()) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 66c9fb93500..4c4cf9fa1b6 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -1,4 +1,4 @@ -use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter}; +use crate::astconv::{HirTyLowerer, OnlySelfBounds, PredicateFilter}; use crate::bounds::Bounds; use crate::collect::ItemCtxt; use crate::constrained_generic_params as cgp; @@ -149,8 +149,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // like `trait Foo: A + B + C`. if let Some(self_bounds) = is_trait { predicates.extend( - icx.astconv() - .compute_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All) + icx.lowerer() + .lower_mono_bounds(tcx.types.self_param, self_bounds, PredicateFilter::All) .clauses(), ); } @@ -175,10 +175,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // We already dealt with early bound lifetimes above. GenericParamKind::Lifetime { .. } => (), GenericParamKind::Type { .. } => { - let param_ty = icx.astconv().hir_id_to_bound_ty(param.hir_id); + let param_ty = icx.lowerer().lower_ty_param(param.hir_id); let mut bounds = Bounds::default(); // Params are implicitly sized unless a `?Sized` bound is found - icx.astconv().add_implicitly_sized( + icx.lowerer().add_sized_bound( &mut bounds, param_ty, &[], @@ -194,7 +194,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen .type_of(param.def_id.to_def_id()) .no_bound_vars() .expect("const parameters cannot be generic"); - let ct = icx.astconv().hir_id_to_bound_const(param.hir_id, ct_ty); + let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty); predicates.insert(( ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx), param.span, @@ -208,7 +208,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen for predicate in ast_generics.predicates { match predicate { hir::WherePredicate::BoundPredicate(bound_pred) => { - let ty = icx.to_ty(bound_pred.bounded_ty); + let ty = icx.lower_ty(bound_pred.bounded_ty); let bound_vars = tcx.late_bound_vars(bound_pred.hir_id); // Keep the type around in a dummy predicate, in case of no bounds. // That way, `where Ty:` is not a complete noop (see #53696) and `Ty` @@ -232,7 +232,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } let mut bounds = Bounds::default(); - icx.astconv().add_bounds( + icx.lowerer().lower_poly_bounds( ty, bound_pred.bounds.iter(), &mut bounds, @@ -243,11 +243,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } hir::WherePredicate::RegionPredicate(region_pred) => { - let r1 = icx.astconv().ast_region_to_region(region_pred.lifetime, None); + let r1 = icx.lowerer().lower_lifetime(region_pred.lifetime, None); predicates.extend(region_pred.bounds.iter().map(|bound| { let (r2, span) = match bound { hir::GenericBound::Outlives(lt) => { - (icx.astconv().ast_region_to_region(lt, None), lt.ident.span) + (icx.lowerer().lower_lifetime(lt, None), lt.ident.span) } bound => { span_bug!( @@ -601,9 +601,9 @@ pub(super) fn implied_predicates_with_filter( let icx = ItemCtxt::new(tcx, trait_def_id); let self_param_ty = tcx.types.self_param; - let superbounds = icx.astconv().compute_bounds(self_param_ty, bounds, filter); + let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter); - let where_bounds_that_match = icx.type_parameter_bounds_in_generics( + let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics( generics, item.owner_id.def_id, self_param_ty, @@ -676,7 +676,7 @@ pub(super) fn type_param_predicates( let mut result = parent .map(|parent| { let icx = ItemCtxt::new(tcx, parent); - icx.get_type_parameter_bounds(DUMMY_SP, def_id, assoc_name) + icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name) }) .unwrap_or_default(); let mut extend = None; @@ -696,7 +696,7 @@ pub(super) fn type_param_predicates( let icx = ItemCtxt::new(tcx, item_def_id); let extra_predicates = extend.into_iter().chain( - icx.type_parameter_bounds_in_generics( + icx.probe_ty_param_bounds_in_generics( ast_generics, def_id, ty, @@ -719,7 +719,7 @@ impl<'tcx> ItemCtxt<'tcx> { /// would create artificial cycles. Instead, we can only convert the /// bounds for a type parameter `X` if `X::Foo` is used. #[instrument(level = "trace", skip(self, ast_generics))] - fn type_parameter_bounds_in_generics( + fn probe_ty_param_bounds_in_generics( &self, ast_generics: &'tcx hir::Generics<'tcx>, param_def_id: LocalDefId, @@ -750,13 +750,13 @@ impl<'tcx> ItemCtxt<'tcx> { let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) { ty } else if matches!(filter, PredicateFilter::All) { - self.to_ty(predicate.bounded_ty) + self.lower_ty(predicate.bounded_ty) } else { continue; }; let bound_vars = self.tcx.late_bound_vars(predicate.hir_id); - self.astconv().add_bounds( + self.lowerer().lower_poly_bounds( bound_ty, predicate.bounds.iter().filter(|bound| { assoc_name diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 86b075a84a7..83877bff98c 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1923,12 +1923,12 @@ fn is_late_bound_map( /// We must therefore "look into" the `Alias` to see whether we should consider `'a` constrained or not. /// /// See #100508 #85533 #47511 for additional context - struct ConstrainedCollectorPostAstConv { + struct ConstrainedCollectorPostHirTyLowering { arg_is_constrained: Box<[bool]>, } use ty::Ty; - impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostAstConv { + impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstrainedCollectorPostHirTyLowering { fn visit_ty(&mut self, t: Ty<'tcx>) { match t.kind() { ty::Param(param_ty) => { @@ -1973,7 +1973,7 @@ fn is_late_bound_map( // See comments on `ConstrainedCollectorPostAstConv` for why this arm does not just consider // args to be unconstrained. let generics = self.tcx.generics_of(alias_def); - let mut walker = ConstrainedCollectorPostAstConv { + let mut walker = ConstrainedCollectorPostHirTyLowering { arg_is_constrained: vec![false; generics.params.len()].into_boxed_slice(), }; walker.visit_ty(self.tcx.type_of(alias_def).instantiate_identity()); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index cec01abae4b..4d8e0e04c73 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -108,7 +108,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> { .unwrap() .0 .def_id; - let ty = ItemCtxt::new(tcx, item_def_id).to_ty(hir_ty); + let ty = ItemCtxt::new(tcx, item_def_id).lower_ty(hir_ty); // Iterate through the generics of the projection to find the one that corresponds to // the def_id that this query was called with. We filter to only type and const args here @@ -369,8 +369,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty ) }) }) - .unwrap_or_else(|| icx.to_ty(ty)), - TraitItemKind::Type(_, Some(ty)) => icx.to_ty(ty), + .unwrap_or_else(|| icx.lower_ty(ty)), + TraitItemKind::Type(_, Some(ty)) => icx.lower_ty(ty), TraitItemKind::Type(_, None) => { span_bug!(item.span, "associated type missing default"); } @@ -392,7 +392,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty "associated constant", ) } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } ImplItemKind::Type(ty) => { @@ -400,7 +400,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty check_feature_inherent_assoc_ty(tcx, item.span); } - icx.to_ty(ty) + icx.lower_ty(ty) } }, @@ -416,17 +416,17 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty "static variable", ) } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } ItemKind::Const(ty, _, body_id) => { if ty.is_suggestable_infer_ty() { infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant") } else { - icx.to_ty(ty) + icx.lower_ty(ty) } } - ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty), + ItemKind::TyAlias(self_ty, _) => icx.lower_ty(self_ty), ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() { spans if spans.len() > 0 => { let guar = tcx @@ -434,7 +434,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty .emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () }); Ty::new_error(tcx, guar) } - _ => icx.to_ty(*self_ty), + _ => icx.lower_ty(*self_ty), }, ItemKind::Fn(..) => { let args = ty::GenericArgs::identity_for_item(tcx, def_id); @@ -466,7 +466,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty let args = ty::GenericArgs::identity_for_item(tcx, def_id); Ty::new_fn_def(tcx, def_id.to_def_id(), args) } - ForeignItemKind::Static(t, _) => icx.to_ty(t), + ForeignItemKind::Static(t, _) => icx.lower_ty(t), ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()), }, @@ -480,7 +480,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty } }, - Node::Field(field) => icx.to_ty(field.ty), + Node::Field(field) => icx.lower_ty(field.ty), Node::Expr(&Expr { kind: ExprKind::Closure { .. }, .. }) => { tcx.typeck(def_id).node_type(hir_id) @@ -495,7 +495,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty Node::GenericParam(param) => match ¶m.kind { GenericParamKind::Type { default: Some(ty), .. } - | GenericParamKind::Const { ty, .. } => icx.to_ty(ty), + | GenericParamKind::Const { ty, .. } => icx.lower_ty(ty), x => bug!("unexpected non-type Node::GenericParam: {:?}", x), }, diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 2a9101b3808..f932acc5e83 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -68,7 +68,7 @@ fn diagnostic_hir_wf_check<'tcx>( let infcx = self.tcx.infer_ctxt().build(); let ocx = ObligationCtxt::new(&infcx); - let tcx_ty = self.icx.to_ty(ty); + let tcx_ty = self.icx.lower_ty(ty); // This visitor can walk into binders, resulting in the `tcx_ty` to // potentially reference escaping bound variables. We simply erase // those here. diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 5fe8d1fe586..e95ed554a78 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -213,10 +213,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { /// A quasi-deprecated helper used in rustdoc and clippy to get /// the type from a HIR node. -pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { +pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { // In case there are any projections, etc., find the "environment" // def-ID that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id); - collect::ItemCtxt::new(tcx, env_def_id.def_id).to_ty(hir_ty) + collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty) } diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index b32c5e2c357..752fe2a4d97 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -5,7 +5,7 @@ use super::{check_fn, CoroutineTypes, Expectation, FnCtxt}; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes}; use rustc_infer::infer::{InferOk, InferResult}; @@ -784,7 +784,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { decl: &hir::FnDecl<'tcx>, closure_kind: hir::ClosureKind, ) -> ty::PolyFnSig<'tcx> { - let astconv = self.astconv(); + let lowerer = self.lowerer(); trace!("decl = {:#?}", decl); debug!(?closure_kind); @@ -793,9 +793,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let bound_vars = self.tcx.late_bound_vars(hir_id); // First, convert the types that the user supplied (if any). - let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a)); + let supplied_arguments = decl.inputs.iter().map(|a| lowerer.lower_ty(a)); let supplied_return = match decl.output { - hir::FnRetTy::Return(ref output) => astconv.ast_ty_to_ty(output), + hir::FnRetTy::Return(ref output) => lowerer.lower_ty(output), hir::FnRetTy::DefaultReturn(_) => match closure_kind { // In the case of the async block that we create for a function body, // we expect the return type of the block to match that of the enclosing @@ -813,7 +813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // easily (and locally) prove that we // *have* reported an // error. --nikomatsakis - astconv.ty_infer(None, decl.output.span()) + lowerer.ty_infer(None, decl.output.span()) }) } // All `gen {}` and `async gen {}` must return unit. @@ -832,7 +832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | hir::ClosureKind::Coroutine(hir::CoroutineKind::Coroutine(_)) | hir::ClosureKind::Closure | hir::ClosureKind::CoroutineClosure(_) => { - astconv.ty_infer(None, decl.output.span()) + lowerer.ty_infer(None, decl.output.span()) } }, }; @@ -989,17 +989,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { decl: &hir::FnDecl<'tcx>, guar: ErrorGuaranteed, ) -> ty::PolyFnSig<'tcx> { - let astconv = self.astconv(); + let lowerer = self.lowerer(); let err_ty = Ty::new_error(self.tcx, guar); let supplied_arguments = decl.inputs.iter().map(|a| { // Convert the types that the user supplied (if any), but ignore them. - astconv.ast_ty_to_ty(a); + lowerer.lower_ty(a); err_ty }); if let hir::FnRetTy::Return(ref output) = decl.output { - astconv.ast_ty_to_ty(output); + lowerer.lower_ty(output); } let result = ty::Binder::dummy(self.tcx.mk_fn_sig( diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 792359c9dda..bed0fee6c94 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -41,7 +41,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::Expr; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult}; use rustc_infer::traits::TraitEngine; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 4c01c201ad2..c5aab115dbf 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -35,7 +35,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, HirId, QPath}; -use rustc_hir_analysis::astconv::AstConv as _; +use rustc_hir_analysis::astconv::HirTyLowerer as _; use rustc_hir_analysis::check::ty_kind_suggestion; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; @@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ExprKind::Cast(e, t) => self.check_expr_cast(e, t, expr), ExprKind::Type(e, t) => { - let ascribed_ty = self.to_ty_saving_user_provided_ty(t); + let ascribed_ty = self.lower_ty_saving_user_provided_ty(t); let ty = self.check_expr_with_hint(e, ascribed_ty); self.demand_eqtype(e.span, ascribed_ty, ty); ascribed_ty @@ -1375,7 +1375,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { // Find the type of `e`. Supply hints based on the type we are casting to, // if appropriate. - let t_cast = self.to_ty_saving_user_provided_ty(t); + let t_cast = self.lower_ty_saving_user_provided_ty(t); let t_cast = self.resolve_vars_if_possible(t_cast); let t_expr = self.check_expr_with_expectation(e, ExpectCastableToType(t_cast)); let t_expr = self.resolve_vars_if_possible(t_expr); @@ -1503,7 +1503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx; - let count = self.array_length_to_const(count); + let count = self.lower_array_length(count); if let Some(count) = count.try_eval_target_usize(tcx, self.param_env) { self.suggest_array_len(expr, count); } @@ -3283,7 +3283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields: &[Ident], expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { - let container = self.to_ty(container).normalized; + let container = self.lower_ty(container).normalized; if let Some(ident_2) = fields.get(1) && !self.tcx.features().offset_of_nested diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 1d885b801d9..c7d88438fbe 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -11,12 +11,10 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, GenericArg, Node, QPath}; -use rustc_hir_analysis::astconv::generics::{ - check_generic_arg_count_for_call, create_args_for_parent_generic_args, -}; +use rustc_hir_analysis::astconv::generics::{check_generic_arg_count_for_call, lower_generic_args}; use rustc_hir_analysis::astconv::{ - AstConv, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch, - GenericArgCountResult, IsMethodCall, PathSeg, + ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgsLowerer, + GenericPathSegment, HirTyLowerer, IsMethodCall, }; use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; @@ -394,14 +392,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn to_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> { - let t = self.astconv().ast_ty_to_ty(ast_t); + pub fn lower_ty(&self, ast_t: &hir::Ty<'tcx>) -> LoweredTy<'tcx> { + let t = self.lowerer().lower_ty(ast_t); self.register_wf_obligation(t.into(), ast_t.span, traits::WellFormed(None)); LoweredTy::from_raw(self, ast_t.span, t) } - pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { - let ty = self.to_ty(ast_ty); + pub fn lower_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { + let ty = self.lower_ty(ast_ty); debug!("to_ty_saving_user_provided_ty: ty={:?}", ty); if Self::can_contain_user_lifetime_bounds(ty.raw) { @@ -424,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> { + pub fn lower_array_length(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> { match length { hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span), hir::ArrayLen::Body(anon_const) => { @@ -436,11 +434,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn const_arg_to_const( - &self, - ast_c: &hir::AnonConst, - param_def_id: DefId, - ) -> ty::Const<'tcx> { + pub fn lower_const_arg(&self, ast_c: &hir::AnonConst, param_def_id: DefId) -> ty::Const<'tcx> { let did = ast_c.def_id; self.tcx.feed_anon_const_type(did, self.tcx.type_of(param_def_id)); let c = ty::Const::from_anon_const(self.tcx, did); @@ -827,7 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { QPath::Resolved(ref opt_qself, path) => { return ( path.res, - opt_qself.as_ref().map(|qself| self.to_ty(qself)), + opt_qself.as_ref().map(|qself| self.lower_ty(qself)), path.segments, ); } @@ -841,7 +835,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // to be object-safe. // We manually call `register_wf_obligation` in the success path // below. - let ty = self.astconv().ast_ty_to_ty_in_path(qself); + let ty = self.lowerer().lower_ty_in_path(qself); (LoweredTy::from_raw(self, span, ty), qself, segment) } QPath::LangItem(..) => { @@ -1119,9 +1113,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> (Ty<'tcx>, Res) { let tcx = self.tcx; - let path_segs = match res { + let generic_segments = match res { Res::Local(_) | Res::SelfCtor(_) => vec![], - Res::Def(kind, def_id) => self.astconv().def_ids_for_value_path_segments( + Res::Def(kind, def_id) => self.lowerer().probe_generic_path_segments( segments, self_ty.map(|ty| ty.raw), kind, @@ -1178,14 +1172,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // provided (if any) into their appropriate spaces. We'll also report // errors if type parameters are provided in an inappropriate place. - let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect(); - let generics_has_err = self.astconv().prohibit_generics( + let indices: FxHashSet<_> = + generic_segments.iter().map(|GenericPathSegment(_, index)| index).collect(); + let generics_has_err = self.lowerer().prohibit_generic_args( segments.iter().enumerate().filter_map(|(index, seg)| { - if !generic_segs.contains(&index) || is_alias_variant_ctor { - Some(seg) - } else { - None - } + if !indices.contains(&index) || is_alias_variant_ctor { Some(seg) } else { None } }), |_| {}, ); @@ -1212,7 +1203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut infer_args_for_err = FxHashSet::default(); let mut explicit_late_bound = ExplicitLateBound::No; - for &PathSeg(def_id, index) in &path_segs { + for &GenericPathSegment(def_id, index) in &generic_segments { let seg = &segments[index]; let generics = tcx.generics_of(def_id); @@ -1233,8 +1224,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let has_self = - path_segs.last().is_some_and(|PathSeg(def_id, _)| tcx.generics_of(*def_id).has_self); + let has_self = generic_segments + .last() + .is_some_and(|GenericPathSegment(def_id, _)| tcx.generics_of(*def_id).has_self); let (res, self_ctor_args) = if let Res::SelfCtor(impl_def_id) = res { let ty = LoweredTy::from_raw( @@ -1294,22 +1286,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, }; - struct CreateCtorInstantiationsContext<'a, 'tcx> { + struct CtorGenericArgsCtxt<'a, 'tcx> { fcx: &'a FnCtxt<'a, 'tcx>, span: Span, - path_segs: &'a [PathSeg], + generic_segments: &'a [GenericPathSegment], infer_args_for_err: &'a FxHashSet<usize>, segments: &'tcx [hir::PathSegment<'tcx>], } - impl<'tcx, 'a> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for CreateCtorInstantiationsContext<'a, 'tcx> - { + impl<'tcx, 'a> GenericArgsLowerer<'a, 'tcx> for CtorGenericArgsCtxt<'a, 'tcx> { fn args_for_def_id( &mut self, def_id: DefId, ) -> (Option<&'a hir::GenericArgs<'tcx>>, bool) { - if let Some(&PathSeg(_, index)) = - self.path_segs.iter().find(|&PathSeg(did, _)| *did == def_id) + if let Some(&GenericPathSegment(_, index)) = + self.generic_segments.iter().find(|&GenericPathSegment(did, _)| *did == def_id) { // If we've encountered an `impl Trait`-related error, we're just // going to infer the arguments for better error messages. @@ -1332,13 +1322,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> ty::GenericArg<'tcx> { match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.fcx.astconv().ast_region_to_region(lt, Some(param)).into() + self.fcx.lowerer().lower_lifetime(lt, Some(param)).into() } (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => { - self.fcx.to_ty(ty).raw.into() + self.fcx.lower_ty(ty).raw.into() } (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => { - self.fcx.const_arg_to_const(&ct.value, param.def_id).into() + self.fcx.lower_const_arg(&ct.value, param.def_id).into() } (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => { self.fcx.ty_infer(Some(param), inf.span).into() @@ -1420,17 +1410,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let args_raw = self_ctor_args.unwrap_or_else(|| { - create_args_for_parent_generic_args( + lower_generic_args( tcx, def_id, &[], has_self, self_ty.map(|s| s.raw), &arg_count, - &mut CreateCtorInstantiationsContext { + &mut CtorGenericArgsCtxt { fcx: self, span, - path_segs: &path_segs, + generic_segments: &generic_segments, infer_args_for_err: &infer_args_for_err, segments, }, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 19f839b6240..f1c6c8bef0b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -24,7 +24,7 @@ use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; use rustc_hir::{ExprKind, Node, QPath}; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::potentially_plural_count; use rustc_hir_analysis::structured_errors::StructuredDiag; @@ -1961,16 +1961,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> (Res, LoweredTy<'tcx>) { match *qpath { QPath::Resolved(ref maybe_qself, path) => { - let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself).raw); - let ty = self.astconv().res_to_ty(self_ty, path, hir_id, true); + let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself).raw); + let ty = self.lowerer().lower_path(self_ty, path, hir_id, true); (path.res, LoweredTy::from_raw(self, path_span, ty)) } QPath::TypeRelative(qself, segment) => { - let ty = self.to_ty(qself); + let ty = self.lower_ty(qself); let result = self - .astconv() - .associated_path_to_ty(hir_id, path_span, ty.raw, qself, segment, true); + .lowerer() + .lower_assoc_path(hir_id, path_span, ty.raw, qself, segment, true); let ty = result .map(|(ty, _, _)| ty) .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar)); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 1850463194d..7922c0bfc96 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -12,7 +12,7 @@ use hir::def_id::CRATE_DEF_ID; use rustc_errors::{DiagCtxt, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_infer::infer; use rustc_infer::infer::error_reporting::sub_relations::SubRelations; use rustc_infer::infer::error_reporting::TypeErrCtxt; @@ -212,7 +212,7 @@ impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> { } } -impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { +impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'tcx> { self.tcx } @@ -221,7 +221,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { self.body_id.to_def_id() } - fn get_type_parameter_bounds( + fn probe_ty_param_bounds( &self, _: Span, def_id: LocalDefId, @@ -256,7 +256,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { Some(self.next_region_var(v)) } - fn allow_ty_infer(&self) -> bool { + fn allow_infer(&self) -> bool { true } @@ -292,7 +292,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { } } - fn projected_ty_from_poly_trait_ref( + fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, @@ -305,7 +305,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { poly_trait_ref, ); - let item_args = self.astconv().create_args_for_associated_item( + let item_args = self.lowerer().lower_generic_args_of_assoc_item( span, item_def_id, item_segment, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index f4090feee17..13ac1de7b36 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -21,7 +21,7 @@ use rustc_hir::{ CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node, Path, QPath, Stmt, StmtKind, TyKind, WherePredicate, }; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_infer::traits::{self}; use rustc_middle::lint::in_external_macro; use rustc_middle::middle::stability::EvalResult; @@ -877,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Only point to return type if the expected type is the return type, as if they // are not, the expectation must have been caused by something else. debug!("return type {:?}", hir_ty); - let ty = self.astconv().ast_ty_to_ty(hir_ty); + let ty = self.lowerer().lower_ty(hir_ty); debug!("return type {:?}", ty); debug!("expected type {:?}", expected); let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into()); @@ -958,7 +958,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .. }) => { // FIXME: Maybe these calls to `ast_ty_to_ty` can be removed (and the ones below) - let ty = self.astconv().ast_ty_to_ty(bounded_ty); + let ty = self.lowerer().lower_ty(bounded_ty); Some((ty, bounds)) } _ => None, @@ -996,7 +996,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let all_bounds_str = all_matching_bounds_strs.join(" + "); let ty_param_used_in_fn_params = fn_parameters.iter().any(|param| { - let ty = self.astconv().ast_ty_to_ty( param); + let ty = self.lowerer().lower_ty( param); matches!(ty.kind(), ty::Param(fn_param_ty_param) if expected_ty_as_param == fn_param_ty_param) }); @@ -1071,7 +1071,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let can_return = match fn_decl.output { hir::FnRetTy::Return(ty) => { - let ty = self.astconv().ast_ty_to_ty(ty); + let ty = self.lowerer().lower_ty(ty); let bound_vars = self.tcx.late_bound_vars(fn_id); let ty = self .tcx diff --git a/compiler/rustc_hir_typeck/src/gather_locals.rs b/compiler/rustc_hir_typeck/src/gather_locals.rs index 6dae1fab6dc..8fddccab5bf 100644 --- a/compiler/rustc_hir_typeck/src/gather_locals.rs +++ b/compiler/rustc_hir_typeck/src/gather_locals.rs @@ -93,7 +93,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { fn declare(&mut self, decl: Declaration<'tcx>) { let local_ty = match decl.ty { Some(ref ty) => { - let o_ty = self.fcx.to_ty(ty); + let o_ty = self.fcx.lower_ty(ty); let c_ty = self.fcx.inh.infcx.canonicalize_user_type_annotation(UserType::Ty(o_ty.raw)); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index d259e71f957..0cba6f538f0 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -57,7 +57,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::Visitor; use rustc_hir::{HirIdMap, Node}; -use rustc_hir_analysis::astconv::AstConv; +use rustc_hir_analysis::astconv::HirTyLowerer; use rustc_hir_analysis::check::check_abi; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::traits::{ObligationCauseCode, ObligationInspector, WellFormedLoc}; @@ -178,7 +178,7 @@ fn typeck_with_fallback<'tcx>( if let Some(hir::FnSig { header, decl, .. }) = fn_sig { let fn_sig = if decl.output.get_infer_ret_ty().is_some() { - fcx.astconv().ty_of_fn(id, header.unsafety, header.abi, decl, None, None) + fcx.lowerer().lower_fn_ty(id, header.unsafety, header.abi, decl, None, None) } else { tcx.fn_sig(def_id).instantiate_identity() }; diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index a580c114f26..361d38baf32 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -4,10 +4,8 @@ use crate::{callee, FnCtxt}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::GenericArg; -use rustc_hir_analysis::astconv::generics::{ - check_generic_arg_count_for_call, create_args_for_parent_generic_args, -}; -use rustc_hir_analysis::astconv::{AstConv, CreateInstantiationsForGenericArgsCtxt, IsMethodCall}; +use rustc_hir_analysis::astconv::generics::{check_generic_arg_count_for_call, lower_generic_args}; +use rustc_hir_analysis::astconv::{GenericArgsLowerer, HirTyLowerer, IsMethodCall}; use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk}; use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; @@ -366,14 +364,12 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // combining parameters from the type and those from the method. assert_eq!(generics.parent_count, parent_args.len()); - struct MethodInstantiationsCtxt<'a, 'tcx> { + struct GenericArgsCtxt<'a, 'tcx> { cfcx: &'a ConfirmContext<'a, 'tcx>, pick: &'a probe::Pick<'tcx>, seg: &'a hir::PathSegment<'tcx>, } - impl<'a, 'tcx> CreateInstantiationsForGenericArgsCtxt<'a, 'tcx> - for MethodInstantiationsCtxt<'a, 'tcx> - { + impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> { fn args_for_def_id( &mut self, def_id: DefId, @@ -393,13 +389,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { ) -> ty::GenericArg<'tcx> { match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.cfcx.fcx.astconv().ast_region_to_region(lt, Some(param)).into() + self.cfcx.fcx.lowerer().lower_lifetime(lt, Some(param)).into() } (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => { - self.cfcx.to_ty(ty).raw.into() + self.cfcx.lower_ty(ty).raw.into() } (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => { - self.cfcx.const_arg_to_const(&ct.value, param.def_id).into() + self.cfcx.lower_const_arg(&ct.value, param.def_id).into() } (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => { self.cfcx.ty_infer(Some(param), inf.span).into() @@ -432,14 +428,14 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } } - let args = create_args_for_parent_generic_args( + let args = lower_generic_args( self.tcx, pick.item.def_id, parent_args, false, None, &arg_count_correct, - &mut MethodInstantiationsCtxt { cfcx: self, pick, seg }, + &mut GenericArgsCtxt { cfcx: self, pick, seg }, ); // When the method is confirmed, the `args` includes diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index cc8b8f72cf3..c875d3da47e 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -46,7 +46,7 @@ pub use self::coherence::{IsFirstInputType, OrphanCheckErr, OverlapResult}; pub use self::engine::{ObligationCtxt, TraitEngineExt}; pub use self::fulfill::{FulfillmentContext, PendingPredicateObligation}; pub use self::normalize::NormalizeExt; -pub use self::object_safety::astconv_object_safety_violations; +pub use self::object_safety::hir_ty_lowering_object_safety_violations; pub use self::object_safety::is_vtable_safe_method; pub use self::object_safety::object_safety_violations_for_assoc_item; pub use self::object_safety::ObjectSafetyViolation; diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 1816b98a636..013f6e16481 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -36,7 +36,7 @@ pub use crate::traits::{MethodViolationCode, ObjectSafetyViolation}; /// astconv -- currently, `Self` in supertraits. This is needed /// because `object_safety_violations` can't be used during /// type collection. -pub fn astconv_object_safety_violations( +pub fn hir_ty_lowering_object_safety_violations( tcx: TyCtxt<'_>, trait_def_id: DefId, ) -> Vec<ObjectSafetyViolation> { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 810a870c35c..cd0a7d68437 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -20,7 +20,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE}; use rustc_hir::PredicateOrigin; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; use rustc_middle::metadata::Reexport; use rustc_middle::middle::resolve_bound_vars as rbv; @@ -1260,12 +1260,8 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext hir::TraitItemKind::Type(bounds, Some(default)) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(); - let item_type = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, default)), - cx, - None, - None, - ); + let item_type = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, default)), cx, None, None); AssocTypeItem( Box::new(TypeAlias { type_: clean_ty(default, cx), @@ -1306,12 +1302,8 @@ pub(crate) fn clean_impl_item<'tcx>( hir::ImplItemKind::Type(hir_ty) => { let type_ = clean_ty(hir_ty, cx); let generics = clean_generics(impl_.generics, cx); - let item_type = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)), - cx, - None, - None, - ); + let item_type = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None); AssocTypeItem( Box::new(TypeAlias { type_, @@ -1690,7 +1682,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type } hir::QPath::Resolved(Some(qself), p) => { // Try to normalize `<X as Y>::T` to a type - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); // `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>` if !ty.has_escaping_bound_vars() && let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) @@ -1716,7 +1708,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type })) } hir::QPath::TypeRelative(qself, segment) => { - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); let self_type = clean_ty(qself, cx); let (trait_, should_show_cast) = match ty.kind() { @@ -2742,12 +2734,8 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::TyAlias(hir_ty, generics) => { *cx.current_type_aliases.entry(def_id).or_insert(0) += 1; let rustdoc_ty = clean_ty(hir_ty, cx); - let type_ = clean_middle_ty( - ty::Binder::dummy(hir_ty_to_ty(cx.tcx, hir_ty)), - cx, - None, - None, - ); + let type_ = + clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None); let generics = clean_generics(generics, cx); if let Some(count) = cx.current_type_aliases.get_mut(&def_id) { *count -= 1; diff --git a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs index a79bf66ae01..8acb138332c 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_hasher.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_hasher.rs @@ -5,7 +5,7 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_inf, walk_ty, Visitor}; use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{Ty, TypeckResults}; @@ -227,7 +227,7 @@ impl<'tcx> ImplicitHasherType<'tcx> { .collect(); let params_len = params.len(); - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if is_type_diagnostic_item(cx, ty, sym::HashMap) && params_len == 2 { Some(ImplicitHasherType::HashMap( diff --git a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs index 74582f7f1de..9f4d7b51271 100644 --- a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs +++ b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs @@ -6,7 +6,7 @@ use rustc_hir::{ GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, TyKind, TypeBinding, WherePredicate, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, ClauseKind, Generics, Ty, TyCtxt}; use rustc_session::declare_lint_pass; @@ -146,7 +146,7 @@ fn try_resolve_type<'tcx>( index: usize, ) -> Option<Ty<'tcx>> { match args.get(index - 1) { - Some(GenericArg::Type(ty)) => Some(hir_ty_to_ty(tcx, ty)), + Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)), Some(_) => None, None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()), } diff --git a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs index a0d609501a0..9729c971672 100644 --- a/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs +++ b/src/tools/clippy/clippy_lints/src/types/redundant_allocation.rs @@ -4,7 +4,7 @@ use clippy_utils::{path_def_id, qpath_generic_tys}; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::TypeVisitableExt; use rustc_span::symbol::sym; @@ -59,7 +59,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>, qpath: // Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use // here because `mod.rs` guarantees this lint is only run on types outside of bodies and // is not run on locals. - let ty = hir_ty_to_ty(cx.tcx, hir_ty); + let ty = lower_ty(cx.tcx, hir_ty); if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx, cx.param_env) { return false; } diff --git a/src/tools/clippy/clippy_lints/src/types/vec_box.rs b/src/tools/clippy/clippy_lints/src/types/vec_box.rs index 7926738d68f..29996a6f783 100644 --- a/src/tools/clippy/clippy_lints/src/types/vec_box.rs +++ b/src/tools/clippy/clippy_lints/src/types/vec_box.rs @@ -4,7 +4,7 @@ use clippy_utils::source::snippet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, GenericArg, LangItem, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::TypeVisitableExt; @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>( && let Some(GenericArg::Type(boxed_ty)) = last.args.first() // extract allocator from the Box for later && let boxed_alloc_ty = last.args.get(1) - && let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty) + && let ty_ty = lower_ty(cx.tcx, boxed_ty) && !ty_ty.has_escaping_bound_vars() && ty_ty.is_sized(cx.tcx, cx.param_env) && let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()) @@ -55,7 +55,7 @@ pub(super) fn check<'tcx>( } }, (Some(GenericArg::Type(l)), Some(GenericArg::Type(r))) => - hir_ty_to_ty(cx.tcx, l) == hir_ty_to_ty(cx.tcx, r), + lower_ty(cx.tcx, l) == lower_ty(cx.tcx, r), _ => false } { diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index d638af2b78b..8764e3006c6 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_body, walk_expr, FnKind, Visitor}; use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, Item, ItemKind, Node, QPath, TyKind}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::map::Map; use rustc_middle::hir::nested_filter; @@ -74,7 +74,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op match qpath { QPath::Resolved(_, path) => path.res.opt_def_id(), QPath::TypeRelative(_, _) => { - let ty = hir_ty_to_ty(tcx, &hir_ty); + let ty = lower_ty(tcx, &hir_ty); match ty.kind() { ty::Alias(ty::Projection, proj) => { diff --git a/src/tools/clippy/clippy_lints/src/uninhabited_references.rs b/src/tools/clippy/clippy_lints/src/uninhabited_references.rs index 6732a43a19e..88039372ebd 100644 --- a/src/tools/clippy/clippy_lints/src/uninhabited_references.rs +++ b/src/tools/clippy/clippy_lints/src/uninhabited_references.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, Expr, ExprKind, FnDecl, FnRetTy, TyKind, UnOp}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; use rustc_session::declare_lint_pass; @@ -71,7 +71,7 @@ impl LateLintPass<'_> for UninhabitedReferences { } if let FnRetTy::Return(hir_ty) = fndecl.output && let TyKind::Ref(_, mut_ty) = hir_ty.kind - && hir_ty_to_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) + && lower_ty(cx.tcx, mut_ty.ty).is_privately_uninhabited(cx.tcx, cx.param_env) { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index b28037db112..dfa816963bc 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -11,7 +11,7 @@ use rustc_hir::{ self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl, ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind, }; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty as MiddleTy; use rustc_session::impl_lint_pass; @@ -224,7 +224,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf { && let ty = if in_body > 0 { cx.typeck_results().node_type(hir_ty.hir_id) } else { - hir_ty_to_ty(cx.tcx, hir_ty) + lower_ty(cx.tcx, hir_ty) } && let impl_ty = cx.tcx.type_of(impl_id).instantiate_identity() && same_type_and_consts(ty, impl_ty) diff --git a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs index 4aaf3b0a0b6..d1f7c6417c7 100644 --- a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs +++ b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_help; use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item}; use rustc_hir::{self as hir, HirId, ItemKind, Node}; -use rustc_hir_analysis::hir_ty_to_ty; +use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; @@ -91,5 +91,5 @@ fn ty_from_hir_ty<'tcx>(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'t None } }) - .unwrap_or_else(|| hir_ty_to_ty(cx.tcx, hir_ty)) + .unwrap_or_else(|| lower_ty(cx.tcx, hir_ty)) } |
