Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d4675aa

Browse files
committed
Turn some comments into docs
1 parent eec21d2 commit d4675aa

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
166166
.clone()
167167
}
168168

169-
// This method calculates two things: Lifetime constraints of the form 'a: 'b,
170-
// and region constraints of the form ReVar: 'a
171-
//
172-
// This is essentially a simplified version of lexical_region_resolve. However,
173-
// handle_lifetimes determines what *needs be* true in order for an impl to hold.
174-
// lexical_region_resolve, along with much of the rest of the compiler, is concerned
175-
// with determining if a given set up constraints/predicates *are* met, given some
176-
// starting conditions (e.g., user-provided code). For this reason, it's easier
177-
// to perform the calculations we need on our own, rather than trying to make
178-
// existing inference/solver code do what we want.
169+
/// This method calculates two things: Lifetime constraints of the form `'a: 'b`,
170+
/// and region constraints of the form `RegionVid: 'a`
171+
///
172+
/// This is essentially a simplified version of lexical_region_resolve. However,
173+
/// handle_lifetimes determines what *needs be* true in order for an impl to hold.
174+
/// lexical_region_resolve, along with much of the rest of the compiler, is concerned
175+
/// with determining if a given set up constraints/predicates *are* met, given some
176+
/// starting conditions (e.g., user-provided code). For this reason, it's easier
177+
/// to perform the calculations we need on our own, rather than trying to make
178+
/// existing inference/solver code do what we want.
179179
fn handle_lifetimes<'cx>(
180180
regions: &RegionConstraintData<'cx>,
181181
names_map: &FxHashMap<Symbol, Lifetime>,
@@ -410,15 +410,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
410410
.collect()
411411
}
412412

413-
// Converts the calculated ParamEnv and lifetime information to a clean::Generics, suitable for
414-
// display on the docs page. Cleaning the Predicates produces sub-optimal `WherePredicate`s,
415-
// so we fix them up:
416-
//
417-
// * Multiple bounds for the same type are coalesced into one: e.g., 'T: Copy', 'T: Debug'
418-
// becomes 'T: Copy + Debug'
419-
// * Fn bounds are handled specially - instead of leaving it as 'T: Fn(), <T as Fn::Output> =
420-
// K', we use the dedicated syntax 'T: Fn() -> K'
421-
// * We explicitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
413+
/// Converts the calculated `ParamEnv` and lifetime information to a [`clean::Generics`](Generics), suitable for
414+
/// display on the docs page. Cleaning the `Predicates` produces sub-optimal [`WherePredicate`]s,
415+
/// so we fix them up:
416+
///
417+
/// * Multiple bounds for the same type are coalesced into one: e.g., `T: Copy`, `T: Debug`
418+
/// becomes `T: Copy + Debug`
419+
/// * `Fn` bounds are handled specially - instead of leaving it as `T: Fn(), <T as Fn::Output> =
420+
/// K`, we use the dedicated syntax `T: Fn() -> K`
421+
/// * We explicitly add a `?Sized` bound if we didn't find any `Sized` predicates for a type
422422
fn param_env_to_generics(
423423
&mut self,
424424
item_def_id: DefId,
@@ -632,11 +632,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
632632
Generics { params: generic_params, where_predicates: existing_predicates }
633633
}
634634

635-
// Ensure that the predicates are in a consistent order. The precise
636-
// ordering doesn't actually matter, but it's important that
637-
// a given set of predicates always appears in the same order -
638-
// both for visual consistency between 'rustdoc' runs, and to
639-
// make writing tests much easier
635+
/// Ensure that the predicates are in a consistent order. The precise
636+
/// ordering doesn't actually matter, but it's important that
637+
/// a given set of predicates always appears in the same order -
638+
/// both for visual consistency between 'rustdoc' runs, and to
639+
/// make writing tests much easier
640640
#[inline]
641641
fn sort_where_predicates(&self, mut predicates: &mut Vec<WherePredicate>) {
642642
// We should never have identical bounds - and if we do,
@@ -645,11 +645,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
645645
self.unstable_debug_sort(&mut predicates);
646646
}
647647

