Skip to content

Commit 34063c5

Browse files
committed
infer: fix and improve comments
1 parent 70adb4e commit 34063c5

File tree

1 file changed

+32
-29
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+32
-29
lines changed

compiler/rustc_infer/src/infer/mod.rs

+32-29
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,26 @@ pub struct InferCtxtInner<'tcx> {
114114
float_unification_storage: ut::UnificationTableStorage<ty::FloatVid>,
115115

116116
/// Tracks the set of region variables and the constraints between them.
117+
///
117118
/// This is initially `Some(_)` but when
118119
/// `resolve_regions_and_report_errors` is invoked, this gets set to `None`
119120
/// -- further attempts to perform unification, etc., may fail if new
120121
/// region constraints would've been added.
121122
region_constraint_storage: Option<RegionConstraintStorage<'tcx>>,
122123

123-
/// A set of constraints that regionck must validate. Each
124-
/// constraint has the form `T:'a`, meaning "some type `T` must
124+
/// A set of constraints that regionck must validate.
125+
///
126+
/// Each constraint has the form `T:'a`, meaning "some type `T` must
125127
/// outlive the lifetime 'a". These constraints derive from
126128
/// instantiated type parameters. So if you had a struct defined
127-
/// like
129+
/// like the following:
128130
/// ```ignore (illustrative)
129-
/// struct Foo<T:'static> { ... }
131+
/// struct Foo<T: 'static> { ... }
130132
/// ```
131-
/// then in some expression `let x = Foo { ... }` it will
133+
/// In some expression `let x = Foo { ... }`, it will
132134
/// instantiate the type parameter `T` with a fresh type `$0`. At
133135
/// the same time, it will record a region obligation of
134-
/// `$0:'static`. This will get checked later by regionck. (We
136+
/// `$0: 'static`. This will get checked later by regionck. (We
135137
/// can't generally check these things right away because we have
136138
/// to wait until types are resolved.)
137139
///
@@ -268,7 +270,7 @@ pub struct InferCtxt<'tcx> {
268270
/// Caches the results of trait evaluation.
269271
pub evaluation_cache: select::EvaluationCache<'tcx>,
270272

271-
/// the set of predicates on which errors have been reported, to
273+
/// The set of predicates on which errors have been reported, to
272274
/// avoid reporting the same error twice.
273275
pub reported_trait_errors: RefCell<FxIndexMap<Span, Vec<ty::Predicate<'tcx>>>>,
274276

@@ -291,7 +293,7 @@ pub struct InferCtxt<'tcx> {
291293
tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
292294

293295
/// Track how many errors were reported when this infcx is created.
294-
/// If the number of errors increases, that's also a sign (line
296+
/// If the number of errors increases, that's also a sign (like
295297
/// `tainted_by_errors`) to avoid reporting certain kinds of errors.
296298
// FIXME(matthewjasper) Merge into `tainted_by_errors`
297299
err_count_on_creation: usize,
@@ -313,7 +315,7 @@ pub struct InferCtxt<'tcx> {
313315
/// During coherence we have to assume that other crates may add
314316
/// additional impls which we currently don't know about.
315317
///
316-
/// To deal with this evaluation should be conservative
318+
/// To deal with this evaluation, we should be conservative
317319
/// and consider the possibility of impls from outside this crate.
318320
/// This comes up primarily when resolving ambiguity. Imagine
319321
/// there is some trait reference `$0: Bar` where `$0` is an
@@ -323,7 +325,7 @@ pub struct InferCtxt<'tcx> {
323325
/// bound to some type that in a downstream crate that implements
324326
/// `Bar`.
325327
///
326-
/// Outside of coherence we set this to false because we are only
328+
/// Outside of coherence, we set this to false because we are only
327329
/// interested in types that the user could actually have written.
328330
/// In other words, we consider `$0: Bar` to be unimplemented if
329331
/// there is no type that the user could *actually name* that
@@ -373,7 +375,7 @@ pub enum SubregionOrigin<'tcx> {
373375
Subtype(Box<TypeTrace<'tcx>>),
374376

375377
/// When casting `&'a T` to an `&'b Trait` object,
376-
/// relating `'a` to `'b`
378+
/// relating `'a` to `'b`.
377379
RelateObjectBound(Span),
378380

379381
/// Some type parameter was instantiated with the given type,
@@ -384,7 +386,7 @@ pub enum SubregionOrigin<'tcx> {
384386
/// that must outlive some other region.
385387
RelateRegionParamBound(Span),
386388

387-
/// Creating a pointer `b` to contents of another reference
389+
/// Creating a pointer `b` to contents of another reference.
388390
Reborrow(Span),
389391

390392
/// (&'a &'b T) where a >= b
@@ -398,7 +400,7 @@ pub enum SubregionOrigin<'tcx> {
398400
trait_item_def_id: DefId,
399401
},
400402

