diff options
| author | bors <bors@rust-lang.org> | 2025-03-24 01:03:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-24 01:03:21 +0000 |
| commit | ae8ab87de4d8caab5d91a027bc19bb5d5e8a3691 (patch) | |
| tree | a96cd1131d237664ee96e872d0fe2aeab2abc5c0 /src/librustdoc/html/render/mod.rs | |
| parent | 7290b04b0a46de2118968aa556bfc0970aac6661 (diff) | |
| parent | 0e95f962d9718a7680ad8c10aa747a120da9ed5b (diff) | |
Auto merge of #138873 - jhpratt:rollup-tggrbxl, r=jhpratt
Rollup of 10 pull requests Successful merges: - #137593 (fix download-llvm logic for subtree sync branches) - #137736 (Don't attempt to export compiler-builtins symbols from rust dylibs) - #138135 (Simplify `PartialOrd` on tuples containing primitives) - #138321 ([bootstrap] Distribute split debuginfo if present) - #138574 (rustdoc: be more strict about "Methods from Deref") - #138606 (Fix missing rustfmt in msi installer - cont) - #138671 (Fix `FileType` `PartialEq` implementation on Windows) - #138728 (Update `compiler-builtins` to 0.1.152) - #138783 (Cache current_dll_path output) - #138846 (Tweaks to writeback and `Obligation -> Goal` conversion) Failed merges: - #138755 ([rustdoc] Remove duplicated loop when computing doc cfgs) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/librustdoc/html/render/mod.rs')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 8dfde1679fe..2237e0f987b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -89,7 +89,7 @@ pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display { /// Specifies whether rendering directly implemented trait items or ones from a certain Deref /// impl. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub(crate) enum AssocItemRender<'a> { All, DerefFor { trait_: &'a clean::Path, type_: &'a clean::Type, deref_mut_: bool }, @@ -1296,7 +1296,8 @@ fn render_assoc_items_inner( info!("Documenting associated items of {:?}", containing_item.name); let cache = &cx.shared.cache; let Some(v) = cache.impls.get(&it) else { return }; - let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none()); + let (mut non_trait, traits): (Vec<_>, _) = + v.iter().partition(|i| i.inner_impl().trait_.is_none()); if !non_trait.is_empty() { let mut close_tags = <Vec<&str>>::with_capacity(1); let mut tmp_buf = String::new(); @@ -1314,6 +1315,16 @@ fn render_assoc_items_inner( AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => { let id = cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx)))); + // the `impls.get` above only looks at the outermost type, + // and the Deref impl may only be implemented for certain + // values of generic parameters. + // for example, if an item impls `Deref<[u8]>`, + // we should not show methods from `[MaybeUninit<u8>]`. + // this `retain` filters out any instances where + // the types do not line up perfectly. + non_trait.retain(|impl_| { + type_.is_doc_subtype_of(&impl_.inner_impl().for_, &cx.shared.cache) + }); let derived_id = cx.derive_id(&id); close_tags.push("</details>"); write_str( @@ -1392,6 +1403,7 @@ fn render_assoc_items_inner( } } +/// `derefs` is the set of all deref targets that have already been handled. fn render_deref_methods( mut w: impl Write, cx: &Context<'_>, |
