Description
Hello all! I couldn't find any tickets that discuss this problem, so hopefully this isn't a duplicate report.
I'm experimenting with the typestate pattern, where I'm using it in a builder to cascade a series of transformations. Here's a simple version:
pub trait State {}
pub struct Add;
impl State for Add {}
pub struct Mul;
impl State for Mul {}
pub struct Calculator<T: State = Add> { value: usize, _state: T }
impl Calculator {
pub fn new() -> Calculator<Add> {
Calculator { value: 0, _state: Add }
}
pub fn add_1(mut self) -> Self {
self.value += 1;
self
}
pub fn next(self) -> Calculator<Mul> {
Calculator { value: self.value, _state: Mul }
}
/// See [Calculator<Mul>::done].
pub fn done(self) -> usize {
self.next().done()
}
}
impl Calculator<Mul> {
pub fn multiply_2(mut self) -> Self {
self.value *= 2;
self
}
/// I'm done.
pub fn done(self) -> usize {
self.value
}
}
It seems though that rustdoc does not handle overloading the name particularly well. When running cargo doc
, the documentation for the Calculator<Add>::done()
just links to itself, rather than the doc on Calculator<Mul>::done()
. I'm guessing it's just stripping out the type parameter and linking to the first entry.
I expected to see this happen:
I hoped that we could link to the doc comment on the overloaded method
Instead, this happened:
rustdoc linked to the first method's comment.
Meta
rustc --version --verbose
:
rustc 1.58.0 (02072b482 2022-01-11)
binary: rustc
commit-hash: 02072b482a8b5357f7fb5e5637444ae30e423c40
commit-date: 2022-01-11
host: x86_64-apple-darwin
release: 1.58.0
LLVM version: 13.0.0