Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ const impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
///
/// # Panics
///
/// Panics if the legacy range iterator has been exhausted.
/// If the legacy range iterator has been exhausted,
/// this function will either panic or return an empty range.
///
/// # Examples
///
Expand All @@ -419,19 +420,23 @@ const impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
/// assert_eq!((empty.start, empty.last), (0, 0));
/// ```
///
/// ```should_panic
/// ```
/// # // This test requires unwinding to work.
/// # // Disable it when unwinding isn't available.
/// # #[cfg(panic = "unwind")]
/// # fn main() {
/// use core::range::legacy;
/// use core::range::RangeInclusive;
/// use std::panic::catch_unwind;
///
/// let mut exhausted: legacy::RangeInclusive<i32> = 0..=0;
/// exhausted.next();
/// # if exhausted.is_empty() {
/// # // assert!s don't work correctly in `should_panic` doctests since you
/// # // can't assert the panic message. Skip the rest of the test instead,
/// # // so that the expected panic doesn't happen and the test fails.
/// assert!(exhausted.is_empty());
/// let _ = RangeInclusive::from(exhausted); // this panics
/// let result = catch_unwind(|| RangeInclusive::from(exhausted));
/// // The `from` call either panicked or returned an empty range.
/// assert!(result.is_err() || result.is_ok_and(|range| range.is_empty()));
/// # }
/// # #[cfg(not(panic = "unwind"))]
/// # fn main() {}
/// ```
#[inline]
fn from(value: legacy::RangeInclusive<T>) -> Self {
Expand Down
37 changes: 22 additions & 15 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,21 +681,26 @@ fn build_module(
// We are only interested into `Res::Def`. And in there, we only want "items" which get their own
// rustdoc page. So not `DefKind::Ctor` for example (which is returned by `tcx.module_children()`).
fn should_ignore_res(res: Res) -> bool {
!matches!(res, Res::Def(def_kind, _) if !should_ignore_def_kind(def_kind))
}

fn should_ignore_def_kind(kind: DefKind) -> bool {
!matches!(
res,
Res::Def(DefKind::Trait, _)
| Res::Def(DefKind::TraitAlias, _)
| Res::Def(DefKind::Fn, _)
| Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::TyAlias, _)
| Res::Def(DefKind::Enum, _)
| Res::Def(DefKind::ForeignTy, _)
| Res::Def(DefKind::Variant, _)
| Res::Def(DefKind::Mod, _)
| Res::Def(DefKind::Static { .. }, _)
| Res::Def(DefKind::Const { .. }, _)
| Res::Def(DefKind::Macro(_), _)
kind,
DefKind::Trait
| DefKind::TraitAlias
| DefKind::Fn
| DefKind::Struct
| DefKind::Union
| DefKind::TyAlias
| DefKind::Enum
| DefKind::ForeignTy
| DefKind::Variant
| DefKind::Mod
| DefKind::Static { .. }
| DefKind::Const { .. }
| DefKind::Macro(_)
| DefKind::Use
)
}

Expand Down Expand Up @@ -770,13 +775,15 @@ fn build_module_items(
} else if let Some(def_id) = res.opt_def_id()
&& let Some(reexport) = item.reexport_chain.first()
&& let Some(reexport_def_id) = reexport.id()
&& !should_ignore_def_kind(cx.tcx.def_kind(reexport_def_id))
&& find_attr!(
load_attrs(cx.tcx, reexport_def_id),
Doc(d)
if d.inline.first().is_some_and(|(inline, _)| *inline == hir::attrs::DocInline::NoInline)
)
{
if should_ignore_res(res) {
// We don't inline foreign `use`.
if should_ignore_res(res) || matches!(res, Res::Def(DefKind::Use, _)) {
continue;
}
// This item is reexported as `no_inline` so it shouldn't be inlined.
Expand Down
19 changes: 14 additions & 5 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use smallvec::{SmallVec, smallvec};
use tracing::{debug, info, instrument, trace};

use crate::clean::utils::find_nearest_parent_module;
use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType};
use crate::clean::{self, Crate, Item, ItemId, ItemLink, PrimitiveType, reexport_chain};
use crate::core::DocContext;
use crate::html::markdown::{MarkdownLink, MarkdownLinkRange, markdown_links};
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
Expand Down Expand Up @@ -1148,10 +1148,19 @@ impl LinkCollector<'_, '_> {
// `use` statement, we need to use the `def_id` of the `use` statement, not the
// inlined item.
// <https://github.com/rust-lang/rust/pull/151120>
let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id
&& find_attr!(tcx, inline_stmt_id, Deprecated { span, ..} if span == depr_span)
{
inline_stmt_id.to_def_id()
let item_id = if let Some(inline_stmt_id) = item.inline_stmt_id {
let target_def_id = item.item_id.expect_def_id();
reexport_chain(tcx, inline_stmt_id, target_def_id)
.iter()
.flat_map(|reexport| reexport.id())
.find(|&reexport_def_id| {
find_attr!(
tcx,
reexport_def_id,
Deprecated { span, .. } if span == depr_span
)
})
.unwrap_or(target_def_id)
} else {
item.item_id.expect_def_id()
};
Expand Down
Loading
Loading