diff --git a/Cargo.lock b/Cargo.lock index 9464c87fc728b..be5ceeb5f1341 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1280,7 +1280,6 @@ name = "error_index_generator" version = "0.0.0" dependencies = [ "rustdoc", - "walkdir", ] [[package]] diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index d831161bcb686..f1d2d3b30d9e2 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -318,7 +318,7 @@ impl NodeRef pub fn ascend( self, ) -> Result, marker::Edge>, Self> { - assert!(BorrowType::PERMITS_TRAVERSAL); + let _ = BorrowType::TRAVERSAL_PERMIT; // We need to use raw pointers to nodes because, if BorrowType is marker::ValMut, // there might be outstanding mutable references to values that we must not invalidate. let leaf_ptr: *const _ = Self::as_leaf_ptr(&self); @@ -1003,7 +1003,7 @@ impl /// `edge.descend().ascend().unwrap()` and `node.ascend().unwrap().descend()` should /// both, upon success, do nothing. pub fn descend(self) -> NodeRef { - assert!(BorrowType::PERMITS_TRAVERSAL); + let _ = BorrowType::TRAVERSAL_PERMIT; // We need to use raw pointers to nodes because, if BorrowType is // marker::ValMut, there might be outstanding mutable references to // values that we must not invalidate. There's no worry accessing the @@ -1666,15 +1666,17 @@ pub mod marker { pub struct ValMut<'a>(PhantomData<&'a mut ()>); pub trait BorrowType { - // Whether node references of this borrow type allow traversing - // to other nodes in the tree. - const PERMITS_TRAVERSAL: bool = true; + // If node references of this borrow type allow traversing to other + // nodes in the tree, this constant can be evaluated. Thus reading it + // serves as a compile-time assertion. + const TRAVERSAL_PERMIT: () = (); } impl BorrowType for Owned { - // Traversal isn't needed, it happens using the result of `borrow_mut`. + // Reject evaluation, because traversal isn't needed. Instead traversal + // happens using the result of `borrow_mut`. // By disabling traversal, and only creating new references to roots, // we know that every reference of the `Owned` type is to a root node. - const PERMITS_TRAVERSAL: bool = false; + const TRAVERSAL_PERMIT: () = panic!(); } impl BorrowType for Dying {} impl<'a> BorrowType for Immut<'a> {} diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 87d4a25afd586..60ecc9c0bdb1c 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -71,6 +71,12 @@ impl RawWaker { /// pointer of a properly constructed [`RawWaker`] object from inside the /// [`RawWaker`] implementation. Calling one of the contained functions using /// any other `data` pointer will cause undefined behavior. +/// +/// These functions must all be thread-safe (even though [`RawWaker`] is +/// \![Send] + \![Sync]) +/// because [`Waker`] is [Send] + [Sync], and thus wakers may be moved to +/// arbitrary threads or invoked by `&` reference. For example, this means that if the +/// `clone` and `drop` functions manage a reference count, they must do so atomically. #[stable(feature = "futures_api", since = "1.36.0")] #[derive(PartialEq, Copy, Clone, Debug)] pub struct RawWakerVTable { @@ -110,6 +116,12 @@ impl RawWakerVTable { /// Creates a new `RawWakerVTable` from the provided `clone`, `wake`, /// `wake_by_ref`, and `drop` functions. /// + /// These functions must all be thread-safe (even though [`RawWaker`] is + /// \![Send] + \![Sync]) + /// because [`Waker`] is [Send] + [Sync], and thus wakers may be moved to + /// arbitrary threads or invoked by `&` reference. For example, this means that if the + /// `clone` and `drop` functions manage a reference count, they must do so atomically. + /// /// # `clone` /// /// This function will be called when the [`RawWaker`] gets cloned, e.g. when @@ -157,9 +169,9 @@ impl RawWakerVTable { } } -/// The `Context` of an asynchronous task. +/// The context of an asynchronous task. /// -/// Currently, `Context` only serves to provide access to a `&Waker` +/// Currently, `Context` only serves to provide access to a [`&Waker`](Waker) /// which can be used to wake the current task. #[stable(feature = "futures_api", since = "1.36.0")] pub struct Context<'a> { @@ -172,7 +184,7 @@ pub struct Context<'a> { } impl<'a> Context<'a> { - /// Create a new `Context` from a `&Waker`. + /// Create a new `Context` from a [`&Waker`](Waker). #[stable(feature = "futures_api", since = "1.36.0")] #[must_use] #[inline] @@ -180,7 +192,7 @@ impl<'a> Context<'a> { Context { waker, _marker: PhantomData } } - /// Returns a reference to the `Waker` for the current task. + /// Returns a reference to the [`Waker`] for the current task. #[stable(feature = "futures_api", since = "1.36.0")] #[must_use] #[inline] @@ -202,7 +214,18 @@ impl fmt::Debug for Context<'_> { /// This handle encapsulates a [`RawWaker`] instance, which defines the /// executor-specific wakeup behavior. /// -/// Implements [`Clone`], [`Send`], and [`Sync`]. +/// The typical life of a `Waker` is that it is constructed by an executor, wrapped in a +/// [`Context`], then passed to [`Future::poll()`]. Then, if the future chooses to return +/// [`Poll::Pending`], it must also store the waker somehow and call [`Waker::wake()`] when +/// the future should be polled again. +/// +/// Implements [`Clone`], [`Send`], and [`Sync`]; therefore, a waker may be invoked +/// from any thread, including ones not in any way managed by the executor. For example, +/// this might be done to wake a future when a blocking function call completes on another +/// thread. +/// +/// [`Future::poll()`]: core::future::Future::poll +/// [`Poll::Pending`]: core::task::Poll::Pending #[repr(transparent)] #[stable(feature = "futures_api", since = "1.36.0")] pub struct Waker { @@ -219,18 +242,21 @@ unsafe impl Sync for Waker {} impl Waker { /// Wake up the task associated with this `Waker`. /// - /// As long as the runtime keeps running and the task is not finished, it is - /// guaranteed that each invocation of `wake` (or `wake_by_ref`) will be followed - /// by at least one `poll` of the task to which this `Waker` belongs. This makes + /// As long as the executor keeps running and the task is not finished, it is + /// guaranteed that each invocation of [`wake()`](Self::wake) (or + /// [`wake_by_ref()`](Self::wake_by_ref)) will be followed by at least one + /// [`poll()`] of the task to which this `Waker` belongs. This makes /// it possible to temporarily yield to other tasks while running potentially /// unbounded processing loops. /// /// Note that the above implies that multiple wake-ups may be coalesced into a - /// single `poll` invocation by the runtime. + /// single [`poll()`] invocation by the runtime. /// /// Also note that yielding to competing tasks is not guaranteed: it is the /// executor’s choice which task to run and the executor may choose to run the /// current task again. + /// + /// [`poll()`]: crate::future::Future::poll #[inline] #[stable(feature = "futures_api", since = "1.36.0")] pub fn wake(self) { @@ -250,8 +276,8 @@ impl Waker { /// Wake up the task associated with this `Waker` without consuming the `Waker`. /// - /// This is similar to `wake`, but may be slightly less efficient in the case - /// where an owned `Waker` is available. This method should be preferred to + /// This is similar to [`wake()`](Self::wake), but may be slightly less efficient in + /// the case where an owned `Waker` is available. This method should be preferred to /// calling `waker.clone().wake()`. #[inline] #[stable(feature = "futures_api", since = "1.36.0")] @@ -263,7 +289,7 @@ impl Waker { unsafe { (self.waker.vtable.wake_by_ref)(self.waker.data) } } - /// Returns `true` if this `Waker` and another `Waker` have awoken the same task. + /// Returns `true` if this `Waker` and another `Waker` would awake the same task. /// /// This function works on a best-effort basis, and may return false even /// when the `Waker`s would awaken the same task. However, if this function diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index ce2a979475c9c..a5003c66fcad7 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -27,12 +27,23 @@ macro_rules! panic { /// necessary to use [`io::stdout().flush()`][flush] to ensure the output is emitted /// immediately. /// +/// The `print!` macro will lock the standard output on each call. If you call +/// `print!` within a hot loop, this behavior may be the bottleneck of the loop. +/// To avoid this, lock stdout with [`io::stdout().lock()`][lock]: +/// ``` +/// use std::io::{stdout, Write}; +/// +/// let mut lock = stdout().lock(); +/// write!(lock, "hello world").unwrap(); +/// ``` +/// /// Use `print!` only for the primary output of your program. Use /// [`eprint!`] instead to print error and progress messages. /// /// [flush]: crate::io::Write::flush /// [`println!`]: crate::println /// [`eprint!`]: crate::eprint +/// [lock]: crate::io::Stdout /// /// # Panics /// @@ -75,11 +86,22 @@ macro_rules! print { /// This macro uses the same syntax as [`format!`], but writes to the standard output instead. /// See [`std::fmt`] for more information. /// +/// The `println!` macro will lock the standard output on each call. If you call +/// `println!` within a hot loop, this behavior may be the bottleneck of the loop. +/// To avoid this, lock stdout with [`io::stdout().lock()`][lock]: +/// ``` +/// use std::io::{stdout, Write}; +/// +/// let mut lock = stdout().lock(); +/// writeln!(lock, "hello world").unwrap(); +/// ``` +/// /// Use `println!` only for the primary output of your program. Use /// [`eprintln!`] instead to print error and progress messages. /// /// [`std::fmt`]: crate::fmt /// [`eprintln!`]: crate::eprintln +/// [lock]: crate::io::Stdout /// /// # Panics /// diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index a7048e788b65a..f367edcbf5a81 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -300,7 +300,7 @@ pub(crate) fn build_impls( } /// `parent_module` refers to the parent of the re-export, not the original item -fn merge_attrs( +pub(crate) fn merge_attrs( cx: &mut DocContext<'_>, parent_module: Option, old_attrs: Attrs<'_>, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4c39021903c5b..909a47d07b166 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -482,7 +482,7 @@ impl Item { cx: &mut DocContext<'_>, cfg: Option>, ) -> Item { - trace!("name={:?}, def_id={:?}", name, def_id); + trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg); // Primitives and Keywords are written in the source code as private modules. // The modules need to be private so that nobody actually uses them, but the @@ -801,6 +801,31 @@ impl ItemKind { | KeywordItem => [].iter(), } } + + /// Returns `true` if this item does not appear inside an impl block. + pub(crate) fn is_non_assoc(&self) -> bool { + matches!( + self, + StructItem(_) + | UnionItem(_) + | EnumItem(_) + | TraitItem(_) + | ModuleItem(_) + | ExternCrateItem { .. } + | FunctionItem(_) + | TypedefItem(_) + | OpaqueTyItem(_) + | StaticItem(_) + | ConstantItem(_) + | TraitAliasItem(_) + | ForeignFunctionItem(_) + | ForeignStaticItem(_) + | ForeignTypeItem + | MacroItem(_) + | ProcMacroItem(_) + | PrimitiveItem(_) + ) + } } #[derive(Clone, Debug)] diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index f9d6b4619cc77..6272f47f460ca 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -191,12 +191,6 @@ impl StylePath { } } -fn write_srclink(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer) { - if let Some(l) = cx.src_href(item) { - write!(buf, "source", l) - } -} - #[derive(Debug, Eq, PartialEq, Hash)] struct ItemEntry { url: String, @@ -522,7 +516,14 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option cfg.as_deref().cloned(), }; - debug!("Portability {:?} - {:?} = {:?}", item.cfg, parent.and_then(|p| p.cfg.as_ref()), cfg); + debug!( + "Portability {:?} {:?} (parent: {:?}) - {:?} = {:?}", + item.name, + item.cfg, + parent, + parent.and_then(|p| p.cfg.as_ref()), + cfg + ); Some(format!("
{}
", cfg?.render_long_html())) } @@ -840,12 +841,13 @@ fn assoc_method( /// Note that it is possible for an unstable function to be const-stable. In that case, the span /// will include the const-stable version, but no stable version will be emitted, as a natural /// consequence of the above rules. -fn render_stability_since_raw( +fn render_stability_since_raw_with_extra( w: &mut Buffer, ver: Option, const_stability: Option, containing_ver: Option, containing_const_ver: Option, + extra_class: &str, ) -> bool { let stable_version = ver.filter(|inner| !inner.is_empty() && Some(*inner) != containing_ver); @@ -893,12 +895,30 @@ fn render_stability_since_raw( } if !stability.is_empty() { - write!(w, r#"{}"#, title, stability); + write!(w, r#"{stability}"#); } !stability.is_empty() } +#[inline] +fn render_stability_since_raw( + w: &mut Buffer, + ver: Option, + const_stability: Option, + containing_ver: Option, + containing_const_ver: Option, +) -> bool { + render_stability_since_raw_with_extra( + w, + ver, + const_stability, + containing_ver, + containing_const_ver, + "", + ) +} + fn render_assoc_item( w: &mut Buffer, item: &clean::Item, @@ -1681,23 +1701,29 @@ fn render_rightside( RenderMode::Normal => (item.const_stability(tcx), containing_item.const_stable_since(tcx)), RenderMode::ForDeref { .. } => (None, None), }; + let src_href = cx.src_href(item); + let has_src_ref = src_href.is_some(); let mut rightside = Buffer::new(); - let has_stability = render_stability_since_raw( + let has_stability = render_stability_since_raw_with_extra( &mut rightside, item.stable_since(tcx), const_stability, containing_item.stable_since(tcx), const_stable_since, + if has_src_ref { "" } else { " rightside" }, ); - let mut srclink = Buffer::empty_from(w); - write_srclink(cx, item, &mut srclink); - if has_stability && !srclink.is_empty() { - rightside.write_str(" · "); + if let Some(l) = src_href { + if has_stability { + write!(rightside, " · source", l) + } else { + write!(rightside, "source", l) + } } - rightside.push_buffer(srclink); - if !rightside.is_empty() { + if has_stability && has_src_ref { write!(w, "{}", rightside.into_inner()); + } else { + w.push_buffer(rightside); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 6d0a825fec866..912601dda20b1 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -18,7 +18,7 @@ use std::rc::Rc; use super::{ collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_section, notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code, - render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink, + render_attributes_in_pre, render_impl, render_rightside, render_stability_since_raw, AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean; @@ -477,7 +477,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> (cfg, _) => cfg.as_deref().cloned(), }; - debug!("Portability {:?} - {:?} = {:?}", item.cfg, parent.cfg, cfg); + debug!("Portability name={:?} {:?} - {:?} = {:?}", item.name, item.cfg, parent.cfg, cfg); if let Some(ref cfg) = cfg { tags += &tag_html("portability", &cfg.render_long_plain(), &cfg.render_short_html()); } @@ -709,14 +709,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: write!(w, "
"); } write!(w, "
", id); - write!(w, "
"); - - let has_stability = render_stability_since(w, m, t, cx.tcx()); - if has_stability { - w.write_str(" · "); - } - write_srclink(cx, m, w); - write!(w, "
"); + render_rightside(w, cx, m, t, RenderMode::Normal); write!(w, "

"); render_assoc_item( w, @@ -1260,7 +1253,13 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: w.write_str(")"); } w.write_str(""); - render_stability_since(w, variant, it, cx.tcx()); + render_stability_since_raw( + w, + variant.stable_since(cx.tcx()), + variant.const_stability(cx.tcx()), + it.stable_since(cx.tcx()), + it.const_stable_since(cx.tcx()), + ); w.write_str("

