Skip to content

Commit 0b0fe69

Browse files
authored
Merge pull request #2175 from lukasstevens/master
Check for arrays with size > 32
2 parents f9682ca + 0ae2ece commit 0b0fe69

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

clippy_lints/src/loops.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use itertools::Itertools;
22
use reexport::*;
33
use rustc::hir::*;
44
use rustc::hir::def::Def;
5-
use rustc::hir::def_id;
5+
use rustc::hir::def_id;
66
use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
77
use rustc::hir::map::Node::{NodeBlock, NodeExpr, NodeStmt};
88
use rustc::lint::*;
@@ -363,7 +363,7 @@ impl LintPass for Pass {
363363
EMPTY_LOOP,
364364
WHILE_LET_ON_ITERATOR,
365365
FOR_KV_MAP,
366-
NEVER_LOOP,
366+
NEVER_LOOP,
367367
MUT_RANGE_BOUND
368368
)
369369
}
@@ -1128,7 +1128,12 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
11281128
let fn_arg_tys = method_type.fn_sig(cx.tcx).inputs();
11291129
assert_eq!(fn_arg_tys.skip_binder().len(), 1);
11301130
if fn_arg_tys.skip_binder()[0].is_region_ptr() {
1131-
lint_iter_method(cx, args, arg, method_name);
1131+
match cx.tables.expr_ty(&args[0]).sty {
1132+
// If the length is greater than 32 no traits are implemented for array and
1133+
// therefore we cannot use `&`.
1134+
ty::TypeVariants::TyArray(_, size) if const_to_u64(size) > 32 => (),
1135+
_ => lint_iter_method(cx, args, arg, method_name)
1136+
};
11321137
} else {
11331138
let object = snippet(cx, args[0].span, "_");
11341139
span_lint_and_sugg(
@@ -1319,7 +1324,7 @@ struct MutateDelegate {
13191324
impl<'tcx> Delegate<'tcx> for MutateDelegate {
13201325
fn consume(&mut self, _: NodeId, _: Span, _: cmt<'tcx>, _: ConsumeMode) {
13211326
}
1322-
1327+
13231328
fn matched_pat(&mut self, _: &Pat, _: cmt<'tcx>, _: MatchMode) {
13241329
}
13251330

@@ -1500,13 +1505,13 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
15001505
walk_expr(&mut used_visitor, idx);
15011506
used_visitor.used
15021507
};
1503-
1508+
15041509
if index_used {
15051510
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
15061511
match def {
15071512
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
15081513
let hir_id = self.cx.tcx.hir.node_to_hir_id(node_id);
1509-
1514+
15101515
let parent_id = self.cx.tcx.hir.get_parent(expr.id);
15111516
let parent_def_id = self.cx.tcx.hir.local_def_id(parent_id);
15121517
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);

0 commit comments

Comments
 (0)