Skip to content

Commit 3265527

Browse files
committed
Update (doc) comments
1 parent 23eabef commit 3265527

File tree

32 files changed

+120
-99
lines changed

32 files changed

+120
-99
lines changed

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree,
466466
visitor.visit_path(&use_tree.prefix, id);
467467
match &use_tree.kind {
468468
UseTreeKind::Simple(rename) => {
469-
// The extra IDs are handled during HIR lowering.
469+
// The extra IDs are handled during AST lowering.
470470
if let &Some(rename) = rename {
471471
visitor.visit_ident(rename);
472472
}

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
//! item id (`item_id`) in case of impl trait or path resolution id (`path_id`) otherwise.
3030
//!
3131
//! Since we do not have a proper way to obtain function type information by path resolution
32-
//! in AST, we mark each function parameter type as `InferDelegation` and inherit it in `AstConv`.
32+
//! in AST, we mark each function parameter type as `InferDelegation` and inherit it during
33+
//! HIR ty lowering.
3334
//!
3435
//! Similarly generics, predicates and header are set to the "default" values.
3536
//! In case of discrepancy with callee function the `NotSupportedDelegation` error will
36-
//! also be emitted in `AstConv`.
37+
//! also be emitted during HIR ty lowering.
3738
3839
use crate::{ImplTraitPosition, ResolverAstLoweringExt};
3940

@@ -133,7 +134,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
133134
) -> &'hir hir::FnDecl<'hir> {
134135
let args_count = if let Some(local_sig_id) = sig_id.as_local() {
135136
// Map may be filled incorrectly due to recursive delegation.
136-
// Error will be emmited later in astconv.
137+
// Error will be emitted later during HIR ty lowering.
137138
self.resolver.fn_parameter_counts.get(&local_sig_id).cloned().unwrap_or_default()
138139
} else {
139140
self.tcx.fn_arg_names(sig_id).len()

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
14161416
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
14171417
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
14181418
// these into hir when we lower thee where clauses), but this makes it quite difficult to
1419-
// keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and
1420-
// where clauses for `?Sized`.
1419+
// keep track of the Span info. Now, `<dyn HirTyLowerer>::add_implicitly_sized` checks both
1420+
// param bounds and where clauses for `?Sized`.
14211421
for pred in &generics.where_clause.predicates {
14221422
let WherePredicate::BoundPredicate(bound_pred) = pred else {
14231423
continue;

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
626626
| GenericArgKind::Const(_),
627627
_,
628628
) => {
629-
// HIR lowering sometimes doesn't catch this in erroneous
629+
// HIR ty lowering sometimes doesn't catch this in erroneous
630630
// programs, so we need to use span_delayed_bug here. See #82126.
631631
self.dcx().span_delayed_bug(
632632
hir_arg.span(),

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ pub enum ExprKind<'hir> {
18451845
/// Wraps the expression in a terminating scope.
18461846
/// This makes it semantically equivalent to `{ let _t = expr; _t }`.
18471847
///
1848-
/// This construct only exists to tweak the drop order in HIR lowering.
1848+
/// This construct only exists to tweak the drop order in AST lowering.
18491849
/// An example of that is the desugaring of `for` loops.
18501850
DropTemps(&'hir Expr<'hir>),
18511851
/// A `let $pat = $expr` expression.
@@ -2278,7 +2278,7 @@ pub enum ImplItemKind<'hir> {
22782278
/// Bind a type to an associated type (i.e., `A = Foo`).
22792279
///
22802280
/// Bindings like `A: Debug` are represented as a special type `A =
2281-
/// $::Debug` that is understood by the astconv code.
2281+
/// $::Debug` that is understood by the HIR ty lowering code.
22822282
///
22832283
/// FIXME(alexreg): why have a separate type for the binding case,
22842284
/// wouldn't it be better to make the `ty` field an enum like the

compiler/rustc_hir_analysis/src/astconv/bounds.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::bounds::Bounds;
1616
use crate::errors;
1717

1818
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19-
/// Sets `implicitly_sized` to true on `Bounds` if necessary
19+
/// Adds a `Sized` bound to the list of `bounds` unless the HIR bounds contain any of
20+
/// `Sized`, `?Sized` or `!Sized`.
2021
pub(crate) fn add_implicitly_sized(
2122
&self,
2223
bounds: &mut Bounds<'tcx>,
@@ -100,8 +101,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
100101
}
101102
}
102103

103-
/// This helper takes a *converted* parameter type (`param_ty`)
104-
/// and an *unconverted* list of bounds:
104+
/// Lower bounds into `bounds`.
105105
///
106106
/// ```text
107107
/// fn foo<T: Debug>
@@ -110,8 +110,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
110110
/// `param_ty`, in ty form
111111
/// ```
112112
///
113-
/// It adds these `ast_bounds` into the `bounds` structure.
114-
///
115113
/// **A note on binders:** there is an implied binder around
116114
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
117115
/// for more details.

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
//! Conversion from AST representation of types to the `ty.rs` representation.
2-
//! The main routine here is `ast_ty_to_ty()`; each use is parameterized by an
3-
//! instance of `AstConv`.
1+
//! HIR ty lowering: Lowers type-system entities from HIR to `rustc_middle::ty` representation.
2+
//!
3+
//! Not to be confused with *AST lowering* which lowers AST constructs to HIR ones.
4+
//!
5+
//! The main routine here is `<dyn HirTyLowerer>::lower_ty()`. The other routines
6+
//! are defined on `dyn HirTyLowerer` (see [`HirTyLowerer`]).
7+
//!
8+
//! This module used to be called `astconv`.
49
510
mod bounds;
611
mod errors;
@@ -69,6 +74,9 @@ pub enum PredicateFilter {
6974
SelfAndAssociatedTypeBounds,
7075
}
7176

77+
/// A context which can lower type-system entities from [HIR][hir] to [`rustc_middle::ty`] representation.
78+
///
79+
/// This trait used to be called `AstConv`.
7280
pub trait HirTyLowerer<'tcx> {
7381
fn tcx(&self) -> TyCtxt<'tcx>;
7482

@@ -127,6 +135,7 @@ pub trait HirTyLowerer<'tcx> {
127135
) -> Ty<'tcx>;
128136

129137
/// Returns `AdtDef` if `ty` is an ADT.
138+
///
130139
/// Note that `ty` might be a projection type that needs normalization.
131140
/// This used to get the enum variants in scope of the type.
132141
/// For example, `Self::A` could refer to an associated type
@@ -214,6 +223,7 @@ pub struct GenericArgCountResult {
214223
pub correct: Result<(), GenericArgCountMismatch>,
215224
}
216225

226+
/// A context which can lower HIR's [`GenericArg`] to `rustc_middle`'s [`ty::GenericArg`].
217227
pub trait GenericArgsLowerer<'a, 'tcx> {
218228
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'tcx>>, bool);
219229

@@ -309,7 +319,6 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
309319
if let Some(b) = item_segment.args().bindings.first() {
310320
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span)));
311321
}
312-
313322
args
314323
}
315324

@@ -593,7 +602,7 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
593602
&self,
594603
generic_args: &'a hir::GenericArgs<'tcx>,
595604
) -> Vec<LoweredBinding<'a, 'tcx>> {
596-
// Convert associated-type bindings or constraints into a separate vector.
605+
// Lower associated-type bindings or constraints into a separate vector.
597606
// Example: Given this:
598607
//
599608
// T: Iterator<Item = u32>
@@ -655,11 +664,9 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
655664
None,
656665
ty::BoundConstness::NotConst,
657666
);
658-
659667
if let Some(b) = item_segment.args().bindings.first() {
660668
prohibit_assoc_ty_binding(self.tcx(), b.span, Some((item_segment, span)));
661669
}
662-
663670
args
664671
}
665672

