rustdoc: be more strict about "Methods from Deref" · rust-lang/rust@b46412f (original) (raw)

`@@ -89,7 +89,7 @@ pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display {

`

89

89

``

90

90

`/// Specifies whether rendering directly implemented trait items or ones from a certain Deref

`

91

91

`/// impl.

`

92

``

`-

#[derive(Copy, Clone)]

`

``

92

`+

#[derive(Copy, Clone, Debug)]

`

93

93

`pub(crate) enum AssocItemRender<'a> {

`

94

94

`All,

`

95

95

`DerefFor { trait_: &'a clean::Path, type_: &'a clean::Type, deref_mut_: bool },

`

`@@ -1296,7 +1296,8 @@ fn render_assoc_items_inner(

`

1296

1296

`info!("Documenting associated items of {:?}", containing_item.name);

`

1297

1297

`let cache = &cx.shared.cache;

`

1298

1298

`let Some(v) = cache.impls.get(&it) else { return };

`

1299

``

`-

let (non_trait, traits): (Vec<_>, ) = v.iter().partition(|i| i.inner_impl().trait.is_none());

`

``

1299

`+

let (mut non_trait, traits): (Vec<_>, _) =

`

``

1300

`+

v.iter().partition(|i| i.inner_impl().trait_.is_none());

`

1300

1301

`if !non_trait.is_empty() {

`

1301

1302

`let mut close_tags = <Vec<&str>>::with_capacity(1);

`

1302

1303

`let mut tmp_buf = String::new();

`

`@@ -1314,6 +1315,16 @@ fn render_assoc_items_inner(

`

1314

1315

`AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {

`

1315

1316

`let id =

`

1316

1317

` cx.derive_id(small_url_encode(format!("deref-methods-{:#}", type_.print(cx))));

`

``

1318

`` +

// the impls.get above only looks at the outermost type,

``

``

1319

`+

// and the Deref impl may only be implemented for certain

`

``

1320

`+

// values of generic parameters.

`

``

1321

`` +

// for example, if an item impls Deref<[u8]>,

``

``

1322

`` +

// we should not show methods from [MaybeUninit<u8>].

``

``

1323

`` +

// this retain filters out any instances where

``

``

1324

`+

// the types do not line up perfectly.

`

``

1325

`+

non_trait.retain(|impl_| {

`

``

1326

`+

type_.is_doc_subtype_of(&impl_.inner_impl().for_, &cx.shared.cache)

`

``

1327

`+

});

`

1317

1328

`let derived_id = cx.derive_id(&id);

`

1318

1329

` close_tags.push("");

`

1319

1330

`write_str(

`

`@@ -1392,6 +1403,7 @@ fn render_assoc_items_inner(

`

1392

1403

`}

`

1393

1404

`}

`

1394

1405

``

``

1406

`` +

/// derefs is the set of all deref targets that have already been handled.

``

1395

1407

`fn render_deref_methods(

`

1396

1408

`mut w: impl Write,

`

1397

1409

`cx: &Context<'_>,

`