Skip to content

Commit 27411d6

Browse files
committed
Handle ExprKind::ConstBlock on clippy
1 parent 54596c9 commit 27411d6

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

src/tools/clippy/clippy_lints/src/loops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
742742
| ExprKind::Closure(_, _, _, _, _)
743743
| ExprKind::LlvmInlineAsm(_)
744744
| ExprKind::Path(_)
745+
| ExprKind::ConstBlock(_)
745746
| ExprKind::Lit(_)
746747
| ExprKind::Err => NeverLoopResult::Otherwise,
747748
}

src/tools/clippy/clippy_lints/src/utils/author.rs

+5
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
506506
println!(" if {}.len() == {};", fields_pat, fields.len());
507507
println!(" // unimplemented: field checks");
508508
},
509+
ExprKind::ConstBlock(_) => {
510+
let value_pat = self.next("value");
511+
println!("Const({})", value_pat);
512+
self.current = value_pat;
513+
},
509514
// FIXME: compute length (needs type info)
510515
ExprKind::Repeat(ref value, _) => {
511516
let value_pat = self.next("value");

src/tools/clippy/clippy_lints/src/utils/eager_or_lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::hir::map::Map;
2323
/// This function is named so to stress that it isn't exhaustive and returns FNs.
2424
fn identify_some_pure_patterns(expr: &Expr<'_>) -> bool {
2525
match expr.kind {
26-
ExprKind::Lit(..) | ExprKind::Path(..) | ExprKind::Field(..) => true,
26+
ExprKind::Lit(..) | ExprKind::ConstBlock(..) | ExprKind::Path(..) | ExprKind::Field(..) => true,
2727
ExprKind::AddrOf(_, _, addr_of_expr) => identify_some_pure_patterns(addr_of_expr),
2828
ExprKind::Tup(tup_exprs) => tup_exprs.iter().all(|expr| identify_some_pure_patterns(expr)),
2929
ExprKind::Struct(_, fields, expr) => {

src/tools/clippy/clippy_lints/src/utils/hir_utils.rs

+3
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
559559
self.hash_name(path.ident.name);
560560
self.hash_exprs(args);
561561
},
562+
ExprKind::ConstBlock(ref l_id) => {
563+
self.hash_body(l_id.body);
564+
},
562565
ExprKind::Repeat(ref e, ref l_id) => {
563566
self.hash_expr(e);
564567
self.hash_body(l_id.body);

src/tools/clippy/clippy_lints/src/utils/inspector.rs

+5
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ fn print_expr(cx: &LateContext<'_>, expr: &hir::Expr<'_>, indent: usize) {
338338
print_expr(cx, base, indent + 1);
339339
}
340340
},
341+
hir::ExprKind::ConstBlock(ref anon_const) => {
342+
println!("{}ConstBlock", ind);
343+
println!("{}anon_const:", ind);
344+
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
345+
},
341346
hir::ExprKind::Repeat(ref val, ref anon_const) => {
342347
println!("{}Repeat", ind);
343348
println!("{}value:", ind);

src/tools/clippy/clippy_lints/src/utils/sugg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ impl<'a> Sugg<'a> {
110110
| hir::ExprKind::Index(..)
111111
| hir::ExprKind::InlineAsm(..)
112112
| hir::ExprKind::LlvmInlineAsm(..)
113+
| hir::ExprKind::ConstBlock(..)
113114
| hir::ExprKind::Lit(..)
114115
| hir::ExprKind::Loop(..)
115116
| hir::ExprKind::MethodCall(..)
@@ -157,6 +158,7 @@ impl<'a> Sugg<'a> {
157158
| ast::ExprKind::Index(..)
158159
| ast::ExprKind::InlineAsm(..)
159160
| ast::ExprKind::LlvmInlineAsm(..)
161+
| ast::ExprKind::ConstBlock(..)
160162
| ast::ExprKind::Lit(..)
161163
| ast::ExprKind::Loop(..)
162164
| ast::ExprKind::MacCall(..)

0 commit comments

Comments
 (0)