Use visit_place

This commit is contained in:
Shotaro Yamada 2020-03-13 02:06:47 +09:00
parent aca64b8df7
commit d9ad33852c
3 changed files with 23 additions and 3 deletions

View File

@ -375,14 +375,16 @@ impl<'tcx> mir::visit::Visitor<'tcx> for LocalUseVisitor {
);
}
fn visit_local(&mut self, local: &mir::Local, ctx: PlaceContext, _: mir::Location) {
if *local == self.used.0
fn visit_place(&mut self, place: &mir::Place<'tcx>, ctx: PlaceContext, _: mir::Location) {
let local = place.local;
if local == self.used.0
&& !matches!(ctx, PlaceContext::MutatingUse(MutatingUseContext::Drop) | PlaceContext::NonUse(_))
{
self.used.1 = true;
}
if *local == self.consumed_or_mutated.0 {
if local == self.consumed_or_mutated.0 {
match ctx {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
| PlaceContext::MutatingUse(MutatingUseContext::Borrow) => {

View File

@ -150,4 +150,13 @@ fn not_consumed() {
s.clone().push_str("foo"); // OK, removing this `clone()` will change the behavior.
s.push_str("bar");
assert_eq!(s, "bar");
let t = Some(s);
// OK
if let Some(x) = t.clone() {
println!("{}", x);
}
if let Some(x) = t {
println!("{}", x);
}
}

View File

@ -150,4 +150,13 @@ fn not_consumed() {
s.clone().push_str("foo"); // OK, removing this `clone()` will change the behavior.
s.push_str("bar");
assert_eq!(s, "bar");
let t = Some(s);
// OK
if let Some(x) = t.clone() {
println!("{}", x);
}
if let Some(x) = t {
println!("{}", x);
}
}