Skip to content

Commit 8289bf2

Browse files
committed
use pat_ty_adjusted from expr_use_visitor to type of arguments
1 parent 81fedd5 commit 8289bf2

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/librustc/middle/expr_use_visitor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
313313
debug!("consume_body(body={:?})", body);
314314

315315
for arg in &body.arguments {
316-
let arg_ty = return_if_err!(self.mc.node_ty(arg.pat.hir_id));
316+
let arg_ty = return_if_err!(self.mc.pat_ty_adjusted(&arg.pat));
317+
debug!("consume_body: arg_ty = {:?}", arg_ty);
317318

318319
let fn_body_scope_r =
319320
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
517517
/// implicit deref patterns attached (e.g., it is really
518518
/// `&Some(x)`). In that case, we return the "outermost" type
519519
/// (e.g., `&Option<T>).
520-
fn pat_ty_adjusted(&self, pat: &hir::Pat) -> McResult<Ty<'tcx>> {
520+
pub fn pat_ty_adjusted(&self, pat: &hir::Pat) -> McResult<Ty<'tcx>> {
521521
// Check for implicit `&` types wrapping the pattern; note
522522
// that these are never attached to binding patterns, so
523523
// actually this is somewhat "disjoint" from the code below
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0507]: cannot move out of borrowed content
2+
--> $DIR/issue-51415.rs:16:47
3+
|
4+
LL | let opt = a.iter().enumerate().find(|(_, &s)| {
5+
| ^ cannot move out of borrowed content
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0507`.

src/test/ui/borrowck/issue-51415.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #51415: match default bindings were failing to
12+
// see the "move out" implied by `&s` below.
13+
14+
fn main() {
15+
let a = vec![String::from("a")];
16+
let opt = a.iter().enumerate().find(|(_, &s)| {
17+
//~^ ERROR cannot move out
18+
*s == String::from("d")
19+
}).map(|(i, _)| i);
20+
println!("{:?}", opt);
21+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0507]: cannot move out of borrowed content
2+
--> $DIR/issue-51415.rs:16:46
3+
|
4+
LL | let opt = a.iter().enumerate().find(|(_, &s)| {
5+
| ^-
6+
| ||
7+
| |hint: to prevent move, use `ref s` or `ref mut s`
8+
| cannot move out of borrowed content
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)