Rollup merge of #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``
This commit is contained in:
commit
f6312870a5
@ -12,7 +12,7 @@
|
||||
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;
|
||||
@ -88,6 +88,11 @@ pub(crate) fn as_def_id(self) -> Option<DefId> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
@ -136,7 +136,7 @@ fn visit_testable<F: FnOnce(&mut Self)>(
|
||||
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),
|
||||
)),
|
||||
);
|
||||
|
@ -40,7 +40,7 @@
|
||||
};
|
||||
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;
|
||||
@ -818,27 +818,25 @@ 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(
|
||||
@ -846,17 +844,15 @@ fn error_invalid_codeblock_attr_with_help(
|
||||
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);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,11 @@
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user