@@ -1372,49 +1372,49 @@ crate struct PolyTrait {
1372
1372
crate generic_params : Vec < GenericParamDef > ,
1373
1373
}
1374
1374
1375
- /// A representation of a type suitable for hyperlinking purposes. Ideally, one can get the original
1376
- /// type out of the AST/`TyCtxt` given one of these, if more information is needed. Most
1377
- /// importantly, it does not preserve mutability or boxes.
1375
+ /// Rustdoc's representation of types, mostly based on the [`hir::Ty`].
1378
1376
#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
1379
1377
crate enum Type {
1380
- /// Structs/enums/traits (most that would be an `hir::TyKind::Path`).
1381
- ResolvedPath {
1382
- path : Path ,
1383
- did : DefId ,
1384
- } ,
1385
- /// `dyn for<'a> Trait<'a> + Send + 'static`
1378
+ /// A named type, which could be a trait.
1379
+ ///
1380
+ /// This is mostly Rustdoc's version of [`hir::Path`].
1381
+ ResolvedPath { path : Path , did : DefId } ,
1382
+ /// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
1386
1383
DynTrait ( Vec < PolyTrait > , Option < Lifetime > ) ,
1387
- /// For parameterized types, so the consumer of the JSON don't go
1388
- /// looking for types which don't exist anywhere.
1384
+ /// A type parameter.
1389
1385
Generic ( Symbol ) ,
1390
- /// Primitives are the fixed-size numeric types (plus int/usize/float), char,
1391
- /// arrays, slices, and tuples.
1386
+ /// A primitive (aka, builtin) type.
1392
1387
Primitive ( PrimitiveType ) ,
1393
- /// `extern "ABI" fn`
1388
+ /// A function pointer: `extern "ABI" fn(...) -> ... `
1394
1389
BareFunction ( Box < BareFunctionDecl > ) ,
1390
+ /// A tuple type: `(i32, &str)`.
1395
1391
Tuple ( Vec < Type > ) ,
1392
+ /// A slice type (does *not* include the `&`): `[i32]`
1396
1393
Slice ( Box < Type > ) ,
1397
- /// The `String` field is about the size or the constant representing the array's length.
1394
+ /// An array type.
1395
+ ///
1396
+ /// The `String` field is a stringified version of the array's length parameter.
1398
1397
Array ( Box < Type > , String ) ,
1398
+ /// A raw pointer type: `*const i32`, `*mut i32`
1399
1399
RawPointer ( Mutability , Box < Type > ) ,
1400
- BorrowedRef {
1401
- lifetime : Option < Lifetime > ,
1402
- mutability : Mutability ,
1403
- type_ : Box < Type > ,
1404
- } ,
1400
+ /// A reference type: `&i32`, `&'a mut Foo`
1401
+ BorrowedRef { lifetime : Option < Lifetime > , mutability : Mutability , type_ : Box < Type > } ,
1405
1402
1406
- // `<Type as Trait>::Name`
1403
+ /// A qualified path to an associated item: `<Type as Trait>::Name`
1407
1404
QPath {
1408
1405
name : Symbol ,
1409
1406
self_type : Box < Type > ,
1407
+ /// FIXME: This is a hack that should be removed; see [this discussion][1].
1408
+ ///
1409
+ /// [1]: https://github.com/rust-lang/rust/pull/85479#discussion_r635729093
1410
1410
self_def_id : Option < DefId > ,
1411
1411
trait_ : Path ,
1412
1412
} ,
1413
1413
1414
- // `_`
1414
+ /// A type that is inferred: `_`
1415
1415
Infer ,
1416
1416
1417
- // `impl TraitA + TraitB + ...`
1417
+ /// An `impl Trait`: `impl TraitA + TraitB + ...`
1418
1418
ImplTrait ( Vec < GenericBound > ) ,
1419
1419
}
1420
1420
@@ -1538,8 +1538,12 @@ impl GetDefId for Type {
1538
1538
}
1539
1539
}
1540
1540
1541
- /// N.B. this has to be different from `hir::PrimTy` because it also includes types that aren't
1542
- /// paths, like `Unit`.
1541
+ /// A primitive (aka, builtin) type.
1542
+ ///
1543
+ /// This represents things like `i32`, `str`, etc.
1544
+ ///
1545
+ /// N.B. This has to be different from [`hir::PrimTy`] because it also includes types that aren't
1546
+ /// paths, like [`Self::Unit`].
1543
1547
#[ derive( Clone , PartialEq , Eq , Hash , Copy , Debug ) ]
1544
1548
crate enum PrimitiveType {
1545
1549
Isize ,
0 commit comments