diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-07-04 05:47:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-04 05:47:28 +0200 |
| commit | 01fe1c0b0eae46a168fa8f81cc9001bf2c37a8f7 (patch) | |
| tree | 5ce562f8402f2bf4168b2d3f37c610cfce885839 /src | |
| parent | 05f5690d81ef8ea55edac774b3646daa1e3e1575 (diff) | |
| parent | 510e5d7e665400822a6495adb23e06df99cc339c (diff) | |
| download | rust-01fe1c0b0eae46a168fa8f81cc9001bf2c37a8f7.tar.gz rust-01fe1c0b0eae46a168fa8f81cc9001bf2c37a8f7.zip | |
Rollup merge of #143381 - fee1-dead-contrib:push-pzxuvlnymxpu, r=GuillaumeGomez
rustdoc: don't treat methods under const impls or traits as const Fixes rust-lang/rust#143071
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/types.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index c9530216968..cc8f4bbb42c 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -647,7 +647,20 @@ impl Item { ) -> hir::FnHeader { let sig = tcx.fn_sig(def_id).skip_binder(); let constness = if tcx.is_const_fn(def_id) { - hir::Constness::Const + // rustc's `is_const_fn` returns `true` for associated functions that have an `impl const` parent + // or that have a `#[const_trait]` parent. Do not display those as `const` in rustdoc because we + // won't be printing correct syntax plus the syntax is unstable. + match tcx.opt_associated_item(def_id) { + Some(ty::AssocItem { + container: ty::AssocItemContainer::Impl, + trait_item_def_id: Some(_), + .. + }) + | Some(ty::AssocItem { container: ty::AssocItemContainer::Trait, .. }) => { + hir::Constness::NotConst + } + None | Some(_) => hir::Constness::Const, + } } else { hir::Constness::NotConst }; |
