Skip to content

doc of macro generated functions is incomplete and constants appear in some internal representation #17090

Closed as duplicate of#8092
@antonilol

Description

@antonilol

rust-analyzer version: rust-analyzer version: 0.4.1830-standalone

rustc version: rustc 1.77.0 (aedd173a2 2024-03-17)

editor or extension: Code OSS (on arch linux, installed with pacman, code 1.87.2-1)

relevant settings: None

code snippet to reproduce:

// start typing this to get the completions
usize::from_be

for me, this looks like this:

image

but the doc should look like this: https://doc.rust-lang.org/std/primitive.usize.html#method.from_be_bytes

the function is defined like this:

        ...

        /// Create a native endian integer value from its representation
        /// as a byte array in big endian.
        ///
        #[doc = $from_xe_bytes_doc]
        ///
        /// # Examples
        ///
        /// ```
        #[doc = concat!("let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");")]
        #[doc = concat!("assert_eq!(value, ", $swap_op, ");")]
        /// ```
        ///
        /// When starting from a slice rather than an array, fallible conversion APIs can be used:
        ///
        /// ```
        #[doc = concat!("fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")]
        #[doc = concat!("    let (int_bytes, rest) = input.split_at(std::mem::size_of::<", stringify!($SelfT), ">());")]
        ///     *input = rest;
        #[doc = concat!("    ", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())")]
        /// }
        /// ```
        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
        #[must_use]
        #[inline]
        pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
            Self::from_be(Self::from_ne_bytes(bytes))
        }

        ...

all parts that are not rendered by rust-analyzer are the parts that are different per int type, and put in there with #[doc = ...] and concat!(), the constant that is not evaluated is in [u8; mem::size_of::<Self>()] ([u8; 8] on 64 bit platforms)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions