Skip to content

Commit fbc2e92

Browse files
committed
Fix handling of for loop patterns in regionck
When establishing region links within a pattern, use the mem-cat of the type the pattern matches against (that is, the result of `iter.next()`) rather than that of the iterator type. Closes #17068 Closes #18767
1 parent b80edf1 commit fbc2e92

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/librustc/middle/typeck/check/regionck.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,12 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
770770

771771
{
772772
let mc = mc::MemCategorizationContext::new(rcx);
773-
let head_cmt = ignore_err!(mc.cat_expr(&**head));
774-
link_pattern(rcx, mc, head_cmt, &**pat);
773+
let pat_ty = rcx.resolve_node_type(pat.id);
774+
let pat_cmt = mc.cat_rvalue(pat.id,
775+
pat.span,
776+
ty::ReScope(body.id),
777+
pat_ty);
778+
link_pattern(rcx, mc, pat_cmt, &**pat);
775779
}
776780

777781
rcx.visit_expr(&**head);

0 commit comments

Comments
 (0)