Use visit_place
This commit is contained in:
parent
aca64b8df7
commit
d9ad33852c
@ -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) => {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user