401-
/// Checking that the bounds of a trait's associated type hold for a given impl
403+
/// Checking that the bounds of a trait's associated type hold for a given impl.
402404
CheckAssociatedTypeBounds {
403405
parent: Box<SubregionOrigin<'tcx>>,
404406
impl_item_def_id: LocalDefId,
@@ -435,32 +437,33 @@ pub enum LateBoundRegionConversionTime {
435437
AssocTypeProjection(DefId),
436438
}
437439

438-
/// Reasons to create a region inference variable
440+
/// Reasons to create a region inference variable.
439441
///
440-
/// See `error_reporting` module for more details
442+
/// See `error_reporting` module for more details.
441443
#[derive(Copy, Clone, Debug)]
442444
pub enum RegionVariableOrigin {
443-
/// Region variables created for ill-categorized reasons,
444-
/// mostly indicates places in need of refactoring
445+
/// Region variables created for ill-categorized reasons.
446+
///
447+
/// They mostly indicate places in need of refactoring.
445448
MiscVariable(Span),
446449

447-
/// Regions created by a `&P` or `[...]` pattern
450+
/// Regions created by a `&P` or `[...]` pattern.
448451
PatternRegion(Span),
449452

450-
/// Regions created by `&` operator
453+
/// Regions created by `&` operator.
454+
///
451455
AddrOfRegion(Span),
452-
453-
/// Regions created as part of an autoref of a method receiver
456+
/// Regions created as part of an autoref of a method receiver.
454457
Autoref(Span),
455458

456-
/// Regions created as part of an automatic coercion
459+
/// Regions created as part of an automatic coercion.
457460
Coercion(Span),
458461

459-
/// Region variables created as the values for early-bound regions
462+
/// Region variables created as the values for early-bound regions.
460463
EarlyBoundRegion(Span, Symbol),
461464

462465
/// Region variables created for bound regions
463-
/// in a function or method that is called
466+
/// in a function or method that is called.
464467
LateBoundRegion(Span, ty::BoundRegionKind, LateBoundRegionConversionTime),
465468

466469
UpvarRegion(ty::UpvarId, Span),
@@ -534,7 +537,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
534537
}
535538
}
536539

537-
/// Used to configure inference contexts before their creation
540+
/// Used to configure inference contexts before their creation.
538541
pub struct InferCtxtBuilder<'tcx> {
539542
tcx: TyCtxt<'tcx>,
540543
defining_use_anchor: DefiningAnchor,
@@ -835,9 +838,9 @@ impl<'tcx> InferCtxt<'tcx> {
835838

836839
/// Scan the constraints produced since `snapshot` began and returns:
837840
///
838-
/// - `None` -- if none of them involve "region outlives" constraints
839-
/// - `Some(true)` -- if there are `'a: 'b` constraints where `'a` or `'b` is a placeholder
840-
/// - `Some(false)` -- if there are `'a: 'b` constraints but none involve placeholders
841+
/// - `None` -- if none of them involves "region outlives" constraints.
842+
/// - `Some(true)` -- if there are `'a: 'b` constraints where `'a` or `'b` is a placeholder.
843+
/// - `Some(false)` -- if there are `'a: 'b` constraints but none involve placeholders.
841844
pub fn region_constraints_added_in_snapshot(
842845
&self,
843846
snapshot: &CombinedSnapshot<'tcx>,
@@ -1770,7 +1773,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17701773
}
17711774
}
17721775

1773-
/// Helper for `ty_or_const_infer_var_changed` (see comment on that), currently
1776+
/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently
17741777
/// used only for `traits::fulfill`'s list of `stalled_on` inference variables.
17751778
#[derive(Copy, Clone, Debug)]
17761779
pub enum TyOrConstInferVar<'tcx> {

0 commit comments

Comments
 (0)