From c7cb8224e2020d30df6bceb8ea2e16e7a2594585 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 2 Jan 2025 11:58:15 -0700 Subject: [PATCH 1/2] rustdoc: treat `allowed_through_unstable_modules` as deprecation This ensures `std::intrinsics::transmute` is deemphasized in the search engine and other UI, by cleaning it into a deprecation without propagating it through reexports when the parent module is stable. --- src/librustdoc/clean/types.rs | 22 +++++++++++++++++++- src/librustdoc/passes/propagate_stability.rs | 9 ++++++++ tests/rustdoc-js-std/core-transmute.js | 11 ++++++++++ tests/rustdoc-js-std/transmute-fail.js | 3 ++- tests/rustdoc-js-std/transmute.js | 3 ++- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/rustdoc-js-std/core-transmute.js diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 3c4fad4bca97e..dcee96978d2b5 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -400,7 +400,27 @@ impl Item { } pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option { - self.def_id().and_then(|did| tcx.lookup_deprecation(did)) + self.def_id().and_then(|did| tcx.lookup_deprecation(did)).or_else(|| { + // `allowed_through_unstable_modules` is a bug-compatibility hack for old rustc + // versions; the paths that are exposed through it are "deprecated" because they + // were never supposed to work at all. + let stab = self.stability(tcx)?; + if let rustc_attr_parsing::StabilityLevel::Stable { + allowed_through_unstable_modules: true, + .. + } = stab.level + { + Some(Deprecation { + // FIXME(#131676, #135003): when a note is added to this stability tag, + // translate it here + since: rustc_attr_parsing::DeprecatedSince::Unspecified, + note: None, + suggestion: None, + }) + } else { + None + } + }) } pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool { diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs index 4c682c3d4ca05..9e06102bef6d4 100644 --- a/src/librustdoc/passes/propagate_stability.rs +++ b/src/librustdoc/passes/propagate_stability.rs @@ -107,6 +107,15 @@ fn merge_stability( || parent_stab.stable_since().is_some_and(|parent_since| parent_since > own_since)) { parent_stability + } else if let Some(mut own_stab) = own_stability + && let StabilityLevel::Stable { since, allowed_through_unstable_modules: true } = + own_stab.level + && let Some(parent_stab) = parent_stability + && parent_stab.is_stable() + { + // this property does not apply transitively through re-exports + own_stab.level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false }; + Some(own_stab) } else { own_stability } diff --git a/tests/rustdoc-js-std/core-transmute.js b/tests/rustdoc-js-std/core-transmute.js new file mode 100644 index 0000000000000..8c9910a32d7f1 --- /dev/null +++ b/tests/rustdoc-js-std/core-transmute.js @@ -0,0 +1,11 @@ +const FILTER_CRATE = "core"; +const EXPECTED = [ + { + 'query': 'generic:T -> generic:U', + 'others': [ + { 'path': 'core::intrinsics::simd', 'name': 'simd_as' }, + { 'path': 'core::intrinsics::simd', 'name': 'simd_cast' }, + { 'path': 'core::mem', 'name': 'transmute' }, + ], + }, +]; diff --git a/tests/rustdoc-js-std/transmute-fail.js b/tests/rustdoc-js-std/transmute-fail.js index c4dddf3cf3cee..ddfb276194818 100644 --- a/tests/rustdoc-js-std/transmute-fail.js +++ b/tests/rustdoc-js-std/transmute-fail.js @@ -1,4 +1,5 @@ // should-fail +const FILTER_CRATE = "std"; const EXPECTED = [ { // Keep this test case identical to `transmute`, except the @@ -7,7 +8,7 @@ const EXPECTED = [ 'others': [ { 'path': 'std::intrinsics::simd', 'name': 'simd_as' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_cast' }, - { 'path': 'std::intrinsics', 'name': 'transmute' }, + { 'path': 'std::mem', 'name': 'transmute' }, ], }, ]; diff --git a/tests/rustdoc-js-std/transmute.js b/tests/rustdoc-js-std/transmute.js index 0e52e21e0dead..f52e0ab14362d 100644 --- a/tests/rustdoc-js-std/transmute.js +++ b/tests/rustdoc-js-std/transmute.js @@ -1,3 +1,4 @@ +const FILTER_CRATE = "std"; const EXPECTED = [ { // Keep this test case identical to `transmute-fail`, except the @@ -6,7 +7,7 @@ const EXPECTED = [ 'others': [ { 'path': 'std::intrinsics::simd', 'name': 'simd_as' }, { 'path': 'std::intrinsics::simd', 'name': 'simd_cast' }, - { 'path': 'std::intrinsics', 'name': 'transmute' }, + { 'path': 'std::mem', 'name': 'transmute' }, ], }, ]; From 8af769d1b13faf4863b1ed06e800dd8faa2d75e4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 2 Jan 2025 14:08:43 -0700 Subject: [PATCH 2/2] Use `is_some_and` helper Co-authored-by: Guillaume Gomez --- src/librustdoc/passes/propagate_stability.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs index 9e06102bef6d4..d892c58583778 100644 --- a/src/librustdoc/passes/propagate_stability.rs +++ b/src/librustdoc/passes/propagate_stability.rs @@ -110,8 +110,7 @@ fn merge_stability( } else if let Some(mut own_stab) = own_stability && let StabilityLevel::Stable { since, allowed_through_unstable_modules: true } = own_stab.level - && let Some(parent_stab) = parent_stability - && parent_stab.is_stable() + && parent_stability.is_some_and(|stab| stab.is_stable()) { // this property does not apply transitively through re-exports own_stab.level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false };