Skip to content

Commit edf65c4

Browse files
committed
ast: Document Item and ForeignItem
1 parent 084f3bc commit edf65c4

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/libsyntax/ast.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,9 @@ impl fmt::Display for Unsafety {
14761476

14771477
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
14781478
pub enum ImplPolarity {
1479-
/// impl Trait for Type
1479+
/// `impl Trait for Type`
14801480
Positive,
1481-
/// impl !Trait for Type
1481+
/// `impl !Trait for Type`
14821482
Negative,
14831483
}
14841484

@@ -1494,10 +1494,10 @@ impl fmt::Debug for ImplPolarity {
14941494

14951495
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14961496
pub enum FunctionRetTy {
1497-
/// Functions with return type ! that always
1497+
/// Functions with return type `!`that always
14981498
/// raise an error or exit (i.e. never return to the caller)
14991499
NoReturn(Span),
1500-
/// Return type is not specified. Functions default to () and
1500+
/// Return type is not specified. Functions default to `()` and
15011501
/// closures default to inference. Span points to where return
15021502
/// type would be inserted.
15031503
DefaultReturn(Span),
@@ -1553,7 +1553,9 @@ pub struct VariantArg {
15531553

15541554
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
15551555
pub enum VariantKind {
1556+
/// Tuple variant, e.g. `Foo(A, B)`
15561557
TupleVariantKind(Vec<VariantArg>),
1558+
/// Struct variant, e.g. `Foo {x: A, y: B}`
15571559
StructVariantKind(P<StructDef>),
15581560
}
15591561

@@ -1568,6 +1570,7 @@ pub struct Variant_ {
15681570
pub attrs: Vec<Attribute>,
15691571
pub kind: VariantKind,
15701572
pub id: NodeId,
1573+
/// Explicit discriminant, eg `Foo = 1`
15711574
pub disr_expr: Option<P<Expr>>,
15721575
pub vis: Visibility,
15731576
}
@@ -1718,6 +1721,9 @@ pub struct StructDef {
17181721
FIXME (#3300): Should allow items to be anonymous. Right now
17191722
we just use dummy names for anon items.
17201723
*/
1724+
/// An item
1725+
///
1726+
/// The name might be a dummy name in case of anonymous items
17211727
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17221728
pub struct Item {
17231729
pub ident: Ident,
@@ -1730,19 +1736,27 @@ pub struct Item {
17301736

17311737
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17321738
pub enum Item_ {
1733-
// Optional location (containing arbitrary characters) from which
1734-
// to fetch the crate sources.
1735-
// For example, extern crate whatever = "github.com/rust-lang/rust".
1739+
/// An`extern crate` item, with optional original crate name,
1740+
/// e.g. `extern crate foo` or `extern crate "foo-bar" as foo`
17361741
ItemExternCrate(Option<(InternedString, StrStyle)>),
1742+
/// A `use` or `pub use` item
17371743
ItemUse(P<ViewPath>),
17381744

1745+
/// A `static` item
17391746
ItemStatic(P<Ty>, Mutability, P<Expr>),
1747+
/// A `const` item
17401748
ItemConst(P<Ty>, P<Expr>),
1749+
/// A function declaration
17411750
ItemFn(P<FnDecl>, Unsafety, Abi, Generics, P<Block>),
1751+
/// A module
17421752
ItemMod(Mod),
1753+
/// An external module
17431754
ItemForeignMod(ForeignMod),
1755+
/// A type alias, e.g. `type Foo = Bar<u8>`
17441756
ItemTy(P<Ty>, Generics),
1757+
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
17451758
ItemEnum(EnumDef, Generics),
1759+
/// A struct definition, e.g. `struct Foo<A> {x: A}`
17461760
ItemStruct(P<StructDef>, Generics),
17471761
/// Represents a Trait Declaration
17481762
ItemTrait(Unsafety,
@@ -1751,8 +1765,9 @@ pub enum Item_ {
17511765
Vec<P<TraitItem>>),
17521766

17531767
// Default trait implementations
1754-
// `impl Trait for ..`
1768+
// `impl Trait for .. {}`
17551769
ItemDefaultImpl(Unsafety, TraitRef),
1770+
/// An implementation, eg `impl<A> Trait for Foo { .. }`
17561771
ItemImpl(Unsafety,
17571772
ImplPolarity,
17581773
Generics,
@@ -1794,10 +1809,13 @@ pub struct ForeignItem {
17941809
pub vis: Visibility,
17951810
}
17961811

1812+
/// An item within an `extern` block
17971813
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17981814
pub enum ForeignItem_ {
1815+
/// A foreign function
17991816
ForeignItemFn(P<FnDecl>, Generics),
1800-
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
1817+
/// A foreign static item (`static ext: u8`), with optional mutability
1818+
ForeignItemStatic(P<Ty>, bool),
18011819
}
18021820

18031821
impl ForeignItem_ {

0 commit comments

Comments
 (0)