@@ -786,7 +793,7 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
786793
self_ty: Ty<'tcx>,
787794
trait_segment: &hir::PathSegment<'tcx>,
788795
is_impl: bool,
789-
// FIXME(effects) move all host param things in astconv to hir lowering
796+
// FIXME(effects): Move all host param things in HIR ty lowering to AST lowering.
790797
constness: ty::BoundConstness,
791798
) -> ty::TraitRef<'tcx> {
792799
let (generic_args, _) = self.lower_args_for_trait_ref(
@@ -973,10 +980,11 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
973980
reported
974981
}
975982

976-
// Search for a bound on a type parameter which includes the associated item
977-
// given by `assoc_name`. `ty_param_def_id` is the `DefId` of the type parameter
978-
// This function will fail if there are no suitable bounds or there is
979-
// any ambiguity.
983+
/// Search for a bound on a type parameter which includes the associated item given by `assoc_name`.
984+
///
985+
/// `ty_param_def_id` is the `DefId` of the type parameter.
986+
/// This function will fail if there are no suitable bounds or there is any ambiguity.
987+
#[instrument(level = "debug", skip(self), ret)]
980988
fn find_bound_for_assoc_item(
981989
&self,
982990
ty_param_def_id: LocalDefId,
@@ -1015,8 +1023,8 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
10151023
)
10161024
}
10171025

