Skip to content

Commit f2d054e

Browse files
committed
Update (doc) comments
1 parent 2e6a9d6 commit f2d054e

File tree

32 files changed

+177
-140
lines changed

32 files changed

+177
-140
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_implicit_sized_bound`
1420+
// checks both 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: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use crate::bounds::Bounds;
1414
use crate::errors;
1515

1616
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
17-
/// Sets `implicitly_sized` to true on `Bounds` if necessary
17+
/// Add a `Sized` bound to the `bounds` unless the HIR bounds contain any of
18+
/// `Sized`, `?Sized` or `!Sized`.
1819
pub(crate) fn add_implicit_sized_bound(
1920
&self,
2021
bounds: &mut Bounds<'tcx>,
@@ -98,21 +99,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
9899
}
99100
}
100101

101-
/// This helper takes a *converted* parameter type (`param_ty`)
102-
/// and an *unconverted* list of bounds:
102+
/// Lower HIR bounds into `bounds` given the self type `param_ty`.
103103
///
104-
/// ```text
105-
/// fn foo<T: Debug>
106-
/// ^ ^^^^^ `ast_bounds` parameter, in HIR form
104+
/// ### Example
105+
///
106+
/// ```ignore (illustrative)
107+
/// fn foo<T: Debug>() { }
108+
/// ^ ^^^^^ `ast_bounds`, in HIR form
107109
/// |
108110
/// `param_ty`, in ty form
109111
/// ```
110112
///
111-
/// It adds these `ast_bounds` into the `bounds` structure.
113+
/// ### A Note on Binders
112114
///
113-
/// **A note on binders:** there is an implied binder around
114-
/// `param_ty` and `ast_bounds`. See `instantiate_poly_trait_ref`
115-
/// for more details.
115+
/// There is an implied binder around `param_ty` and `ast_bounds`.
116+
/// See `lower_poly_trait_ref` for more details.
116117
#[instrument(level = "debug", skip(self, ast_bounds, bounds))]
117118
pub(crate) fn lower_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
118119
&self,
@@ -168,22 +169,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
168169
}
169170
}
170171

171-
/// Translates a list of bounds from the HIR into the `Bounds` data structure.
172-
/// The self-type for the bounds is given by `param_ty`.
172+
// FIXME(astconv-no-mo): Currently this has the same docs as `lower_bounds`.
173+
/// Lower HIR bounds into `bounds` given the self type `param_ty`.
173174
///
174-
/// Example:
175+
/// ### Example
175176
///
176177
/// ```ignore (illustrative)
177178
/// fn foo<T: Bar + Baz>() { }
178179
/// // ^ ^^^^^^^^^ ast_bounds
179180
/// // param_ty
180181
/// ```
181-
///
182-
/// The `sized_by_default` parameter indicates if, in this context, the `param_ty` should be
183-
/// considered `Sized` unless there is an explicit `?Sized` bound. This would be true in the
184-
/// example above, but is not true in supertrait listings like `trait Foo: Bar + Baz`.
185-
///
186-
/// `span` should be the declaration size of the parameter.
182+
// FIXME(astconv-no-more): This should renamed to make it clear how it differs from `lower_bounds`
183+
// Maybe `lower_mono_bounds` (as in no bound vars)?
187184
pub(crate) fn compute_bounds(
188185
&self,
189186
param_ty: Ty<'tcx>,
@@ -225,12 +222,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
225222
bounds
226223
}
227224

228-
/// Given an HIR binding like `Item = Foo` or `Item: Foo`, pushes the corresponding predicates
229-
/// onto `bounds`.
225+
// FIXME(astconv-no-mo): Expand these docs!
226+
/// Lower an associated item binding from HIR into `bounds`.
227+
///
228+
/// ### A Note on Binders
230229
///
231-
/// **A note on binders:** given something like `T: for<'a> Iterator<Item = &'a u32>`, the
232-
/// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside*
233-
/// the binder (e.g., `&'a u32`) and hence may reference bound regions.
230+
/// Given something like `T: for<'a> Iterator<Item = &'a u32>`, the `trait_ref` here will be
231+
/// `for<'a> T: Iterator`. The `binding` data however is from *inside* the binder (e.g., `&'a u32`)
232+
/// and hence may reference bound regions.
234233
#[instrument(level = "debug", skip(self, bounds, speculative, dup_bindings, path_span))]
235234
pub(super) fn lower_assoc_item_binding(
236235
&self,
@@ -243,6 +242,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
243242
path_span: Span,
244243
only_self_bounds: OnlySelfBounds,
245244
) -> Result<(), ErrorGuaranteed> {
245+
// FIXME(astconv-no-mo): Update this comment / move it someplace better.
246246
// Given something like `U: SomeTrait<T = X>`, we want to produce a
247247
// predicate like `<U as SomeTrait>::T = X`. This is somewhat
248248
// subtle in the event that `T` is defined in a supertrait of
@@ -436,6 +436,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
436436
span: binding.span,
437437
}));
438438
}
439+
// Lower an equality constraint like `Item = u32` as found in HIR bound `T: Iterator<Item = u32>`
440+
// to a projection predicate: `<T as Iterator>::Item = u32`.
439441
hir::TypeBindingKind::Equality { term } => {
440442
let term = match term {
441443
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
@@ -479,29 +481,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
479481
);
480482
}
481483

482-
// "Desugar" a constraint like `T: Iterator<Item = u32>` this to
483-
// the "projection predicate" for:
484-
//
485-
// `<T as Iterator>::Item = u32`
486484
bounds.push_projection_bound(
487485
tcx,
488486
projection_ty
489487
.map_bound(|projection_ty| ty::ProjectionPredicate { projection_ty, term }),
490488
binding.span,
491489
);
492490
}
491+
// Lower a constraint like `Item: Debug` as found in HIR bound `T: Iterator<Item: Debug>`
492+
// to a bound involving a projection: `<T as Iterator>::Item: Debug`.
493493
hir::TypeBindingKind::Constraint { bounds: ast_bounds } => {
494-
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
495-
//
496-
// `<T as Iterator>::Item: Debug`
497-
//
498-
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
499-
// parameter to have a skipped binder.
500-
//
501-
// NOTE: If `only_self_bounds` is true, do NOT expand this associated
502-
// type bound into a trait predicate, since we only want to add predicates
503-
// for the `Self` type.
494+
// NOTE: If `only_self_bounds` is true, do NOT expand this associated type bound into
495+
// a trait predicate, since we only want to add predicates for the `Self` type.
504496
if !only_self_bounds.0 {
497+
// Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty`
498+
// parameter to have a skipped binder.
505499
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
506500
self.lower_bounds(
507501
param_ty,

0 commit comments

Comments
 (0)