about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-11-02 14:12:12 +0000
committerbors <bors@rust-lang.org>2024-11-02 14:12:12 +0000
commit07cbbdd69363da97075650e9be24b78af0bcdd23 (patch)
tree42948eb7578316c7ee491b6f1cfc47326bce5e95
parent588a4203508ed7c76750c96b482641261630ed36 (diff)
parentc4024585a418a732d9ae13017373b4f8b84b3ab2 (diff)
downloadrust-07cbbdd69363da97075650e9be24b78af0bcdd23.tar.gz
rust-07cbbdd69363da97075650e9be24b78af0bcdd23.zip
Auto merge of #132513 - matthiaskrgr:rollup-y98jvsl, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #132481 (rustdoc: skip stability inheritance for some item kinds)
 - #132482 (library: fix some stability annotations)
 - #132493 (Fix type reference in documents which was being confused with html tags.)
 - #132494 (make `download-rustc="if-unchanged"` default for library profile)
 - #132495 (Remove unintended link)

r? `@ghost`
`@rustbot` modify labels: rollup
-rw-r--r--library/core/src/array/mod.rs5
-rw-r--r--library/core/src/char/mod.rs2
-rw-r--r--library/std/src/lib.rs2
-rw-r--r--library/std/src/sys/pal/windows/mod.rs2
-rw-r--r--library/std/src/sys/thread_local/guard/windows.rs2
-rw-r--r--src/bootstrap/defaults/config.library.toml3
-rw-r--r--src/bootstrap/defaults/config.tools.toml2
-rw-r--r--src/bootstrap/src/utils/change_tracker.rs5
-rw-r--r--src/librustdoc/passes/propagate_stability.rs74
-rw-r--r--tests/rustdoc/stability.rs114
10 files changed, 173 insertions, 38 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index 9b28b8b613e..4764d7f0b0f 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -2,7 +2,7 @@
 //!
 //! *[See also the array primitive type](array).*
 
-#![stable(feature = "core_array", since = "1.36.0")]
+#![stable(feature = "core_array", since = "1.35.0")]
 
 use crate::borrow::{Borrow, BorrowMut};
 use crate::cmp::Ordering;
@@ -154,10 +154,11 @@ pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1] {
 
 /// The error type returned when a conversion from a slice to an array fails.
 #[stable(feature = "try_from", since = "1.34.0")]
+#[rustc_allowed_through_unstable_modules]
 #[derive(Debug, Copy, Clone)]
 pub struct TryFromSliceError(());
 
-#[stable(feature = "core_array", since = "1.36.0")]
+#[stable(feature = "core_array", since = "1.35.0")]
 impl fmt::Display for TryFromSliceError {
     #[inline]
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs
index fa3c2075423..59fd7250e8f 100644
--- a/library/core/src/char/mod.rs
+++ b/library/core/src/char/mod.rs
@@ -18,7 +18,7 @@
 //! functions that convert various types to `char`.
 
 #![allow(non_snake_case)]
-#![stable(feature = "core_char", since = "1.2.0")]
+#![stable(feature = "rust1", since = "1.0.0")]
 
 mod convert;
 mod decode;
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 1de52eb7b21..d0dd991a933 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -481,7 +481,7 @@ pub mod prelude;
 
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use core::any;
-#[stable(feature = "core_array", since = "1.36.0")]
+#[stable(feature = "core_array", since = "1.35.0")]
 pub use core::array;
 #[unstable(feature = "async_iterator", issue = "79024")]
 pub use core::async_iter;
diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs
index a9886012e8e..aca69490d7a 100644
--- a/library/std/src/sys/pal/windows/mod.rs
+++ b/library/std/src/sys/pal/windows/mod.rs
@@ -38,7 +38,7 @@ cfg_if::cfg_if! {
     }
 }
 
-/// Map a Result<T, WinError> to io::Result<T>.
+/// Map a [`Result<T, WinError>`] to [`io::Result<T>`](crate::io::Result<T>).
 trait IoResult<T> {
     fn io_result(self) -> crate::io::Result<T>;
 }
diff --git a/library/std/src/sys/thread_local/guard/windows.rs b/library/std/src/sys/thread_local/guard/windows.rs
index 7ee8e695c75..1752b0e1208 100644
--- a/library/std/src/sys/thread_local/guard/windows.rs
+++ b/library/std/src/sys/thread_local/guard/windows.rs
@@ -26,7 +26,7 @@
 //! This apparently translates to any callbacks in the ".CRT$XLB" section
 //! being run on certain events.
 //!
-//! So after all that, we use the compiler's #[link_section] feature to place
+//! So after all that, we use the compiler's `#[link_section]` feature to place
 //! a callback pointer into the magic section so it ends up being called.
 //!
 //! # What's up with this callback?
diff --git a/src/bootstrap/defaults/config.library.toml b/src/bootstrap/defaults/config.library.toml
index 5447565a4b0..3d697be8156 100644
--- a/src/bootstrap/defaults/config.library.toml
+++ b/src/bootstrap/defaults/config.library.toml
@@ -8,6 +8,9 @@ bench-stage = 0
 [rust]
 # This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
 incremental = true
+# Download rustc from CI instead of building it from source.
+# For stage > 1 builds, this cuts compile times significantly when there are no changes on "compiler" tree.
+download-rustc = "if-unchanged"
 # Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown.
 lto = "off"
 
diff --git a/src/bootstrap/defaults/config.tools.toml b/src/bootstrap/defaults/config.tools.toml
index efb56996bcd..27c1d1cf26d 100644
--- a/src/bootstrap/defaults/config.tools.toml
+++ b/src/bootstrap/defaults/config.tools.toml
@@ -4,7 +4,7 @@
 # This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
 incremental = true
 # Download rustc from CI instead of building it from source.
-# This cuts compile times by almost 60x, but means you can't modify the compiler.
+# For stage > 1 builds, this cuts compile times significantly when there are no changes on "compiler" tree.
 # Using these defaults will download the stage2 compiler (see `download-rustc`
 # setting) and the stage2 toolchain should therefore be used for these defaults.
 download-rustc = "if-unchanged"
diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs
index b9cf8f05316..0915ec15a2f 100644
--- a/src/bootstrap/src/utils/change_tracker.rs
+++ b/src/bootstrap/src/utils/change_tracker.rs
@@ -290,4 +290,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
         severity: ChangeSeverity::Info,
         summary: "New option `llvm.offload` to control whether the llvm offload runtime for GPU support is built. Implicitly enables the openmp runtime as dependency.",
     },