1018-
// Checks that `bounds` contains exactly one element and reports appropriate
1019-
// errors otherwise.
1026+
// FIXME(fmease): This also *resolves* the bound. Update docs!
1027+
/// Checks that `bounds` contains exactly one element and reports appropriate errors otherwise.
10201028
#[instrument(level = "debug", skip(self, all_candidates, ty_param_name, binding), ret)]
10211029
fn one_bound_for_assoc_item<I>(
10221030
&self,
@@ -1133,12 +1141,14 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
11331141
Ok(bound)
11341142
}
11351143

1136-
// Create a type from a path to an associated type or to an enum variant.
1137-
// For a path `A::B::C::D`, `qself_ty` and `qself_def` are the type and def for `A::B::C`
1138-
// and item_segment is the path segment for `D`. We return a type and a def for
1139-
// the whole path.
1140-
// Will fail except for `T::A` and `Self::A`; i.e., if `qself_ty`/`qself_def` are not a type
1141-
// parameter or `Self`.
1144+
/// Create a type from a path to an associated type or to an enum variant.
1145+
///
1146+
/// For a path `A::B::C::D`, `qself_ty` and `qself` are the type and def for `A::B::C`
1147+
/// and item_segment is the path segment for `D`. We return a type and a def for
1148+
/// the whole path.
1149+
///
1150+
/// Will fail except for `T::A` and `Self::A`; i.e., if `qself_ty`/`qself` are not a type
1151+
/// parameter or `Self`.
11421152
// NOTE: When this function starts resolving `Trait::AssocTy` successfully
11431153
// it should also start reporting the `BARE_TRAIT_OBJECTS` lint.
11441154
#[instrument(level = "debug", skip(self, hir_ref_id, span, qself, assoc_segment), fields(assoc_ident=?assoc_segment.ident), ret)]
@@ -1436,8 +1446,9 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
14361446
// Don't attempt to look up inherent associated types when the feature is not enabled.
14371447
// Theoretically it'd be fine to do so since we feature-gate their definition site.
14381448
// However, due to current limitations of the implementation (caused by us performing
1439-
// selection in AstConv), IATs can lead to cycle errors (#108491, #110106) which mask the
1440-
// feature-gate error, needlessly confusing users that use IATs by accident (#113265).
1449+
// selection during HIR ty lowering instead of in the trait solver), IATs can lead to cycle
1450+
// errors (#108491, #110106) which mask the feature-gate error, needlessly confusing users
1451+
// who use IATs by accident (#113265).
14411452
if !tcx.features().inherent_associated_types {
14421453
return Ok(None);
14431454
}
@@ -2013,7 +2024,7 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
20132024
path_segs
20142025
}
20152026

