Skip to content

Commit f0c03f6

Browse files
authored
Rollup merge of #135043 - notriddle:notriddle/allowed-through-unstable-modules-is-a-deprecation-flag, r=GuillaumeGomez
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. Fixes #131676 Related to #135003 r? ``@GuillaumeGomez`` ``@RalfJung`` ``@workingjubilee``
2 parents 564a29d + 8af769d commit f0c03f6

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

src/librustdoc/clean/types.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,27 @@ impl Item {
400400
}
401401

402402
pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
403-
self.def_id().and_then(|did| tcx.lookup_deprecation(did))
403+
self.def_id().and_then(|did| tcx.lookup_deprecation(did)).or_else(|| {
404+
// `allowed_through_unstable_modules` is a bug-compatibility hack for old rustc
405+
// versions; the paths that are exposed through it are "deprecated" because they
406+
// were never supposed to work at all.
407+
let stab = self.stability(tcx)?;
408+
if let rustc_attr_parsing::StabilityLevel::Stable {
409+
allowed_through_unstable_modules: true,
410+
..
411+
} = stab.level
412+
{
413+
Some(Deprecation {
414+
// FIXME(#131676, #135003): when a note is added to this stability tag,
415+
// translate it here
416+
since: rustc_attr_parsing::DeprecatedSince::Unspecified,
417+
note: None,
418+
suggestion: None,
419+
})
420+
} else {
421+
None
422+
}
423+
})
404424
}
405425

406426
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {

src/librustdoc/passes/propagate_stability.rs

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ fn merge_stability(
107107
|| parent_stab.stable_since().is_some_and(|parent_since| parent_since > own_since))
108108
{
109109
parent_stability
110+
} else if let Some(mut own_stab) = own_stability
111+
&& let StabilityLevel::Stable { since, allowed_through_unstable_modules: true } =
112+
own_stab.level
113+
&& parent_stability.is_some_and(|stab| stab.is_stable())
114+
{
115+
// this property does not apply transitively through re-exports
116+
own_stab.level = StabilityLevel::Stable { since, allowed_through_unstable_modules: false };
117+
Some(own_stab)
110118
} else {
111119
own_stability
112120
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const FILTER_CRATE = "core";
2+
const EXPECTED = [
3+
{
4+
'query': 'generic:T -> generic:U',
5+
'others': [
6+
{ 'path': 'core::intrinsics::simd', 'name': 'simd_as' },
7+
{ 'path': 'core::intrinsics::simd', 'name': 'simd_cast' },
8+
{ 'path': 'core::mem', 'name': 'transmute' },
9+
],
10+
},
11+
];
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// should-fail
2+
const FILTER_CRATE = "std";
23
const EXPECTED = [
34
{
45
// Keep this test case identical to `transmute`, except the
@@ -7,7 +8,7 @@ const EXPECTED = [
78
'others': [
89
{ 'path': 'std::intrinsics::simd', 'name': 'simd_as' },
910
{ 'path': 'std::intrinsics::simd', 'name': 'simd_cast' },
10-
{ 'path': 'std::intrinsics', 'name': 'transmute' },
11+
{ 'path': 'std::mem', 'name': 'transmute' },
1112
],
1213
},
1314
];

tests/rustdoc-js-std/transmute.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const FILTER_CRATE = "std";
12
const EXPECTED = [
23
{
34
// Keep this test case identical to `transmute-fail`, except the
@@ -6,7 +7,7 @@ const EXPECTED = [
67
'others': [
78
{ 'path': 'std::intrinsics::simd', 'name': 'simd_as' },
89
{ 'path': 'std::intrinsics::simd', 'name': 'simd_cast' },
9-
{ 'path': 'std::intrinsics', 'name': 'transmute' },
10+
{ 'path': 'std::mem', 'name': 'transmute' },
1011
],
1112
},
1213
];

0 commit comments

Comments
 (0)