@@ -1372,49 +1372,49 @@ crate struct PolyTrait {
13721372 crate generic_params : Vec < GenericParamDef > ,
13731373}
13741374
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`].
13781376#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
13791377crate 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`
13861383 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.
13891385 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.
13921387 Primitive ( PrimitiveType ) ,
1393- /// `extern "ABI" fn`
1388+ /// A function pointer: `extern "ABI" fn(...) -> ... `
13941389 BareFunction ( Box < BareFunctionDecl > ) ,
1390+ /// A tuple type: `(i32, &str)`.
13951391 Tuple ( Vec < Type > ) ,
1392+ /// A slice type (does *not* include the `&`): `[i32]`
13961393 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.
13981397 Array ( Box < Type > , String ) ,
1398+ /// A raw pointer type: `*const i32`, `*mut i32`
13991399 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 > } ,
14051402
1406- // `<Type as Trait>::Name`
1403+ /// A qualified path to an associated item: `<Type as Trait>::Name`
14071404 QPath {
14081405 name : Symbol ,
14091406 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
14101410 self_def_id : Option < DefId > ,
14111411 trait_ : Path ,
14121412 } ,
14131413
1414- // `_`
1414+ /// A type that is inferred: `_`
14151415 Infer ,
14161416
1417- // `impl TraitA + TraitB + ...`
1417+ /// An `impl Trait`: `impl TraitA + TraitB + ...`
14181418 ImplTrait ( Vec < GenericBound > ) ,
14191419}
14201420
@@ -1538,8 +1538,12 @@ impl GetDefId for Type {
15381538 }
15391539}
15401540
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`].
15431547#[ derive( Clone , PartialEq , Eq , Hash , Copy , Debug ) ]
15441548crate enum PrimitiveType {
15451549 Isize ,
0 commit comments