Fix ICE.
This commit is contained in:
parent
0ee393cf01
commit
d8716f5a3f
@ -153,11 +153,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
|
||||
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
|
||||
match item.kind {
|
||||
hir::ItemKind::Fn(ref sig, ..) => {
|
||||
hir::ItemKind::Fn(ref sig, _, body_id) => {
|
||||
if !(is_entrypoint_fn(cx, cx.tcx.hir().local_def_id(item.hir_id))
|
||||
|| in_external_macro(cx.tcx.sess, item.span))
|
||||
{
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
|
||||
}
|
||||
},
|
||||
hir::ItemKind::Impl {
|
||||
@ -180,7 +180,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
|
||||
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
|
||||
if let hir::TraitItemKind::Method(ref sig, ..) = item.kind {
|
||||
if !in_external_macro(cx.tcx.sess, item.span) {
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,8 +190,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
|
||||
if self.in_trait_impl || in_external_macro(cx.tcx.sess, item.span) {
|
||||
return;
|
||||
}
|
||||
if let hir::ImplItemKind::Method(ref sig, ..) = item.kind {
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers);
|
||||
if let hir::ImplItemKind::Method(ref sig, body_id) = item.kind {
|
||||
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, Some(body_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,6 +202,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
||||
span: impl Into<MultiSpan> + Copy,
|
||||
sig: &hir::FnSig<'_>,
|
||||
headers: DocHeaders,
|
||||
body_id: Option<hir::BodyId>,
|
||||
) {
|
||||
if !cx.access_levels.is_exported(hir_id) {
|
||||
return; // Private functions do not require doc comments
|
||||
@ -222,24 +223,24 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
||||
span,
|
||||
"docs for function returning `Result` missing `# Errors` section",
|
||||
);
|
||||
} else {
|
||||
let def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||
} else if let (Some(body_id), Some(future)) = (body_id, get_trait_def_id(cx, &paths::FUTURE)) {
|
||||
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
|
||||
let mir = cx.tcx.optimized_mir(def_id);
|
||||
if let Some(future) = get_trait_def_id(cx, &paths::FUTURE) {
|
||||
if implements_trait(cx, mir.return_ty(), future, &[]) {
|
||||
use TyKind::*;
|
||||
let ret_ty = mir.return_ty();
|
||||
|
||||
if let Opaque(_, subs) = mir.return_ty().kind {
|
||||
if let Some(ty) = subs.types().next() {
|
||||
if let Generator(_, subs, _) = ty.kind {
|
||||
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
|
||||
span_lint(
|
||||
cx,
|
||||
MISSING_ERRORS_DOC,
|
||||
span,
|
||||
"docs for function returning `Result` missing `# Errors` section",
|
||||
);
|
||||
}
|
||||
if implements_trait(cx, ret_ty, future, &[]) {
|
||||
use TyKind::*;
|
||||
|
||||
if let Opaque(_, subs) = ret_ty.kind {
|
||||
if let Some(ty) = subs.types().next() {
|
||||
if let Generator(_, subs, _) = ty.kind {
|
||||
if match_type(cx, subs.as_generator().return_ty(def_id, cx.tcx), &paths::RESULT) {
|
||||
span_lint(
|
||||
cx,
|
||||
MISSING_ERRORS_DOC,
|
||||
span,
|
||||
"docs for function returning `Result` missing `# Errors` section",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user