648-
// Ensure that the bounds are in a consistent order. The precise
649-
// ordering doesn't actually matter, but it's important that
650-
// a given set of bounds always appears in the same order -
651-
// both for visual consistency between 'rustdoc' runs, and to
652-
// make writing tests much easier
648+
/// Ensure that the bounds are in a consistent order. The precise
649+
/// ordering doesn't actually matter, but it's important that
650+
/// a given set of bounds always appears in the same order -
651+
/// both for visual consistency between 'rustdoc' runs, and to
652+
/// make writing tests much easier
653653
#[inline]
654654
fn sort_where_bounds(&self, mut bounds: &mut Vec<GenericBound>) {
655655
// We should never have identical bounds - and if we do,
@@ -658,33 +658,33 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
658658
self.unstable_debug_sort(&mut bounds);
659659
}
660660

661-
// This might look horrendously hacky, but it's actually not that bad.
662-
//
663-
// For performance reasons, we use several different FxHashMaps
664-
// in the process of computing the final set of where predicates.
665-
// However, the iteration order of a HashMap is completely unspecified.
666-
// In fact, the iteration of an FxHashMap can even vary between platforms,
667-
// since FxHasher has different behavior for 32-bit and 64-bit platforms.
668-
//
669-
// Obviously, it's extremely undesirable for documentation rendering
670-
// to be dependent on the platform it's run on. Apart from being confusing
671-
// to end users, it makes writing tests much more difficult, as predicates
672-
// can appear in any order in the final result.
673-
//
674-
// To solve this problem, we sort WherePredicates and GenericBounds
675-
// by their Debug string. The thing to keep in mind is that we don't really
676-
// care what the final order is - we're synthesizing an impl or bound
677-
// ourselves, so any order can be considered equally valid. By sorting the
678-
// predicates and bounds, however, we ensure that for a given codebase, all
679-
// auto-trait impls always render in exactly the same way.
680-
//
681-
// Using the Debug implementation for sorting prevents us from needing to
682-
// write quite a bit of almost entirely useless code (e.g., how should two
683-
// Types be sorted relative to each other). It also allows us to solve the
684-
// problem for both WherePredicates and GenericBounds at the same time. This
685-
// approach is probably somewhat slower, but the small number of items
686-
// involved (impls rarely have more than a few bounds) means that it
687-
// shouldn't matter in practice.
661+
/// This might look horrendously hacky, but it's actually not that bad.
662+
///
663+
/// For performance reasons, we use several different FxHashMaps
664+
/// in the process of computing the final set of where predicates.
665+
/// However, the iteration order of a HashMap is completely unspecified.
666+
/// In fact, the iteration of an FxHashMap can even vary between platforms,
667+
/// since FxHasher has different behavior for 32-bit and 64-bit platforms.
668+
///
669+
/// Obviously, it's extremely undesirable for documentation rendering
670+
/// to be dependent on the platform it's run on. Apart from being confusing
671+
/// to end users, it makes writing tests much more difficult, as predicates
672+
/// can appear in any order in the final result.
673+
///
674+
/// To solve this problem, we sort WherePredicates and GenericBounds
675+
/// by their Debug string. The thing to keep in mind is that we don't really
676+
/// care what the final order is - we're synthesizing an impl or bound
677+
/// ourselves, so any order can be considered equally valid. By sorting the
678+
/// predicates and bounds, however, we ensure that for a given codebase, all
679+
/// auto-trait impls always render in exactly the same way.
680+
///
681+
/// Using the Debug implementation for sorting prevents us from needing to
682+
/// write quite a bit of almost entirely useless code (e.g., how should two
683+
/// Types be sorted relative to each other). It also allows us to solve the
684+
/// problem for both WherePredicates and GenericBounds at the same time. This
685+
/// approach is probably somewhat slower, but the small number of items
686+
/// involved (impls rarely have more than a few bounds) means that it
687+
/// shouldn't matter in practice.
688688
fn unstable_debug_sort<T: Debug>(&self, vec: &mut Vec<T>) {
689689
vec.sort_by_cached_key(|x| format!("{:?}", x))
690690
}
@@ -705,7 +705,7 @@ fn region_name(region: Region<'_>) -> Option<Symbol> {
705705
}
706706
}
707707

708-
// Replaces all ReVars in a type with ty::Region's, using the provided map
708+
/// Replaces all [`ty::RegionVid`]s in a type with [`ty::Region`]s, using the provided map.
709709
struct RegionReplacer<'a, 'tcx> {
710710
vid_to_region: &'a FxHashMap<ty::RegionVid, ty::Region<'tcx>>,
711711
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)