Skip to content

Commit

Permalink
Unrolled build for rust-lang#129318
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#129318 - GuillaumeGomez:rm-unneeded-defid-conversion, r=notriddle

Remove unneeded conversion to `DefId` for `ExtraInfo`

I'm working on adding support for "unit test doctests" and this first cleanup came up so just sending it ahead of the rest.

r? ``@notriddle``
  • Loading branch information
rust-timer authored Aug 21, 2024
2 parents 5aea140 + 83fce47 commit 5dab9a6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
7 changes: 6 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel, StableS
use rustc_const_eval::const_eval::is_unstable_const_fn;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{BodyId, Mutability};
use rustc_hir_analysis::check::intrinsic::intrinsic_operation_unsafety;
Expand Down Expand Up @@ -88,6 +88,11 @@ impl ItemId {
}
}

#[inline]
pub(crate) fn as_local_def_id(self) -> Option<LocalDefId> {
self.as_def_id().and_then(|id| id.as_local())
}

#[inline]
pub(crate) fn krate(self) -> CrateNum {
match self {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/doctest/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a, 'tcx> HirCollector<'a, 'tcx> {
self.enable_per_target_ignores,
Some(&crate::html::markdown::ExtraInfo::new(
self.tcx,
def_id.to_def_id(),
def_id,
span_of_fragments(&attrs.doc_strings).unwrap_or(sp),
)),
);
Expand Down
44 changes: 20 additions & 24 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use pulldown_cmark::{
};
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{Diag, DiagMessage};
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::TyCtxt;
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
use rustc_resolve::rustdoc::may_be_doc_link;
Expand Down Expand Up @@ -818,45 +818,41 @@ pub(crate) fn find_codes<T: doctest::DocTestVisitor>(
}

pub(crate) struct ExtraInfo<'tcx> {
def_id: DefId,
def_id: LocalDefId,
sp: Span,
tcx: TyCtxt<'tcx>,
}

impl<'tcx> ExtraInfo<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: DefId, sp: Span) -> ExtraInfo<'tcx> {
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, sp: Span) -> ExtraInfo<'tcx> {
ExtraInfo { def_id, sp, tcx }
}

fn error_invalid_codeblock_attr(&self, msg: impl Into<DiagMessage>) {
if let Some(def_id) = self.def_id.as_local() {
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
|lint| {
lint.primary_message(msg);
},
);
}
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(self.def_id),
self.sp,
|lint| {
lint.primary_message(msg);
},
);
}

fn error_invalid_codeblock_attr_with_help(
&self,
msg: impl Into<DiagMessage>,
f: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
) {
if let Some(def_id) = self.def_id.as_local() {
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
|lint| {
lint.primary_message(msg);
f(lint);
},
);
}
self.tcx.node_span_lint(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(self.def_id),
self.sp,
|lint| {
lint.primary_message(msg);
f(lint);
},
);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/passes/lint/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use crate::core::DocContext;
use crate::html::markdown::{self, RustCodeBlock};

pub(crate) fn visit_item(cx: &DocContext<'_>, item: &clean::Item) {
if let Some(dox) = &item.opt_doc_value() {
if let Some(def_id) = item.item_id.as_local_def_id()
&& let Some(dox) = &item.opt_doc_value()
{
let sp = item.attr_span(cx.tcx);
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, item.item_id.expect_def_id(), sp);
let extra = crate::html::markdown::ExtraInfo::new(cx.tcx, def_id, sp);
for code_block in markdown::rust_code_blocks(dox, &extra) {
check_rust_syntax(cx, item, dox, code_block);
}
Expand Down

0 comments on commit 5dab9a6

Please sign in to comment.