Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f79a2a3

Browse files
committed
needless_collect: use node_type_opt instead of node_type
It may prevent future ICEs.
1 parent 1835d8a commit f79a2a3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/loops/needless_collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
2727
if chain_method.ident.name == sym!(collect) && is_trait_method(cx, &args[0], sym::Iterator);
2828
if let Some(generic_args) = chain_method.args;
2929
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
30-
let ty = cx.typeck_results().node_type(ty.hir_id);
30+
if let Some(ty) = cx.typeck_results().node_type_opt(ty.hir_id);
3131
if is_type_diagnostic_item(cx, ty, sym::vec_type)
3232
|| is_type_diagnostic_item(cx, ty, sym::vecdeque_type)
3333
|| match_type(cx, ty, &paths::BTREEMAP)
@@ -82,7 +82,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
8282
if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind;
8383
if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator);
8484
if let Some(hir_id) = get_hir_id(*ty, method_name.args);
85-
if let ty = cx.typeck_results().node_type(hir_id);
85+
if let Some(ty) = cx.typeck_results().node_type_opt(hir_id);
8686
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
8787
is_type_diagnostic_item(cx, ty, sym::vecdeque_type) ||
8888
is_type_diagnostic_item(cx, ty, sym::BinaryHeap) ||

0 commit comments

Comments
 (0)