Skip to content

Commit 049f4d8

Browse files
author
Alexander Regueiro
committed
document the Bounds struct a bit
1 parent 963e22c commit 049f4d8

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,17 +2287,52 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
22872287
}
22882288
}
22892289

2290-
// A helper struct for conveniently grouping a set of bounds which we pass to
2291-
// and return from functions in multiple places.
2290+
/// Collects together a list of bounds that are applied to some type,
2291+
/// after they've been converted into `ty` form (from the HIR
2292+
/// representations). These lists of bounds occur in many places in
2293+
/// Rust's syntax:
2294+
///
2295+
/// ```
2296+
/// trait Foo: Bar + Baz { }
2297+
/// ^^^^^^^^^ supertrait list bounding the `Self` type parameter
2298+
///
2299+
/// fn foo<T: Bar + Baz>() { }
2300+
/// ^^^^^^^^^ bounding the type parameter `T`
2301+
///
2302+
/// impl dyn Bar + Baz
2303+
/// ^^^^^^^^^ bounding the forgotten dynamic type
2304+
/// ```
2305+
///
2306+
/// Our representation is a bit mixed here -- in some cases, we
2307+
/// include the self type (e.g., `trait_bounds`) but in others we do
22922308
#[derive(Default, PartialEq, Eq, Clone, Debug)]
22932309
pub struct Bounds<'tcx> {
2310+
/// A list of region bounds on the (implicit) self type. So if you
2311+
/// had `T: 'a + 'b` this might would be a list `['a, 'b]` (but
2312+
/// the `T` is not explicitly included).
22942313
pub region_bounds: Vec<(ty::Region<'tcx>, Span)>,
2314+
2315+
/// A list of trait bounds. So if you had `T: Debug` this would be
2316+
/// `T: Debug`. Note that the self-type is explicit here.
22952317
pub trait_bounds: Vec<(ty::PolyTraitRef<'tcx>, Span)>,
2318+
2319+
/// A list of projection equality bounds. So if you had `T:
2320+
/// Iterator<Item = u32>` this would include `<T as
2321+
/// Iterator>::Item => u32`. Note that the self-type is explicit
2322+
/// here.
22962323
pub projection_bounds: Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>,
2324+
2325+
/// `Some` if there is *no* `?Sized` predicate. The `span`
2326+
/// is the location in the source of the `T` declaration which can
2327+
/// be cited as the source of the `T: Sized` requirement.
22972328
pub implicitly_sized: Option<Span>,
22982329
}
22992330

23002331
impl<'a, 'gcx, 'tcx> Bounds<'tcx> {
2332+
/// Converts a bounds list into a flat set of predicates (like
2333+
/// where-clauses). Because some of our bounds listings (e.g.,
2334+
/// regions) don't include the self-type, you must supply the
2335+
/// self-type here (the `param_ty` parameter).
23012336
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, param_ty: Ty<'tcx>)
23022337
-> Vec<(ty::Predicate<'tcx>, Span)>
23032338
{

0 commit comments

Comments
 (0)