2016-
/// Check a type `Path` and convert it to a `Ty`.
2027+
/// Check a type `Path` and lower it to a `Ty`.
20172028
pub fn lower_res_to_ty(
20182029
&self,
20192030
opt_self_ty: Option<Ty<'tcx>>,
@@ -2053,7 +2064,7 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
20532064
self.lower_path_to_ty(span, did, path.segments.last().unwrap())
20542065
}
20552066
Res::Def(kind @ DefKind::Variant, def_id) if permit_variants => {
2056-
// Convert "variant type" as if it were a real type.
2067+
// Lower "variant type" as if it were a real type.
20572068
// The resulting `Ty` is type of the variant's enum for now.
20582069
assert_eq!(opt_self_ty, None);
20592070

@@ -2254,8 +2265,8 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
22542265
}
22552266
}
22562267

2257-
// Converts a hir id corresponding to a type parameter to
2258-
// a early-bound `ty::Param` or late-bound `ty::Bound`.
2268+
/// Lower a `HirId` corresponding to a type parameter to an early-bound
2269+
/// [`ty::Param`] or late-bound [`ty::Bound`].
22592270
pub(crate) fn lower_type_param(&self, hir_id: hir::HirId) -> Ty<'tcx> {
22602271
let tcx = self.tcx();
22612272
match tcx.named_bound_var(hir_id) {
@@ -2279,8 +2290,8 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
22792290
}
22802291
}
22812292

2282-
// Converts a hir id corresponding to a const parameter to
2283-
// a early-bound `ConstKind::Param` or late-bound `ConstKind::Bound`.
2293+
/// Lower a `HirId` corresponding to a const parameter to an early-bound
2294+
/// [`ty::ConstKind::Param`] or late-bound [`ty::ConstKind::Bound`].
22842295
pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
22852296
let tcx = self.tcx();
22862297
match tcx.named_bound_var(hir_id) {
@@ -2421,8 +2432,10 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
24212432
}
24222433
}
24232434

