Auto merge of #114617 - petrochenkov:docspacing, r=Mark-Simulacrum · rust-lang/rust@ce01f4d (original) (raw)

`@@ -916,21 +916,34 @@ impl !Send for Punct {}

`

916

916

`#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

`

917

917

`impl !Sync for Punct {}

`

918

918

``

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.

`

921

921

`#[derive(Copy, Clone, Debug, PartialEq, Eq)]

`

922

922

`#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

`

923

923

`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.

``

930

934

`///

`

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.

`

932

936

`#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

`

933

937

`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,

`

934

947

`}

`

935

948

``

936

949

`impl Punct {

`

`@@ -962,10 +975,9 @@ impl Punct {

`

962

975

`self.0.ch as char

`

963

976

`}

`

964

977

``

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).

``

969

981

`#[stable(feature = "proc_macro_lib2", since = "1.29.0")]

`

970

982

`pub fn spacing(&self) -> Spacing {

`

971

983

`if self.0.joint { Spacing::Joint } else { Spacing::Alone }

`