Skip to content

Commit

Permalink
Auto merge of #7034 - Jarcho:missing_doc_ice, r=phansch
Browse files Browse the repository at this point in the history
Fix ICE in `missing_panics_doc`

fixes: #7033
changelog: Fix ICE in `missing_panics_doc` while searching in a `const` block
  • Loading branch information
bors committed Apr 5, 2021
2 parents 8d221c5 + a00de90 commit 81f9946
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_errors::emitter::EmitterWriter;
use rustc_errors::Handler;
use rustc_hir as hir;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_hir::{AnonConst, Expr, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
use rustc_middle::lint::in_external_macro;
Expand Down Expand Up @@ -735,6 +735,9 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
intravisit::walk_expr(self, expr);
}

// Panics in const blocks will cause compilation to fail.
fn visit_anon_const(&mut self, _: &'tcx AnonConst) {}

fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
}
Expand Down
21 changes: 19 additions & 2 deletions tests/ui/doc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This file tests for the `DOC_MARKDOWN` lint.

#![allow(dead_code)]
#![allow(dead_code, incomplete_features)]
#![warn(clippy::doc_markdown)]
#![feature(custom_inner_attributes)]
#![feature(custom_inner_attributes, const_generics, const_evaluatable_checked, const_option)]
#![rustfmt::skip]

/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
Expand Down Expand Up @@ -202,3 +202,20 @@ fn issue_2343() {}
/// This should not cause an ICE:
/// __|_ _|__||_|
fn pulldown_cmark_crash() {}

// issue #7033 - const_evaluatable_checked ICE
struct S<T, const N: usize>
where [(); N.checked_next_power_of_two().unwrap()]: {
arr: [T; N.checked_next_power_of_two().unwrap()],
n: usize,
}

impl<T: Copy + Default, const N: usize> S<T, N>
where [(); N.checked_next_power_of_two().unwrap()]: {
fn new() -> Self {
Self {
arr: [T::default(); N.checked_next_power_of_two().unwrap()],
n: 0,
}
}
}

0 comments on commit 81f9946

Please sign in to comment.