diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-08-09 17:34:54 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-09 17:34:54 +0530 |
| commit | d910e5376b69d232071b8eeed4d65e703e13a82b (patch) | |
| tree | 81ea31c690e0e14ab9d751b47b80431ad51ac0b6 /src | |
| parent | 7efe24c3ed070193ca64f402036166c8ab0c44b3 (diff) | |
| parent | b3b23aada9382e7768c0bd4d8f79319d73558259 (diff) | |
Rollup merge of #100221 - compiler-errors:impossible-trait-items, r=lcnr,notriddle,camelid
Don't document impossible to call default trait items on impls Closes #100176 This only skips documenting _default_ trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 9 | ||||
| -rw-r--r-- | src/test/rustdoc/impossible-default.rs | 20 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a262c8f7d19..ae7d8c108d3 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1550,6 +1550,15 @@ fn render_impl( rendering_params: ImplRenderingParameters, ) { for trait_item in &t.items { + // Skip over any default trait items that are impossible to call + // (e.g. if it has a `Self: Sized` bound on an unsized type). + if let Some(impl_def_id) = parent.item_id.as_def_id() + && let Some(trait_item_def_id) = trait_item.item_id.as_def_id() + && cx.tcx().is_impossible_method((impl_def_id, trait_item_def_id)) + { + continue; + } + let n = trait_item.name; if i.items.iter().any(|m| m.name == n) { continue; diff --git a/src/test/rustdoc/impossible-default.rs b/src/test/rustdoc/impossible-default.rs new file mode 100644 index 00000000000..24d6e3bdac1 --- /dev/null +++ b/src/test/rustdoc/impossible-default.rs @@ -0,0 +1,20 @@ +#![crate_name = "foo"] + +// Check that default trait items that are impossible to satisfy + +pub trait Foo { + fn needs_sized(&self) + where + Self: Sized, + {} + + fn no_needs_sized(&self) {} +} + +// @!has foo/struct.Bar.html '//*[@id="method.needs_sized"]//h4[@class="code-header"]' \ +// "fn needs_sized" +// @has foo/struct.Bar.html '//*[@id="method.no_needs_sized"]//h4[@class="code-header"]' \ +// "fn no_needs_sized" +pub struct Bar([u8]); + +impl Foo for Bar {} |
