Skip to content

Commit ce01f4d

Browse files
committed
Auto merge of rust-lang#114617 - petrochenkov:docspacing, r=Mark-Simulacrum
proc_macro: Update docs for `Spacing` Brings the docs more in line with reality
2 parents c94cb83 + 176a939 commit ce01f4d

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

library/proc_macro/src/lib.rs

+25-13
Original file line numberDiff line numberDiff line change
@@ -916,21 +916,34 @@ impl !Send for Punct {}
916916
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
917917
impl !Sync for Punct {}
918918

919-
/// Describes whether a `Punct` is followed immediately by another `Punct` ([`Spacing::Joint`]) or
920-
/// by a different token or whitespace ([`Spacing::Alone`]).
919+
/// Indicates whether a `Punct` token can join with the following token
920+
/// to form a multi-character operator.
921921
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
922922
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
923923
pub enum Spacing {
924-
/// A `Punct` is not immediately followed by another `Punct`.
925-
/// E.g. `+` is `Alone` in `+ =`, `+ident` and `+()`.
926-
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
927-
Alone,
928-
/// A `Punct` is immediately followed by another `Punct`.
929-
/// E.g. `+` is `Joint` in `+=` and `++`.
924+
/// A `Punct` token can join with the following token to form a multi-character operator.
925+
///
926+
/// In token streams constructed using proc macro interfaces `Joint` punctuation tokens can be
927+
/// followed by any other tokens. \
928+
/// However, in token streams parsed from source code compiler will only set spacing to `Joint`
929+
/// in the following cases:
930+
/// - A `Punct` is immediately followed by another `Punct` without a whitespace. \
931+
/// E.g. `+` is `Joint` in `+=` and `++`.
932+
/// - A single quote `'` is immediately followed by an identifier without a whitespace. \
933+
/// E.g. `'` is `Joint` in `'lifetime`.
930934
///
931-
/// Additionally, single quote `'` can join with identifiers to form lifetimes: `'ident`.
935+
/// This list may be extended in the future to enable more token combinations.
932936
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
933937
Joint,
938+
/// A `Punct` token cannot join with the following token to form a multi-character operator.
939+
///
940+
/// `Alone` punctuation tokens can be followed by any other tokens. \
941+
/// In token streams parsed from source code compiler will set spacing to `Alone` in all cases
942+
/// not covered by the conditions for `Joint` above. \
943+
/// E.g. `+` is `Alone` in `+ =`, `+ident` and `+()`.
944+
/// In particular, token not followed by anything will also be marked as `Alone`.
945+
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
946+
Alone,
934947
}
935948

936949
impl Punct {
@@ -962,10 +975,9 @@ impl Punct {
962975
self.0.ch as char
963976
}
964977

965-
/// Returns the spacing of this punctuation character, indicating whether it's immediately
966-
/// followed by another `Punct` in the token stream, so they can potentially be combined into
967-
/// a multi-character operator (`Joint`), or it's followed by some other token or whitespace
968-
/// (`Alone`) so the operator has certainly ended.
978+
/// Returns the spacing of this punctuation character, indicating whether it can be potentially
979+
/// combined into a multi-character operator with the following token (`Joint`), or the operator
980+
/// has certainly ended (`Alone`).
969981
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
970982
pub fn spacing(&self) -> Spacing {
971983
if self.0.joint { Spacing::Joint } else { Spacing::Alone }

0 commit comments

Comments
 (0)