rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.69k stars 1.5k forks source link

`pow` documentation is cut off #17206

Closed lubomirkurcak closed 3 weeks ago

lubomirkurcak commented 3 weeks ago

Location

/lib/rustlib/src/rust/library/core/src/num/uint_macros.rs

Summary

Documentation is cut off before examples are shown.

Neovim

image

VS Code

image

Source code of pow, the documentation stops rendering at the #[doc] directive:

/// Raises self to the power of `exp`, using exponentiation by squaring.
///
/// # Examples
///
/// Basic usage:
///
/// ```
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".pow(5), 32);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
#[must_use = "this returns the result of the operation, \
              without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn pow(self, mut exp: u32) -> Self {
    if exp == 0 {
        return 1;
    }
    let mut base = self;
    let mut acc = 1;

    while exp > 1 {
        if (exp & 1) == 1 {
            acc = acc * base;
        }
        exp /= 2;
        base = base * base;
    }

    // since exp!=0, finally the exp must be 1.
    // Deal with the final bit of the exponent separately, since
    // squaring the base afterwards is not necessary and may cause a
    // needless overflow.
    acc * base
}

There are many functions in this file that have the same problem.

P.S. Usually I would expect documentation to be like this:

/// Basic usage:
///
/// ```
/// assert_eq!(2.pow(5), 32);
/// ```
Urgau commented 3 weeks ago

Given that I can see the full documentation of pow on the website, I think this is an issue with rust-analyzer.

Which is in this Github repository: https://github.com/rust-lang/rust-analyzer.

fmease commented 3 weeks ago

@rustbot transfer rust-analyzer

roife commented 3 weeks ago

Might be related to #8092.

Veykril commented 3 weeks ago

Duplicate of #8092