Skip to content

Commit 9a240e4

Browse files
committed
Edit rustc_ast::tokenstream docs
Fix some punctuation and wording, and add intra-documentation links.
1 parent bcd6975 commit 9a240e4

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

compiler/rustc_ast/src/tokenstream.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
//! # Token Streams
22
//!
33
//! `TokenStream`s represent syntactic objects before they are converted into ASTs.
4-
//! A `TokenStream` is, roughly speaking, a sequence (eg stream) of `TokenTree`s,
5-
//! which are themselves a single `Token` or a `Delimited` subsequence of tokens.
4+
//! A `TokenStream` is, roughly speaking, a sequence of [`TokenTree`]s,
5+
//! which are themselves a single [`Token`] or a `Delimited` subsequence of tokens.
66
//!
77
//! ## Ownership
88
//!
99
//! `TokenStream`s are persistent data structures constructed as ropes with reference
1010
//! counted-children. In general, this means that calling an operation on a `TokenStream`
1111
//! (such as `slice`) produces an entirely new `TokenStream` from the borrowed reference to
12-
//! the original. This essentially coerces `TokenStream`s into 'views' of their subparts,
12+
//! the original. This essentially coerces `TokenStream`s into "views" of their subparts,
1313
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
1414
//! ownership of the original.
1515
@@ -24,9 +24,9 @@ use smallvec::{smallvec, SmallVec};
2424

2525
use std::{fmt, iter, mem};
2626

27-
/// When the main rust parser encounters a syntax-extension invocation, it
28-
/// parses the arguments to the invocation as a token-tree. This is a very
29-
/// loose structure, such that all sorts of different AST-fragments can
27+
/// When the main Rust parser encounters a syntax-extension invocation, it
28+
/// parses the arguments to the invocation as a token tree. This is a very
29+
/// loose structure, such that all sorts of different AST fragments can
3030
/// be passed to syntax extensions using a uniform type.
3131
///
3232
/// If the syntax extension is an MBE macro, it will attempt to match its
@@ -38,9 +38,9 @@ use std::{fmt, iter, mem};
3838
/// Nothing special happens to misnamed or misplaced `SubstNt`s.
3939
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
4040
pub enum TokenTree {
41-
/// A single token
41+
/// A single token.
4242
Token(Token),
43-
/// A delimited sequence of token trees
43+
/// A delimited sequence of token trees.
4444
Delimited(DelimSpan, DelimToken, TokenStream),
4545
}
4646

@@ -62,7 +62,7 @@ where
6262
}
6363

6464
impl TokenTree {
65-
/// Checks if this TokenTree is equal to the other, regardless of span information.
65+
/// Checks if this `TokenTree` is equal to the other, regardless of span information.
6666
pub fn eq_unspanned(&self, other: &TokenTree) -> bool {
6767
match (self, other) {
6868
(TokenTree::Token(token), TokenTree::Token(token2)) => token.kind == token2.kind,
@@ -73,7 +73,7 @@ impl TokenTree {
7373
}
7474
}
7575

76-
/// Retrieves the TokenTree's span.
76+
/// Retrieves the `TokenTree`'s span.
7777
pub fn span(&self) -> Span {
7878
match self {
7979
TokenTree::Token(token) => token.span,
@@ -140,7 +140,7 @@ impl CreateTokenStream for TokenStream {
140140
}
141141
}
142142

143-
/// A lazy version of `TokenStream`, which defers creation
143+
/// A lazy version of [`TokenStream`], which defers creation
144144
/// of an actual `TokenStream` until it is needed.
145145
/// `Box` is here only to reduce the structure size.
146146
#[derive(Clone)]
@@ -188,11 +188,12 @@ impl<CTX> HashStable<CTX> for LazyTokenStream {
188188
}
189189
}
190190

191-
/// A `TokenStream` is an abstract sequence of tokens, organized into `TokenTree`s.
191+
/// A `TokenStream` is an abstract sequence of tokens, organized into [`TokenTree`]s.
192192
///
193193
/// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s
194194
/// instead of a representation of the abstract syntax tree.
195-
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat.
195+
/// Today's `TokenTree`s can still contain AST via `token::Interpolated` for
196+
/// backwards compatability.
196197
#[derive(Clone, Debug, Default, Encodable, Decodable)]
197198
pub struct TokenStream(pub(crate) Lrc<Vec<TreeAndSpacing>>);
198199

@@ -429,7 +430,7 @@ impl TokenStreamBuilder {
429430
}
430431
}
431432

432-
/// By-reference iterator over a `TokenStream`.
433+
/// By-reference iterator over a [`TokenStream`].
433434
#[derive(Clone)]
434435
pub struct CursorRef<'t> {
435436
stream: &'t TokenStream,
@@ -457,8 +458,8 @@ impl<'t> Iterator for CursorRef<'t> {
457458
}
458459
}
459460

460-
/// Owning by-value iterator over a `TokenStream`.
461-
/// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
461+
/// Owning by-value iterator over a [`TokenStream`].
462+
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
462463
#[derive(Clone)]
463464
pub struct Cursor {
464465
pub stream: TokenStream,

0 commit comments

Comments
 (0)