2424-
/// Turns a `hir::Ty` into a `Ty`. For diagnostics' purposes we keep track of whether trait
2425-
/// objects are borrowed like `&dyn Trait` to avoid emitting redundant errors.
2435+
/// Lowers a [`hir::Ty`] to a [`Ty`].
2436+
///
2437+
/// For diagnostics' purposes we keep track of whether trait objects are
2438+
/// borrowed like `&dyn Trait` to avoid emitting redundant errors.
24262439
#[instrument(level = "debug", skip(self), ret)]
24272440
fn lower_ty_inner(&self, ast_ty: &hir::Ty<'tcx>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
24282441
let tcx = self.tcx();
@@ -2822,7 +2835,9 @@ impl<'o, 'tcx> dyn HirTyLowerer<'tcx> + 'o {
28222835
}
28232836

28242837
/// Given the bounds on an object, determines what single region bound (if any) we can
2825-
/// use to summarize this type. The basic idea is that we will use the bound the user
2838+
/// use to summarize this type.
2839+
///
2840+
/// The basic idea is that we will use the bound the user
28262841
/// provided, if they provided one, and otherwise search the supertypes of trait bounds
28272842
/// for region bounds. It may be that we can derive no bound at all, in which case
28282843
/// we return `None`.

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! Bounds are restrictions applied to some types after they've been converted into the
2-
//! `ty` form from the HIR.
1+
//! Bounds are restrictions applied to some types after they've been lowered from the HIR to the
2+
//! [`rustc_middle::ty`] form.
33
44
use rustc_hir::LangItem;
55
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
745745

746746
// We may not collect all RPITITs that we see in the HIR for a trait signature
747747
// because an RPITIT was located within a missing item. Like if we have a sig
748-
// returning `-> Missing<impl Sized>`, that gets converted to `-> [type error]`,
748+
// returning `-> Missing<impl Sized>`, that gets converted to `-> {type error}`,
749749
// and when walking through the signature we end up never collecting the def id
750750
// of the `impl Sized`. Insert that here, so we don't ICE later.
751751
for assoc_item in tcx.associated_types_for_impl_traits_in_associated_fn(trait_m.def_id) {

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ impl<'tcx> RegionResolutionVisitor<'tcx> {
760760

761761
fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
762762
// If node was previously marked as a terminating scope during the
763-
// recursive visit of its parent node in the AST, then we need to
763+
// recursive visit of its parent node in the HIR, then we need to
764764
// account for the destruction scope representing the scope of
765765
// the destructors that run immediately after it completes.
766766
if self.terminating_scopes.contains(&id) {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
266266
}
267267
Some(ty::ImplPolarity::Negative) => {
268268
let ast::ImplPolarity::Negative(span) = impl_.polarity else {
269-
bug!("impl_polarity query disagrees with impl's polarity in AST");
269+
bug!("impl_polarity query disagrees with impl's polarity in HIR");
270270
};
271271
// FIXME(#27579): what amount of WF checking do we need for neg impls?
272272
if let hir::Defaultness::Default { .. } = impl_.defaultness {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ pub fn provide(providers: &mut Providers) {
9191

9292
///////////////////////////////////////////////////////////////////////////
9393

94-
/// Context specific to some particular item. This is what implements
95-
/// [`AstConv`].
94+
/// Context specific to some particular item. This is what implements [`HirTyLowerer`].
9695
///
9796
/// # `ItemCtxt` vs `FnCtxt`
9897
///
9998
/// `ItemCtxt` is primarily used to type-check item signatures and lower them
100-
/// from HIR to their [`ty::Ty`] representation, which is exposed using [`AstConv`].
99+
/// from HIR to their [`ty::Ty`] representation, which is exposed using [`HirTyLowerer`].
101100
/// It's also used for the bodies of items like structs where the body (the fields)
102101
/// are just signatures.
103102
///
@@ -114,11 +113,11 @@ pub fn provide(providers: &mut Providers) {
114113
/// `ItemCtxt` has information about the predicates that are defined
115114
/// on the trait. Unfortunately, this predicate information is
116115
/// available in various different forms at various points in the
117-
/// process. So we can't just store a pointer to e.g., the AST or the
116+
/// process. So we can't just store a pointer to e.g., the HIR or the
118117
/// parsed ty form, we have to be more flexible. To this end, the
119118
/// `ItemCtxt` is parameterized by a `DefId` that it uses to satisfy
120119
/// `get_type_parameter_bounds` requests, drawing the information from
121-
/// the AST (`hir::Generics`), recursively.
120+
/// the HIR (`hir::Generics`), recursively.
122121
pub struct ItemCtxt<'tcx> {
123122
tcx: TyCtxt<'tcx>,
124123
item_def_id: LocalDefId,
@@ -1524,7 +1523,7 @@ fn impl_trait_header(
15241523
// we have a const impl, but for a trait without `#[const_trait]`, so
15251524
// without the host param. If we continue with the HIR trait ref, we get
15261525
// ICEs for generic arg count mismatch. We do a little HIR editing to
1527-
// make astconv happy.
1526+
// make HIR ty lowering happy.
15281527
let mut path_segments = ast_trait_ref.path.segments.to_vec();
15291528
let last_segment = path_segments.len() - 1;
15301529
let mut args = *path_segments[last_segment].args();

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ pub(super) fn explicit_item_bounds(
119119
let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args);
120120
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
121121
}
122-
// Since RPITITs are astconv'd as projections in `ast_ty_to_ty`, when we're asking
123-
// for the item bounds of the *opaques* in a trait's default method signature, we
122+
// Since RPITITs are lowered as projections in `<dyn HirTyLowerer>::lower_ty`, when we're
123+
// asking for the item bounds of the *opaques* in a trait's default method signature, we
124124
// need to map these projections back to opaques.
125125
hir::Node::Item(hir::Item {
126126
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, in_trait: true, origin, .. }),

0 commit comments

Comments
 (0)