Files
rust/tests/rustdoc-html/impl/impl-fundamental-nesting.rs
Rain c3864bee80 rustdoc: show impl Trait<Box<Local>> for Foreign, etc on Local's docs
This is a generalization of PR 92940: that PR handled cases like `impl Foreign for Box<Local>`, but was missing handling for a few other closely related cases.

My particular interest was with showing `impl From<Box<Utf8Path>> for Box<Path>` in camino's documentation. But I ended up handling a bunch of related cases along the way.

I'm new to rustdoc so please let me know if I got anything wrong :) took a bit to fully understand how this worked.
2026-06-27 03:27:43 -07:00

59 lines
1.8 KiB
Rust

// Followup to https://github.com/rust-lang/rust/issues/92940 and impl-box.rs.
//
// Show traits implemented on fundamental types that wrap local ones: nested edition.
#![crate_name = "foo"]
use std::pin::Pin;
pub struct Local;
//@ has 'foo/struct.Local.html'
// Nested fundamental + foreign Self.
//@ has '-' '//*[@id="impl-From%3CBox%3CLocal%3E%3E-for-String"]' 'impl From<Box<Local>> for String'
impl From<Box<Local>> for String {
fn from(_: Box<Local>) -> String {
String::new()
}
}
// Also test with Pin.
//@ has '-' '//*[@id="impl-From%3CPin%3CLocal%3E%3E-for-u8"]' 'impl From<Pin<Local>> for u8'
impl From<Pin<Local>> for u8 {
fn from(_: Pin<Local>) -> u8 {
0
}
}
// Reference to a fundamental wrapper.
//@ has '-' '//*[@id="impl-From%3C%26Box%3CLocal%3E%3E-for-u16"]' "impl<'a> From<&'a Box<Local>> for u16"
impl<'a> From<&'a Box<Local>> for u16 {
fn from(_: &'a Box<Local>) -> u16 {
0
}
}
// Nested two levels deep in Self.
//@ has '-' '//*[@id="impl-From%3Cu32%3E-for-Box%3CBox%3CLocal%3E%3E"]' 'impl From<u32> for Box<Box<Local>>'
impl From<u32> for Box<Box<Local>> {
fn from(_: u32) -> Box<Box<Local>> {
Box::new(Box::new(Local))
}
}
// Mixed fundamental wrappers in Self.
//@ has '-' '//*[@id="impl-From%3Cu64%3E-for-Pin%3CBox%3CLocal%3E%3E"]' 'impl From<u64> for Pin<Box<Local>>'
impl From<u64> for Pin<Box<Local>> {
fn from(_: u64) -> Pin<Box<Local>> {
Pin::new(Box::new(Local))
}
}
// A non-fundamental wrapper must not show up on Local's page, but it should still be listed on the
// trait's own page.
pub trait Marker {}
//@ has 'foo/trait.Marker.html' '//*[@id="impl-Marker-for-Vec%3CLocal%3E"]' 'impl Marker for Vec<Local>'
//@ !has 'foo/struct.Local.html' '//*[@id="impl-Marker-for-Vec%3CLocal%3E"]' 'impl Marker for Vec<Local>'
impl Marker for Vec<Local> {}