Skip to content

Commit 05d48b9

Browse files
committed
Rename AstConv to HIR ty lowering
This includes updating astconv-related items and a few local variables.
1 parent b57a10c commit 05d48b9

35 files changed

+371
-402
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use rustc_trait_selection::traits;
1212
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
1313
use smallvec::SmallVec;
1414

15-
use crate::astconv::{AstConv, OnlySelfBounds, PredicateFilter};
15+
use crate::astconv::{HirTyLowerer, OnlySelfBounds, PredicateFilter};
1616
use crate::bounds::Bounds;
1717
use crate::errors;
1818

19-
impl<'tcx> dyn AstConv<'tcx> + '_ {
19+
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2020
/// Sets `implicitly_sized` to true on `Bounds` if necessary
21-
pub(crate) fn add_implicitly_sized(
21+
pub(crate) fn add_sized_bound(
2222
&self,
2323
bounds: &mut Bounds<'tcx>,
2424
self_ty: Ty<'tcx>,
@@ -117,7 +117,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
117117
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
118118
/// for more details.
119119
#[instrument(level = "debug", skip(self, ast_bounds, bounds))]
120-
pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
120+
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
121121
&self,
122122
param_ty: Ty<'tcx>,
123123
ast_bounds: I,
@@ -145,7 +145,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
145145
}
146146
hir::TraitBoundModifier::Maybe => continue,
147147
};
148-
let _ = self.instantiate_poly_trait_ref(
148+
let _ = self.lower_poly_trait_ref(
149149
&poly_trait_ref.trait_ref,
150150
poly_trait_ref.span,
151151
constness,
@@ -156,7 +156,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
156156
);
157157
}
158158
hir::GenericBound::Outlives(lifetime) => {
159-
let region = self.ast_region_to_region(lifetime, None);
159+
let region = self.lower_lifetime(lifetime, None);
160160
bounds.push_region_bound(
161161
self.tcx(),
162162
ty::Binder::bind_with_vars(
@@ -186,7 +186,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
186186
/// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`.
187187
///
188188
/// `span` should be the declaration size of the parameter.
189-
pub(crate) fn compute_bounds(
189+
pub(crate) fn lower_mono_bounds(
190190
&self,
191191
param_ty: Ty<'tcx>,
192192
ast_bounds: &[hir::GenericBound<'tcx>],
@@ -201,7 +201,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
201201
PredicateFilter::SelfOnly | PredicateFilter::SelfThatDefines(_) => OnlySelfBounds(true),
202202
};
203203

204-
self.add_bounds(
204+
self.lower_poly_bounds(
205205
param_ty,
206206
ast_bounds.iter().filter(|bound| match filter {
207207
PredicateFilter::All
@@ -234,7 +234,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
234234
/// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside*
235235
/// the binder (e.g., `&'a u32`) and hence may reference bound regions.
236236
#[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))]
237-
pub(super) fn add_predicates_for_ast_type_binding(
237+
pub(super) fn lower_assoc_item_binding(
238238
&self,
239239
hir_ref_id: hir::HirId,
240240
trait_ref: ty::PolyTraitRef<'tcx>,
@@ -272,7 +272,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
272272
ty::AssocKind::Type
273273
};
274274

275-
let candidate = if self.trait_defines_associated_item_named(
275+
let candidate = if self.probe_trait_that_defines_assoc_item(
276276
trait_ref.def_id(),
277277
assoc_kind,
278278
binding.ident,
@@ -282,7 +282,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
282282
} else {
283283
// Otherwise, we have to walk through the supertraits to find
284284
// one that does define it.
285-
self.one_bound_for_assoc_item(
285+
self.probe_single_bound_for_assoc_item(
286286
|| traits::supertraits(tcx, trait_ref),
287287
trait_ref.skip_binder().print_only_trait_name(),
288288
None,
@@ -417,7 +417,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
417417
infer_args: false,
418418
};
419419

420-
let alias_args = self.create_args_for_associated_item(
420+
let alias_args = self.lower_generic_args_of_assoc_item(
421421
path_span,
422422
assoc_item.def_id,
423423
&item_segment,
@@ -451,7 +451,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
451451
}
452452
hir::TypeBindingKind::Equality { term } => {
453453
let term = match term {
454-
hir::Term::Ty(ty) => self.ast_ty_to_ty(ty).into(),
454+
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
455455
hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(),
456456
};
457457

@@ -514,7 +514,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
514514
// for the `Self` type.
515515
if !only_self_bounds.0 {
516516
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
517-
self.add_bounds(
517+
self.lower_poly_bounds(
518518
param_ty,
519519
ast_bounds.iter(),
520520
bounds,

compiler/rustc_hir_analysis/src/astconv/errors.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::astconv::AstConv;
1+
use crate::astconv::HirTyLowerer;
22
use crate::errors::{
33
self, AssocTypeBindingNotAllowed, ManualImplementation, MissingTypeParams,
44
ParenthesizedFnTraitExpansion,
@@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Ident};
2222
use rustc_span::{Span, Symbol, DUMMY_SP};
2323
use rustc_trait_selection::traits::object_safety_violations_for_assoc_item;
2424

25-
impl<'tcx> dyn AstConv<'tcx> + '_ {
25+
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2626
/// On missing type parameters, emit an E0393 error and provide a structured suggestion using
2727
/// the type parameter's name as a placeholder.
2828
pub(crate) fn complain_about_missing_type_params(
@@ -311,7 +311,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
311311
// FIXME(associated_const_equality): This has quite a few false positives and negatives.
312312
let wrap_in_braces_sugg = if let Some(binding) = binding
313313
&& let hir::TypeBindingKind::Equality { term: hir::Term::Ty(hir_ty) } = binding.kind
314-
&& let ty = self.ast_ty_to_ty(hir_ty)
314+
&& let ty = self.lower_ty(hir_ty)
315315
&& (ty.is_enum() || ty.references_error())
316316
&& tcx.features().associated_const_equality
317317
{
@@ -349,7 +349,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
349349
})
350350
}
351351

352-
pub(super) fn report_ambiguous_associated_type(
352+
pub(super) fn report_ambiguous_assoc_ty(
353353
&self,
354354
span: Span,
355355
types: &[String],
@@ -458,7 +458,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
458458
reported
459459
}
460460

461-
pub(crate) fn complain_about_ambiguous_inherent_assoc_type(
461+
pub(crate) fn complain_about_ambiguous_inherent_assoc_ty(
462462
&self,
463463
name: Ident,
464464
candidates: Vec<DefId>,
@@ -471,14 +471,14 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
471471
"multiple applicable items in scope"
472472
);
473473
err.span_label(name.span, format!("multiple `{name}` found"));
474-
self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span);
474+
self.note_ambiguous_inherent_assoc_ty(&mut err, candidates, span);
475475
let reported = err.emit();
476476
self.set_tainted_by_errors(reported);
477477
reported
478478
}
479479

480480
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
481-
fn note_ambiguous_inherent_assoc_type(
481+
fn note_ambiguous_inherent_assoc_ty(
482482
&self,
483483
err: &mut Diag<'_>,
484484
candidates: Vec<DefId>,
@@ -521,7 +521,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
521521
}
522522

523523
// FIXME(inherent_associated_types): Find similarly named associated types and suggest them.
524-
pub(crate) fn complain_about_inherent_assoc_type_not_found(
524+
pub(crate) fn complain_about_inherent_assoc_ty_not_found(
525525
&self,
526526
name: Ident,
527527
self_ty: Ty<'tcx>,
@@ -697,7 +697,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
697697
/// reasonable suggestion on how to write it. For the case of multiple associated types in the
698698
/// same trait bound have the same name (as they come from different supertraits), we instead
699699
/// emit a generic note suggesting using a `where` clause to constraint instead.
700-
pub(crate) fn complain_about_missing_associated_types(
700+
pub(crate) fn complain_about_missing_assoc_tys(
701701
&self,
702702
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
703703
potential_assoc_types: Vec<Span>,
@@ -1027,7 +1027,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
10271027
}
10281028

10291029
/// Emits an error regarding forbidden type binding associations
1030-
pub fn prohibit_assoc_ty_binding(
1030+
pub fn prohibit_assoc_item_binding(
10311031
tcx: TyCtxt<'_>,
10321032
span: Span,
10331033
segment: Option<(&hir::PathSegment<'_>, Span)>,

compiler/rustc_hir_analysis/src/astconv/generics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::IsMethodCall;
22
use crate::astconv::{
3-
errors::prohibit_assoc_ty_binding, CreateInstantiationsForGenericArgsCtxt, ExplicitLateBound,
4-
GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
3+
errors::prohibit_assoc_item_binding, ExplicitLateBound, GenericArgCountMismatch,
4+
GenericArgCountResult, GenericArgPosition, GenericArgsLowerer,
55
};
66
use crate::structured_errors::{GenericArgsInfo, StructuredDiag, WrongNumberOfGenericArgs};
77
use rustc_ast::ast::ParamKindOrd;
@@ -172,14 +172,14 @@ fn generic_arg_mismatch_err(
172172
/// instantiate a `GenericArg`.
173173
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
174174
/// creates a suitable inference variable.
175-
pub fn create_args_for_parent_generic_args<'tcx: 'a, 'a>(
175+
pub fn lower_generic_args<'tcx: 'a, 'a>(
176176
tcx: TyCtxt<'tcx>,
177177
def_id: DefId,
178178
parent_args: &[ty::GenericArg<'tcx>],
179179
has_self: bool,
180180
self_ty: Option<Ty<'tcx>>,
181181
arg_count: &GenericArgCountResult,
182-
ctx: &mut impl CreateInstantiationsForGenericArgsCtxt<'a, 'tcx>,
182+
ctx: &mut impl GenericArgsLowerer<'a, 'tcx>,
183183
) -> GenericArgsRef<'tcx> {
184184
// Collect the segments of the path; we need to instantiate arguments
185185
// for parameters throughout the entire path (wherever there are
@@ -456,7 +456,7 @@ pub(crate) fn check_generic_arg_count(
456456
if gen_pos != GenericArgPosition::Type
457457
&& let Some(b) = gen_args.bindings.first()
458458
{
459-
prohibit_assoc_ty_binding(tcx, b.span, None);
459+
prohibit_assoc_item_binding(tcx, b.span, None);
460460
}
461461

462462
let explicit_late_bound =

compiler/rustc_hir_analysis/src/astconv/lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
66
use rustc_span::Span;
77
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
88

9-
use super::AstConv;
9+
use super::HirTyLowerer;
1010

11-
impl<'tcx> dyn AstConv<'tcx> + '_ {
11+
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1212
/// Make sure that we are in the condition to suggest the blanket implementation.
1313
pub(super) fn maybe_lint_blanket_trait_impl<G: EmissionGuarantee>(
1414
&self,

0 commit comments

Comments
 (0)