+    ChangeInfo {
+        change_id: 132494,
+        severity: ChangeSeverity::Info,
+        summary: "`download-rustc='if-unchanged'` is now a default option for library profile.",
+    },
 ];
diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs
index f55479687f8..a28487cc79e 100644
--- a/src/librustdoc/passes/propagate_stability.rs
+++ b/src/librustdoc/passes/propagate_stability.rs
@@ -9,7 +9,7 @@
 use rustc_attr::{Stability, StabilityLevel};
 use rustc_hir::def_id::CRATE_DEF_ID;
 
-use crate::clean::{Crate, Item, ItemId};
+use crate::clean::{Crate, Item, ItemId, ItemKind};
 use crate::core::DocContext;
 use crate::fold::DocFolder;
 use crate::passes::Pass;
@@ -38,22 +38,45 @@ impl<'a, 'tcx> DocFolder for StabilityPropagator<'a, 'tcx> {
             ItemId::DefId(def_id) => {
                 let own_stability = self.cx.tcx.lookup_stability(def_id);
 
-                // If any of the item's parents was stabilized later or is still unstable,
-                // then use the parent's stability instead.
-                if let Some(own_stab) = own_stability
-                    && let StabilityLevel::Stable {
-                        since: own_since,
-                        allowed_through_unstable_modules: false,
-                    } = own_stab.level
-                    && let Some(parent_stab) = parent_stability
-                    && (parent_stab.is_unstable()
-                        || parent_stab
-                            .stable_since()
-                            .is_some_and(|parent_since| parent_since > own_since))
-                {
-                    parent_stability
-                } else {
-                    own_stability
+                let (ItemKind::StrippedItem(box kind) | kind) = &item.kind;
+                match kind {
+                    ItemKind::ExternCrateItem { .. }
+                    | ItemKind::ImportItem(..)
+                    | ItemKind::StructItem(..)
+                    | ItemKind::UnionItem(..)
+                    | ItemKind::EnumItem(..)
+                    | ItemKind::FunctionItem(..)
+                    | ItemKind::ModuleItem(..)
+                    | ItemKind::TypeAliasItem(..)
+                    | ItemKind::StaticItem(..)
+                    | ItemKind::TraitItem(..)
+                    | ItemKind::TraitAliasItem(..)
+                    | ItemKind::StructFieldItem(..)
+                    | ItemKind::VariantItem(..)
+                    | ItemKind::ForeignFunctionItem(..)
+                    | ItemKind::ForeignStaticItem(..)
+                    | ItemKind::ForeignTypeItem
+                    | ItemKind::MacroItem(..)
+                    | ItemKind::ProcMacroItem(..)
+                    | ItemKind::ConstantItem(..) => {
+                        // If any of the item's parents was stabilized later or is still unstable,
+                        // then use the parent's stability instead.
+                        merge_stability(own_stability, parent_stability)
+                    }
+
+                    // Don't inherit the parent's stability for these items, because they
+                    // are potentially accessible even if the parent is more unstable.
+                    ItemKind::ImplItem(..)
+                    | ItemKind::TyMethodItem(..)
+                    | ItemKind::MethodItem(..)
+                    | ItemKind::TyAssocConstItem(..)
+                    | ItemKind::AssocConstItem(..)
+                    | ItemKind::TyAssocTypeItem(..)
+                    | ItemKind::AssocTypeItem(..)
+                    | ItemKind::PrimitiveItem(..)
+                    | ItemKind::KeywordItem => own_stability,
+
+                    ItemKind::StrippedItem(..) => unreachable!(),
                 }
             }
             ItemId::Auto { .. } | ItemId::Blanket { .. } => {
@@ -70,3 +93,20 @@ impl<'a, 'tcx> DocFolder for StabilityPropagator<'a, 'tcx> {
         Some(item)
     }
 }
+
+fn merge_stability(
+    own_stability: Option<Stability>,
+    parent_stability: Option<Stability>,
+) -> Option<Stability> {
+    if let Some(own_stab) = own_stability
+        && let StabilityLevel::Stable { since: own_since, allowed_through_unstable_modules: false } =
+            own_stab.level
+        && let Some(parent_stab) = parent_stability
+        && (parent_stab.is_unstable()
+            || parent_stab.stable_since().is_some_and(|parent_since| parent_since > own_since))
+    {
+        parent_stability
+    } else {
+        own_stability
+    }
+}
diff --git a/tests/rustdoc/stability.rs b/tests/rustdoc/stability.rs
index fc72154cad8..550eb0bc137 100644
--- a/tests/rustdoc/stability.rs
+++ b/tests/rustdoc/stability.rs
@@ -1,6 +1,8 @@
 #![feature(staged_api)]
+#![feature(rustc_attrs)]
+#![feature(rustdoc_internals)]
 
-#![stable(feature = "rust1", since = "1.0.0")]
+#![stable(feature = "core", since = "1.6.0")]
 
 //@ has stability/index.html
 //@ has - '//ul[@class="item-table"]/li[1]//a' AaStable
@@ -26,7 +28,7 @@ pub struct ZzStable;
 #[unstable(feature = "unstable", issue = "none")]
 pub mod unstable {
     //@ !hasraw stability/unstable/struct.StableInUnstable.html \
-    //      '//span[@class="since"]'
+    //      '//div[@class="main-heading"]//span[@class="since"]'
     //@ has - '//div[@class="stab unstable"]' 'experimental'
     #[stable(feature = "rust1", since = "1.0.0")]
     pub struct StableInUnstable;
@@ -34,52 +36,136 @@ pub mod unstable {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub mod stable_in_unstable {
         //@ !hasraw stability/unstable/stable_in_unstable/struct.Inner.html \
-        //      '//span[@class="since"]'
+        //      '//div[@class="main-heading"]//span[@class="since"]'
         //@ has - '//div[@class="stab unstable"]' 'experimental'
         #[stable(feature = "rust1", since = "1.0.0")]
         pub struct Inner;
     }
+
+    //@ has stability/struct.AaStable.html \
+    //      '//*[@id="method.foo"]//span[@class="since"]' '2.2.2'
+    impl super::AaStable {
+        #[stable(feature = "rust2", since = "2.2.2")]
+        pub fn foo() {}
+    }
+
+    //@ has stability/unstable/struct.StableInUnstable.html \
+    //      '//*[@id="method.foo"]//span[@class="since"]' '1.0.0'
+    impl StableInUnstable {
+        #[stable(feature = "rust1", since = "1.0.0")]
+        pub fn foo() {}
+    }
+}
+
+#[unstable(feature = "unstable", issue = "none")]
+#[doc(hidden)]
+pub mod unstable_stripped {
+    //@ has stability/struct.AaStable.html \
+    //      '//*[@id="method.foo"]//span[@class="since"]' '2.2.2'
+    impl super::AaStable {
+        #[stable(feature = "rust2", since = "2.2.2")]
+        pub fn foo() {}
+    }
 }
 
 #[stable(feature = "rust2", since = "2.2.2")]
 pub mod stable_later {
     //@ has stability/stable_later/struct.StableInLater.html \
-    //      '//span[@class="since"]' '2.2.2'
+    //      '//div[@class="main-heading"]//span[@class="since"]' '2.2.2'
     #[stable(feature = "rust1", since = "1.0.0")]
     pub struct StableInLater;
 
     #[stable(feature = "rust1", since = "1.0.0")]
     pub mod stable_in_later {
         //@ has stability/stable_later/stable_in_later/struct.Inner.html \
-        //      '//span[@class="since"]' '2.2.2'
+        //      '//div[@class="main-heading"]//span[@class="since"]' '2.2.2'
         #[stable(feature = "rust1", since = "1.0.0")]
         pub struct Inner;
     }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-pub mod stable_earlier {
-    //@ has stability/stable_earlier/struct.StableInUnstable.html \
-    //      '//span[@class="since"]' '1.0.0'
+#[rustc_allowed_through_unstable_modules]
+pub mod stable_earlier1 {
+    //@ has stability/stable_earlier1/struct.StableInUnstable.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+    //@ has - '//*[@id="method.foo"]//span[@class="since"]' '1.0.0'
+    #[doc(inline)]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub use crate::unstable::StableInUnstable;
+
+    //@ has stability/stable_earlier1/stable_in_unstable/struct.Inner.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+    #[doc(inline)]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub use crate::unstable::stable_in_unstable;
+
+    //@ has stability/stable_earlier1/struct.StableInLater.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+    #[doc(inline)]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub use crate::stable_later::StableInLater;
+
+    //@ has stability/stable_earlier1/stable_in_later/struct.Inner.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+    #[doc(inline)]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub use crate::stable_later::stable_in_later;
+}
+
+/// These will inherit the crate stability.
+#[stable(feature = "rust1", since = "1.0.0")]
+pub mod stable_earlier2 {
+    //@ has stability/stable_earlier2/struct.StableInUnstable.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.6.0'
+    //@ has - '//*[@id="method.foo"]//span[@class="since"]' '1.0.0'
     #[doc(inline)]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use crate::unstable::StableInUnstable;
 
-    //@ has stability/stable_earlier/stable_in_unstable/struct.Inner.html \
-    //      '//span[@class="since"]' '1.0.0'
+    //@ has stability/stable_earlier2/stable_in_unstable/struct.Inner.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.6.0'
     #[doc(inline)]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use crate::unstable::stable_in_unstable;
 
-    //@ has stability/stable_earlier/struct.StableInLater.html \
-    //      '//span[@class="since"]' '1.0.0'
+    //@ has stability/stable_earlier2/struct.StableInLater.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.6.0'
     #[doc(inline)]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use crate::stable_later::StableInLater;
 
-    //@ has stability/stable_earlier/stable_in_later/struct.Inner.html \
-    //      '//span[@class="since"]' '1.0.0'
+    //@ has stability/stable_earlier2/stable_in_later/struct.Inner.html \
+    //      '//div[@class="main-heading"]//span[@class="since"]' '1.6.0'
     #[doc(inline)]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use crate::stable_later::stable_in_later;
 }
+
+//@ !hasraw stability/trait.UnstableTraitWithStableMethod.html \
+//      '//div[@class="main-heading"]//span[@class="since"]'
+//@ has - '//*[@id="tymethod.foo"]//span[@class="since"]' '1.0.0'
+//@ has - '//*[@id="method.bar"]//span[@class="since"]' '1.0.0'
+#[unstable(feature = "unstable", issue = "none")]
+pub trait UnstableTraitWithStableMethod {
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn foo();
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn bar() {}
+}
+
+//@ has stability/primitive.i32.html \
+//      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+#[rustc_doc_primitive = "i32"]
+//
+/// `i32` is always stable in 1.0, even if you look at it from core.
+#[stable(feature = "rust1", since = "1.0.0")]
+mod prim_i32 {}
+
+//@ has stability/keyword.if.html \
+//      '//div[@class="main-heading"]//span[@class="since"]' '1.0.0'
+#[doc(keyword = "if")]
+//
+/// We currently don't document stability for keywords, but let's test it anyway.
+#[stable(feature = "rust1", since = "1.0.0")]
+mod if_keyword {}