Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ impl<'tcx> LoanPath<'tcx> {
}

fn to_type(&self) -> Ty<'tcx> { self.ty }

fn is_downcast(&self) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe call this has_downcast? Also, we should try this out with the MIR borrowck.

match self.kind {
LpDowncast(_, _) => true,
LpExtend(ref lp, _, LpInterior(_, _)) => {
lp.is_downcast()
}
_ => false,
}
}
}

// FIXME (pnkfelix): See discussion here
Expand Down Expand Up @@ -715,16 +725,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
move_note));
err
} else {
err.span_label(use_span, format!("value {} here after move", verb_participle))
.span_label(move_span, format!("value moved{} here", move_note));
err.span_label(use_span, format!("value {} here after move", verb_participle));
err.span_label(move_span, format!("value moved{} here", move_note));
err
};

if need_note {
err.note(&format!("move occurs because `{}` has type `{}`, \
which does not implement the `Copy` trait",
self.loan_path_to_string(moved_lp),
moved_lp.ty));
err.note(&format!(
"move occurs because {} has type `{}`, which does not implement the `Copy` trait",
if moved_lp.is_downcast() {
"the value".to_string()
} else {
format!("`{}`", self.loan_path_to_string(moved_lp))
},
moved_lp.ty));
}

// Note: we used to suggest adding a `ref binding` or calling
Expand Down Expand Up @@ -1391,7 +1405,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
LpDowncast(ref lp_base, variant_def_id) => {
out.push('(');
self.append_autoderefd_loan_path_to_string(&lp_base, out);
out.push(':');
out.push_str(DOWNCAST_PRINTED_OPERATOR);
out.push_str(&self.tcx.item_path_str(variant_def_id));
out.push(')');
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/issue-24357.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ struct NoCopy;
fn main() {
let x = NoCopy;
let f = move || { let y = x; };
//~^ value moved (into closure) here
//~^ NOTE value moved (into closure) here
let z = x;
//~^ ERROR use of moved value: `x`
//~| value used here after move
//~| move occurs because `x` has type `NoCopy`
//~| NOTE value used here after move
//~| NOTE move occurs because `x` has type `NoCopy`
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ fn touch<A>(_a: &A) {}
fn f00() {
let x = "hi".to_string();
let _y = Foo { f:x };
//~^ value moved here
//~^ NOTE value moved here
touch(&x); //~ ERROR use of moved value: `x`
//~^ value used here after move
//~| move occurs because `x` has type `std::string::String`
//~^ NOTE value used here after move
//~| NOTE move occurs because `x` has type `std::string::String`
}

fn f05() {
let x = "hi".to_string();
let _y = Foo { f:(((x))) };
//~^ value moved here
//~^ NOTE value moved here
touch(&x); //~ ERROR use of moved value: `x`
//~^ NOTE value used here after move
//~| NOTE move occurs because `x` has type `std::string::String`
}

fn f10() {
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/borrowck/issue-41962.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn main(){
let maybe = Some(vec![true, true]);

loop {
if let Some(thing) = maybe {
//~^ ERROR use of partially moved value
//~| ERROR use of moved value
}
}
}
20 changes: 20 additions & 0 deletions src/test/ui/borrowck/issue-41962.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0382]: use of partially moved value: `maybe`
--> $DIR/issue-41962.rs:15:30
|
15 | if let Some(thing) = maybe {
| ----- ^^^^^ value used here after move
| |
| value moved here
|
= note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait

error[E0382]: use of moved value: `(maybe as std::prelude::v1::Some).0`
--> $DIR/issue-41962.rs:15:21
|
15 | if let Some(thing) = maybe {
| ^^^^^ value moved here in previous iteration of loop
|
= note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait

error: aborting due to 2 previous errors