"); use crate::clean::Variant; @@ -1591,21 +1590,6 @@ where w.write_str(""); } -fn render_stability_since( - w: &mut Buffer, - item: &clean::Item, - containing_item: &clean::Item, - tcx: TyCtxt<'_>, -) -> bool { - render_stability_since_raw( - w, - item.stable_since(tcx), - item.const_stability(tcx), - containing_item.stable_since(tcx), - containing_item.const_stable_since(tcx), - ) -} - fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering { let lhss = format!("{}", lhs.inner_impl().print(false, cx)); let rhss = format!("{}", rhs.inner_impl().print(false, cx)); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index f6a7875fddc8c..38cdcd61e88cb 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1200,14 +1200,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ float: right; } -.variants_table { - width: 100%; -} - -.variants_table tbody tr td:first-child { - width: 1%; /* make the variant name as small as possible */ -} - td.summary-column { width: 100%; } diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 63009006b3f1f..8591f22d6de60 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -199,7 +199,7 @@ details.rustdoc-toggle > summary::before { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 1fcda22b6f4fa..d5cd47c3e19d5 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -165,7 +165,7 @@ details.rustdoc-toggle > summary::before { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 7139c199729ae..cff70268144f3 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -148,7 +148,7 @@ details.rustdoc-toggle > summary::before { .stab { background: #FFF5D6; border-color: #FFC600; } .stab.portability > code { background: none; } -.rightside, +.rightside:not(a), .out-of-band { color: grey; } diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 8e25f6764a9c5..7caffeae3d610 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -13,13 +13,13 @@ {#- -#} {#- -#} {#- -#} - {#- -#} - {#- -#} {%- for theme in themes -%} - {#- -#} {#- -#} {%- if layout.css_file_extension.is_some() -%} - {#- -#} {%- endif -%} {%- if !layout.favicon.is_empty() -%} diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index 0c5d836551823..21d295bb1f88e 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -2,29 +2,53 @@ use std::sync::Arc; use crate::clean::cfg::Cfg; +use crate::clean::inline::{load_attrs, merge_attrs}; use crate::clean::{Crate, Item}; use crate::core::DocContext; use crate::fold::DocFolder; use crate::passes::Pass; +use rustc_hir::def_id::LocalDefId; + pub(crate) const PROPAGATE_DOC_CFG: Pass = Pass { name: "propagate-doc-cfg", run: propagate_doc_cfg, description: "propagates `#[doc(cfg(...))]` to child items", }; -pub(crate) fn propagate_doc_cfg(cr: Crate, _: &mut DocContext<'_>) -> Crate { - CfgPropagator { parent_cfg: None }.fold_crate(cr) +pub(crate) fn propagate_doc_cfg(cr: Crate, cx: &mut DocContext<'_>) -> Crate { + CfgPropagator { parent_cfg: None, parent: None, cx }.fold_crate(cr) } -struct CfgPropagator { +struct CfgPropagator<'a, 'tcx> { parent_cfg: Option>, + parent: Option, + cx: &'a mut DocContext<'tcx>, } -impl DocFolder for CfgPropagator { +impl<'a, 'tcx> DocFolder for CfgPropagator<'a, 'tcx> { fn fold_item(&mut self, mut item: Item) -> Option { let old_parent_cfg = self.parent_cfg.clone(); + if item.kind.is_non_assoc() && + let Some(def_id) = item.item_id.as_def_id().and_then(|def_id| def_id.as_local()) { + let hir = self.cx.tcx.hir(); + let hir_id = hir.local_def_id_to_hir_id(def_id); + let expected_parent = hir.get_parent_item(hir_id); + + // If parents are different, it means that `item` is a reexport and we need to compute + // the actual `cfg` by iterating through its "real" parents. + if self.parent != Some(expected_parent) { + let mut attrs = Vec::new(); + for (parent_hir_id, _) in hir.parent_iter(hir_id) { + let def_id = hir.local_def_id(parent_hir_id).to_def_id(); + attrs.extend_from_slice(load_attrs(self.cx, def_id)); + } + let (_, cfg) = + merge_attrs(self.cx, None, item.attrs.other_attrs.as_slice(), Some(&attrs)); + item.cfg = cfg; + } + } let new_cfg = match (self.parent_cfg.take(), item.cfg.take()) { (None, None) => None, (Some(rc), None) | (None, Some(rc)) => Some(rc), @@ -37,8 +61,15 @@ impl DocFolder for CfgPropagator { self.parent_cfg = new_cfg.clone(); item.cfg = new_cfg; + let old_parent = + if let Some(def_id) = item.item_id.as_def_id().and_then(|def_id| def_id.as_local()) { + self.parent.replace(def_id) + } else { + self.parent.take() + }; let result = self.fold_item_recur(item); self.parent_cfg = old_parent_cfg; + self.parent = old_parent; Some(result) } diff --git a/src/test/rustdoc-gui/anchors.goml b/src/test/rustdoc-gui/anchors.goml index 84b8bbd1b327f..3ad62c721b4b8 100644 --- a/src/test/rustdoc-gui/anchors.goml +++ b/src/test/rustdoc-gui/anchors.goml @@ -1,6 +1,5 @@ // This test is to ensure that the anchors (`§`) have the expected color and position. -goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html -show-text: true +goto: file://|DOC_PATH|/staged_api/struct.Foo.html // This is needed to ensure that the text color is computed. show-text: true @@ -13,10 +12,31 @@ reload: assert-css: ("#toggle-all-docs", {"color": "rgb(0, 0, 0)"}) assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(0, 0, 0)"}) assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(173, 55, 138)"}) -assert-css: (".srclink", {"color": "rgb(56, 115, 173)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) move-cursor-to: ".main-heading .srclink" -assert-css: (".srclink", {"text-decoration": "underline solid rgb(56, 115, 173)"}) +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "underline solid rgb(56, 115, 173)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(56, 115, 173)", "text-decoration": "none solid rgb(56, 115, 173)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html assert-css: ("#top-doc-prose-title", {"color": "rgb(0, 0, 0)"}) @@ -32,3 +52,103 @@ move-cursor-to: "#impl-HeavilyDocumentedStruct" assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(0, 0, 0)"}) assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) + +// +// We do the same checks with the dark theme now. +// +local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"} +goto: file://|DOC_PATH|/staged_api/struct.Foo.html + +assert-css: ("#toggle-all-docs", {"color": "rgb(221, 221, 221)"}) +assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(221, 221, 221)"}) +assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(45, 191, 184)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) + +move-cursor-to: ".main-heading .srclink" +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "underline solid rgb(210, 153, 29)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(210, 153, 29)", "text-decoration": "none solid rgb(210, 153, 29)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html + +assert-css: ("#top-doc-prose-title", {"color": "rgb(221, 221, 221)"}) + +assert-css: (".sidebar a", {"color": "rgb(253, 191, 53)"}) +assert-css: (".in-band a", {"color": "rgb(221, 221, 221)"}) + +// We move the cursor over the "Implementations" title so the anchor is displayed. +move-cursor-to: "h2#implementations" +assert-css: ("h2#implementations a.anchor", {"color": "rgb(221, 221, 221)"}) + +// Same thing with the impl block title. +move-cursor-to: "#impl-HeavilyDocumentedStruct" +assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(221, 221, 221)"}) + +assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) + +// +// We do the same checks with the ayu theme now. +// +local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"} +goto: file://|DOC_PATH|/staged_api/struct.Foo.html + +assert-css: ("#toggle-all-docs", {"color": "rgb(197, 197, 197)"}) +assert-css: (".fqn .in-band a:nth-of-type(1)", {"color": "rgb(255, 255, 255)"}) +assert-css: (".fqn .in-band a:nth-of-type(2)", {"color": "rgb(255, 160, 165)"}) +assert-css: ( + ".rightside .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, + ALL, +) +compare-elements-css: (".rightside .srclink", ".rightside.srclink", ["color", "text-decoration"]) +compare-elements-css: (".main-heading .srclink", ".rightside.srclink", ["color", "text-decoration"]) + +move-cursor-to: ".main-heading .srclink" +assert-css: ( + ".main-heading .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "underline solid rgb(57, 175, 215)"}, +) +move-cursor-to: ".impl-items .rightside .srclink" +assert-css: ( + ".impl-items .rightside .srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, +) +move-cursor-to: ".impl-items .rightside.srclink" +assert-css: ( + ".impl-items .rightside.srclink", + {"color": "rgb(57, 175, 215)", "text-decoration": "none solid rgb(57, 175, 215)"}, +) + +goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html + +assert-css: ("#top-doc-prose-title", {"color": "rgb(255, 255, 255)"}) + +assert-css: (".sidebar a", {"color": "rgb(83, 177, 219)"}) +assert-css: (".in-band a", {"color": "rgb(255, 255, 255)"}) + +// We move the cursor over the "Implementations" title so the anchor is displayed. +move-cursor-to: "h2#implementations" +assert-css: ("h2#implementations a.anchor", {"color": "rgb(197, 197, 197)"}) + +// Same thing with the impl block title. +move-cursor-to: "#impl-HeavilyDocumentedStruct" +assert-css: ("#impl-HeavilyDocumentedStruct a.anchor", {"color": "rgb(197, 197, 197)"}) + +assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"}) diff --git a/src/test/rustdoc-gui/headings.goml b/src/test/rustdoc-gui/headings.goml index 8c2c3df1588f5..ed07e777b1880 100644 --- a/src/test/rustdoc-gui/headings.goml +++ b/src/test/rustdoc-gui/headings.goml @@ -247,12 +247,12 @@ assert-css: ( local-storage: {"rustdoc-theme": "light"} goto: file://|DOC_PATH|/staged_api/struct.Foo.html -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) local-storage: {"rustdoc-theme": "dark"} reload: -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) local-storage: {"rustdoc-theme": "ayu"} reload: -assert-css: (".since", {"color": "rgb(128, 128, 128)"}) +assert-css: (".since", {"color": "rgb(128, 128, 128)"}, ALL) diff --git a/src/test/rustdoc-gui/src/staged_api/Cargo.toml b/src/test/rustdoc-gui/src/staged_api/Cargo.toml index 117c4134e3419..b231be6eee902 100644 --- a/src/test/rustdoc-gui/src/staged_api/Cargo.toml +++ b/src/test/rustdoc-gui/src/staged_api/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" path = "lib.rs" [features] -default = ["some_feature"] +default = ["some_feature", "some_other_feature"] some_feature = [] +some_other_feature = [] diff --git a/src/test/rustdoc-gui/src/staged_api/lib.rs b/src/test/rustdoc-gui/src/staged_api/lib.rs index 0cb460f03f701..5934593a8999b 100644 --- a/src/test/rustdoc-gui/src/staged_api/lib.rs +++ b/src/test/rustdoc-gui/src/staged_api/lib.rs @@ -7,4 +7,6 @@ pub struct Foo {} impl Foo { #[stable(feature = "some_feature", since = "1.3.5")] pub fn bar() {} + #[stable(feature = "some_other_feature", since = "1.3.6")] + pub fn yo() {} } diff --git a/src/test/rustdoc/anchors.no_const_anchor.html b/src/test/rustdoc/anchors.no_const_anchor.html index 98f47e53038a9..4da1ffead2a4c 100644 --- a/src/test/rustdoc/anchors.no_const_anchor.html +++ b/src/test/rustdoc/anchors.no_const_anchor.html @@ -1 +1 @@ - + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_const_anchor2.html b/src/test/rustdoc/anchors.no_const_anchor2.html index 6d37e8e5eee5e..c002519760242 100644 --- a/src/test/rustdoc/anchors.no_const_anchor2.html +++ b/src/test/rustdoc/anchors.no_const_anchor2.html @@ -1 +1 @@ - + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_method_anchor.html b/src/test/rustdoc/anchors.no_method_anchor.html index f46d3090ed370..521fdcb7877a7 100644 --- a/src/test/rustdoc/anchors.no_method_anchor.html +++ b/src/test/rustdoc/anchors.no_method_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_trait_method_anchor.html b/src/test/rustdoc/anchors.no_trait_method_anchor.html index 445a7bb560aca..6b78c7c811a06 100644 --- a/src/test/rustdoc/anchors.no_trait_method_anchor.html +++ b/src/test/rustdoc/anchors.no_trait_method_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_tymethod_anchor.html b/src/test/rustdoc/anchors.no_tymethod_anchor.html index bb0771b10035d..c08f4427cf697 100644 --- a/src/test/rustdoc/anchors.no_tymethod_anchor.html +++ b/src/test/rustdoc/anchors.no_tymethod_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/anchors.no_type_anchor.html b/src/test/rustdoc/anchors.no_type_anchor.html index d317eb5005017..ba8e65443ec81 100644 --- a/src/test/rustdoc/anchors.no_type_anchor.html +++ b/src/test/rustdoc/anchors.no_type_anchor.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/rustdoc/cfg_doc_reexport.rs b/src/test/rustdoc/cfg_doc_reexport.rs new file mode 100644 index 0000000000000..addb6709db1da --- /dev/null +++ b/src/test/rustdoc/cfg_doc_reexport.rs @@ -0,0 +1,33 @@ +#![feature(doc_cfg)] +#![feature(no_core)] + +#![crate_name = "foo"] +#![no_core] + +// @has 'foo/index.html' +// @has - '//*[@class="item-left module-item"]/*[@class="stab portability"]' 'foobar' +// @has - '//*[@class="item-left module-item"]/*[@class="stab portability"]' 'bar' + +#[doc(cfg(feature = "foobar"))] +mod imp_priv { + // @has 'foo/struct.BarPriv.html' + // @has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ + // 'Available on crate feature foobar only.' + pub struct BarPriv {} + impl BarPriv { + pub fn test() {} + } +} +#[doc(cfg(feature = "foobar"))] +pub use crate::imp_priv::*; + +pub mod bar { + // @has 'foo/bar/struct.Bar.html' + // @has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ + // 'Available on crate feature bar only.' + #[doc(cfg(feature = "bar"))] + pub struct Bar; +} + +#[doc(cfg(feature = "bar"))] +pub use bar::Bar; diff --git a/src/test/rustdoc/ensure-src-link.rs b/src/test/rustdoc/ensure-src-link.rs index 9f8b0277e76b0..c65387080f11b 100644 --- a/src/test/rustdoc/ensure-src-link.rs +++ b/src/test/rustdoc/ensure-src-link.rs @@ -2,5 +2,5 @@ // This test ensures that the [src] link is present on traits items. -// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="srclink"]' "source" +// @has foo/trait.Iterator.html '//*[@id="method.zip"]//a[@class="srclink rightside"]' "source" pub use std::iter::Iterator; diff --git a/src/test/rustdoc/src-links-auto-impls.rs b/src/test/rustdoc/src-links-auto-impls.rs index 69be9aa8d5f10..313a4b1189334 100644 --- a/src/test/rustdoc/src-links-auto-impls.rs +++ b/src/test/rustdoc/src-links-auto-impls.rs @@ -6,7 +6,7 @@ // @has - '//*[@id="impl-Sync-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Sync for Unsized' // @!has - '//*[@id="impl-Sync-for-Unsized"]//a[@class="srclink"]' 'source' // @has - '//*[@id="impl-Any-for-Unsized"]/h3[@class="code-header in-band"]' 'impl Any for T' -// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink"]' 'source' +// @has - '//*[@id="impl-Any-for-Unsized"]//a[@class="srclink rightside"]' 'source' pub struct Unsized { data: [u8], } diff --git a/src/test/rustdoc/version-separator-without-source.rs b/src/test/rustdoc/version-separator-without-source.rs index ae866deba1ef0..04ea46a7f3a01 100644 --- a/src/test/rustdoc/version-separator-without-source.rs +++ b/src/test/rustdoc/version-separator-without-source.rs @@ -16,7 +16,7 @@ pub fn foo() {} pub struct Bar; impl Bar { - // @has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0' + // @has - '//*[@id="method.bar"]/*[@class="since rightside"]' '2.0' // @!has - '//*[@id="method.bar"]/*[@class="rightside"]' '2.0 ·' #[stable(feature = "foobar", since = "2.0")] pub fn bar() {} diff --git a/src/tools/error_index_generator/Cargo.toml b/src/tools/error_index_generator/Cargo.toml index c84b79e11e9b4..b9fd852f742cf 100644 --- a/src/tools/error_index_generator/Cargo.toml +++ b/src/tools/error_index_generator/Cargo.toml @@ -6,9 +6,6 @@ edition = "2021" [dependencies] rustdoc = { path = "../../librustdoc" } -[build-dependencies] -walkdir = "2" - [[bin]] name = "error_index_generator" path = "main.rs"