rustdoc: Replace pair of Option
s with an enum
They are never both `None` or both `Some`, so it makes more sense to use an enum so that we "make impossible states impossible".
This commit is contained in:
parent
61edfd591c
commit
f820fd2bc0
1 changed files with 11 additions and 8 deletions
|
@ -690,25 +690,29 @@ crate fn find_testable_code<T: doctest::Tester>(
|
||||||
}
|
}
|
||||||
|
|
||||||
crate struct ExtraInfo<'tcx> {
|
crate struct ExtraInfo<'tcx> {
|
||||||
hir_id: Option<HirId>,
|
id: ExtraInfoId,
|
||||||
item_did: Option<DefId>,
|
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ExtraInfoId {
|
||||||
|
Hir(HirId),
|
||||||
|
Def(DefId),
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> ExtraInfo<'tcx> {
|
impl<'tcx> ExtraInfo<'tcx> {
|
||||||
crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> {
|
crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> {
|
||||||
ExtraInfo { hir_id: Some(hir_id), item_did: None, sp, tcx }
|
ExtraInfo { id: ExtraInfoId::Hir(hir_id), sp, tcx }
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> {
|
crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> {
|
||||||
ExtraInfo { hir_id: None, item_did: Some(did), sp, tcx }
|
ExtraInfo { id: ExtraInfoId::Def(did), sp, tcx }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_invalid_codeblock_attr(&self, msg: &str, help: &str) {
|
fn error_invalid_codeblock_attr(&self, msg: &str, help: &str) {
|
||||||
let hir_id = match (self.hir_id, self.item_did) {
|
let hir_id = match self.id {
|
||||||
(Some(h), _) => h,
|
ExtraInfoId::Hir(hir_id) => hir_id,
|
||||||
(None, Some(item_did)) => {
|
ExtraInfoId::Def(item_did) => {
|
||||||
match item_did.as_local() {
|
match item_did.as_local() {
|
||||||
Some(item_did) => self.tcx.hir().local_def_id_to_hir_id(item_did),
|
Some(item_did) => self.tcx.hir().local_def_id_to_hir_id(item_did),
|
||||||
None => {
|
None => {
|
||||||
|
@ -717,7 +721,6 @@ impl<'tcx> ExtraInfo<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, None) => return,
|
|
||||||
};
|
};
|
||||||
self.tcx.struct_span_lint_hir(
|
self.tcx.struct_span_lint_hir(
|
||||||
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
|
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
|
||||||
|
|
Loading…
Reference in a new issue